Mercurial > octave-nkf
changeset 16542:016073c0cb94
Add popdown toolbutton to files-dock-window toolbar.
* libgui/src/files-dock-widget.cc
(files_dock_widget::files_dock_widget): added popdown button to toolbar and
merged set current dir, show current dir into it as well as adding new dir
and new file option.
(files_dock_widget::display_directory): change to call process_set_current_dir
instead of emit.
(files_dock_widget::contextmenu_newfile): change to call process_new_file.
(files_dock_widget::contextmenu_newdir): Change to call process_new_dir.
(files_dock_widget::contextmenu_setcurrentdir): Change to call
process_set_current_dir.
(files_dock_widget::popdownmenu_newdir): New function.
(files_dock_widget::popdownmenu_newfile): New function.
(files_dock_widget::process_new_file): New function.
(files_dock_widget::process_new_dir): New function.
(iles_dock_widget::process_set_current_dir): New function.
* libgui/src/resource.qrc: Added icons/gear.png.
* libgui/src/module.mk: Added icons/gear.png.
* libgui/src/icons.png: New file.
author | John Donoghue <john.donoghue@ieee.org> |
---|---|
date | Tue, 16 Apr 2013 22:16:57 -0400 |
parents | 6afb29359968 |
children | c58069081439 |
files | libgui/src/files-dock-widget.cc libgui/src/files-dock-widget.h libgui/src/icons/gear.png libgui/src/module.mk libgui/src/resource.qrc |
diffstat | 5 files changed, 84 insertions(+), 28 deletions(-) [+] |
line wrap: on
line diff
--- a/libgui/src/files-dock-widget.cc Thu Apr 18 11:55:25 2013 -0400 +++ b/libgui/src/files-dock-widget.cc Tue Apr 16 22:16:57 2013 -0400 @@ -39,6 +39,7 @@ #include <QMenu> #include <QInputDialog> #include <QMessageBox> +#include <QToolButton> files_dock_widget::files_dock_widget (QWidget *p) : octave_dock_widget (p) @@ -80,19 +81,35 @@ directory_up_action->setToolTip (tr ("Move up one directory")); _sync_browser_directory_action = new QAction (QIcon(":/actions/icons/reload.png"), - "", _navigation_tool_bar); + tr("Show octave directory"), _navigation_tool_bar); _sync_browser_directory_action->setToolTip (tr ("Goto current octave directory")); _sync_browser_directory_action->setEnabled ("false"); _sync_octave_directory_action = new QAction (QIcon(":/actions/icons/ok.png"), - "", _navigation_tool_bar); + tr("Set octave directory"), _navigation_tool_bar); _sync_octave_directory_action->setToolTip (tr ("Set octave directroy to current browser directory")); _sync_octave_directory_action->setEnabled ("false"); + QToolButton * popdown_button = new QToolButton(); + popdown_button->setToolTip(tr ("Actions on current directory")); + QMenu * popdown_menu = new QMenu(); + popdown_menu->addAction(_sync_browser_directory_action); + popdown_menu->addAction(_sync_octave_directory_action); + popdown_button->setMenu(popdown_menu); + popdown_button->setPopupMode(QToolButton::InstantPopup); + popdown_button->setDefaultAction(new QAction(QIcon(":/actions/icons/gear.png"),"", _navigation_tool_bar)); + + popdown_menu->addSeparator(); + popdown_menu->addAction(QIcon(":/actions/icons/filenew.png"), + tr ("New File"), + this, SLOT(popdownmenu_newfile(bool))); + popdown_menu->addAction(QIcon(":/actions/icons/folder_new.png"), + tr ("New Directory"), + this, SLOT(popdownmenu_newdir(bool))); + _navigation_tool_bar->addWidget (_current_directory); _navigation_tool_bar->addAction (directory_up_action); - _navigation_tool_bar->addAction (_sync_browser_directory_action); - _navigation_tool_bar->addAction (_sync_octave_directory_action); + _navigation_tool_bar->addWidget (popdown_button); connect (directory_up_action, SIGNAL (triggered ()), this, SLOT (change_directory_up ())); @@ -101,8 +118,6 @@ connect (_sync_browser_directory_action, SIGNAL (triggered ()), this, SLOT (do_sync_browser_directory ())); - // TODO: Add other buttons for creating directories - // Create the QFileSystemModel starting in the actual directory QDir curr_dir; _file_system_model = new QFileSystemModel (this); @@ -252,7 +267,7 @@ _file_system_model->setRootPath (fileInfo.absoluteFilePath ()); _file_system_model->sort (0, Qt::AscendingOrder); if (_sync_octave_dir && set_octave_dir) - emit displayed_directory_changed (fileInfo.absoluteFilePath ()); + process_set_current_dir(fileInfo.absoluteFilePath ()); // see if its in the list, and if it is, remove it and then, put at top of the list int index = _current_directory->findText(fileInfo.absoluteFilePath ()); @@ -449,18 +464,8 @@ QFileInfo info = _file_system_model->fileInfo(index); QString parent_dir = info.filePath(); - bool ok; - QString name = QInputDialog::getText (this, tr("Create File"), tr("Create file in\n") + parent_dir, - QLineEdit::Normal, "New File.txt", &ok); - if(ok && name.length()>0) - { - name = parent_dir + "/" + name; - - QFile file(name); - file.open(QIODevice::WriteOnly); - _file_system_model->revert(); - } + process_new_file(parent_dir); } } @@ -476,14 +481,8 @@ QFileInfo info = _file_system_model->fileInfo(index); QString parent_dir = info.filePath(); - bool ok; - QString name = QInputDialog::getText (this, tr("Create Directory"), tr("Create folder in\n") + parent_dir, - QLineEdit::Normal, "New Directory", &ok); - if(ok && name.length()>0) - { - _file_system_model->mkdir(index, name); - } + process_new_dir(parent_dir); } } @@ -501,7 +500,7 @@ if(info.isDir()) { - emit displayed_directory_changed (info.absoluteFilePath ()); + process_set_current_dir(info.absoluteFilePath ()); } } } @@ -535,3 +534,53 @@ display_directory (_octave_dir); // sync browser to octave dir } + +void +files_dock_widget::popdownmenu_newdir (bool) +{ + process_new_dir(_file_system_model->rootPath()); +} + +void +files_dock_widget::popdownmenu_newfile (bool) +{ + process_new_file(_file_system_model->rootPath()); +} + +void +files_dock_widget::process_new_file (const QString &parent_dir) +{ + bool ok; + + QString name = QInputDialog::getText (this, tr("Create File"), tr("Create file in\n") + parent_dir, + QLineEdit::Normal, "New File.txt", &ok); + if(ok && name.length()>0) + { + name = parent_dir + "/" + name; + + QFile file(name); + file.open(QIODevice::WriteOnly); + _file_system_model->revert(); + } +} + +void +files_dock_widget::process_new_dir (const QString &parent_dir) +{ + bool ok; + + QString name = QInputDialog::getText (this, tr("Create Directory"), tr("Create folder in\n") + parent_dir, + QLineEdit::Normal, "New Directory", &ok); + if(ok && name.length()>0) + { + QDir dir(parent_dir); + dir.mkdir(name); + _file_system_model->revert(); + } +} + +void files_dock_widget::process_set_current_dir(const QString & dir) +{ + emit displayed_directory_changed (dir); +} +
--- a/libgui/src/files-dock-widget.h Thu Apr 18 11:55:25 2013 -0400 +++ b/libgui/src/files-dock-widget.h Tue Apr 16 22:16:57 2013 -0400 @@ -93,6 +93,10 @@ void contextmenu_newdir (bool); void contextmenu_setcurrentdir (bool); + /* popdown menu options */ + void popdownmenu_newfile(bool); + void popdownmenu_newdir(bool); + signals: /** Emitted, whenever the user requested to open a file. */ @@ -108,8 +112,9 @@ void run_file_signal (const QString& fileName); private: - - // TODO: Add toolbar with buttons for navigating the path, creating dirs, etc + void process_new_file(const QString &parent_name); + void process_new_dir(const QString &parent_name); + void process_set_current_dir(const QString &parent_name); /** set a new directory or open a file **/ void display_directory (const QString& dir, bool set_octave_dir = true);
--- a/libgui/src/module.mk Thu Apr 18 11:55:25 2013 -0400 +++ b/libgui/src/module.mk Tue Apr 16 22:16:57 2013 -0400 @@ -29,6 +29,7 @@ src/icons/filesaveas.png \ src/icons/filesave.png \ src/icons/find.png \ + src/icons/gear.png \ src/icons/folder_new.png \ src/icons/graphic_logo_DocumentationDockWidget.png \ src/icons/graphic_logo_FileEditor.png \
--- a/libgui/src/resource.qrc Thu Apr 18 11:55:25 2013 -0400 +++ b/libgui/src/resource.qrc Tue Apr 16 22:16:57 2013 -0400 @@ -27,6 +27,7 @@ <file>icons/zoom-in.png</file> <file>icons/zoom-out.png</file> <file>icons/find.png</file> + <file>icons/gear.png</file> <file>icons/chat.png</file> <file>icons/help_index.png</file> <file>icons/jabber_protocol.png</file>