# HG changeset patch
# User John Donoghue <john.donoghue@ieee.org>
# Date 1366165017 14400
# Node ID 07402545d81002bfa89d97d0a0527100685bf404
# Parent  8701792e16ecbd2c12dc2895c48373ee74672346
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.

diff --git a/libgui/src/files-dock-widget.cc b/libgui/src/files-dock-widget.cc
--- a/libgui/src/files-dock-widget.cc
+++ b/libgui/src/files-dock-widget.cc
@@ -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);
+}
+
diff --git a/libgui/src/files-dock-widget.h b/libgui/src/files-dock-widget.h
--- a/libgui/src/files-dock-widget.h
+++ b/libgui/src/files-dock-widget.h
@@ -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);
diff --git a/libgui/src/icons/gear.png b/libgui/src/icons/gear.png
new file mode 100755
index 0000000000000000000000000000000000000000..430a62341c613b35c9dddc9bfa359615b2e60b39
GIT binary patch
diff --git a/libgui/src/module.mk b/libgui/src/module.mk
--- a/libgui/src/module.mk
+++ b/libgui/src/module.mk
@@ -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 \
diff --git a/libgui/src/resource.qrc b/libgui/src/resource.qrc
--- a/libgui/src/resource.qrc
+++ b/libgui/src/resource.qrc
@@ -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>
