changeset 15626:1cc10ce368ea

enable entering a new directory in the current directory combobox * main_window.cc: construct (): use QLineEdit for the line edit in _current_directory_combo_box, connect its signal returnedPressed () to new slot current_working_directory_entered (), use const int instead of hard coded constants for combobox parameters; set_current_working_directory (): Check whether directory exists; new slot current_wirking_directory_entered (): set current directory to the entered one if it exists * main_window.h: new slot current_working_directory_entered (), define constants for combobox parameters, QLineEdit _current_directory_line_edit to be used in combobox
author Torsten <ttl@justmail.de>
date Sun, 25 Nov 2012 15:16:07 +0100
parents acf0addfc610
children e40ae983288f
files libgui/src/main-window.cc libgui/src/main-window.h
diffstat 2 files changed, 30 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/libgui/src/main-window.cc
+++ b/libgui/src/main-window.cc
@@ -257,8 +257,10 @@
 void
 main_window::set_current_working_directory (const QString& directory)
 {
-  octave_link::post_event (this, &main_window::change_directory_callback,
-                           directory.toStdString ());
+  QFileInfo fileInfo (directory);  // check whether this is an existing dir
+  if (fileInfo.exists () && fileInfo.isDir ())   // is dir and exists
+    octave_link::post_event (this, &main_window::change_directory_callback,
+                             directory.toStdString ());
 }
 
 void
@@ -267,6 +269,19 @@
   set_current_working_directory ("..");
 }
 
+// Slot that is called if return is pressed in the line edit of the combobox
+// -> a new or a directory that is already in the drop down list was entered
+void
+main_window::current_working_directory_entered ()
+{
+  QString dir = _current_directory_line_edit->text ();  // get new directory
+  int index = _current_directory_combo_box->findText (dir);  // already in list?
+  if ( index < 0 )  // directory not yet in list -> set directory
+    set_current_working_directory (dir);
+  // if directory already in list, combobox triggers signal activated ()
+  // to change directory
+}
+
 void
 main_window::focus_command_window ()
 {
@@ -508,12 +523,15 @@
   _documentation_dock_widget->setStatusTip (tr ("See the documentation for help."));
   _status_bar               = new QStatusBar (this);
 
+  _current_directory_line_edit = new QLineEdit (this);
   _current_directory_combo_box = new QComboBox (this);
-  _current_directory_combo_box->setFixedWidth (300);
+  _current_directory_combo_box->setFixedWidth (current_directory_width);
   _current_directory_combo_box->setEditable (true);
+  // setLineEdit takes ownership -> no need to delete line_edit in ~main_window
+  _current_directory_combo_box->setLineEdit (_current_directory_line_edit);
   _current_directory_combo_box->setInsertPolicy (QComboBox::InsertAtTop);
-  _current_directory_combo_box->setMaxVisibleItems (16);
-  _current_directory_combo_box->setMaxCount (16);
+  _current_directory_combo_box->setMaxVisibleItems (current_directory_max_visible);
+  _current_directory_combo_box->setMaxCount (current_directory_max_count);
 
   QToolButton *current_directory_tool_button = new QToolButton (this);
   current_directory_tool_button->setIcon (QIcon(":/actions/icons/search.png"));
@@ -881,6 +899,8 @@
            _terminal,                   SLOT   (pasteClipboard ()));
   connect (_current_directory_combo_box, SIGNAL (activated (QString)),
            this,                        SLOT (set_current_working_directory (QString)));
+  connect (_current_directory_line_edit, SIGNAL (returnPressed ()),
+           this,                        SLOT (current_working_directory_entered ()));
   connect (_debug_continue,             SIGNAL (triggered ()),
            this,                        SLOT (debug_continue ()));
   connect (_debug_step_into,            SIGNAL (triggered ()),
--- a/libgui/src/main-window.h
+++ b/libgui/src/main-window.h
@@ -98,6 +98,7 @@
   void change_current_working_directory ();
   void set_current_working_directory (const QString& directory);
   void current_working_directory_up ();
+  void current_working_directory_entered ();
 
   void focus_command_window ();
   void focus_command_history ();
@@ -166,6 +167,10 @@
   // Toolbars.
   QStatusBar *              _status_bar;
   QComboBox *               _current_directory_combo_box;
+  static const int        current_directory_width       = 300;
+  static const int        current_directory_max_visible = 16;
+  static const int        current_directory_max_count   = 16;
+  QLineEdit *               _current_directory_line_edit;
 
   octave_qt_event_listener *_octave_qt_event_listener;