changeset 19837:415864f5b85f

communicating actual working directory to the editor (#44298) * file-editor-tab.cc (file-editor-tab.cc): init new _ced variable storing current editor directory, do not store directory in _file_name; (set_current_directory): new slot for setting current editor directory; (handle_context_menu_edit): use _ced for current directory; (valid_file_name): just check whether name is empty; (save_file_as): set directory to current edit directory; * file-editor-tab.h: new variable _ced; new slot for setting _ced, * file-editor.cc (update_octave_directory): new slot for setting current editor directory to wirking directory; (handle_editor_state_changed): do not ced from current file name; (add_file_editor_tab) connect new signal for setting directory to related slot in file_editor_tab * file-editor.h: new slot and new signal updating directory * main-window.cc (change_directory): do not call update directory function in file_browser_window because the latter is notified by a signal now; (construct_octave_qt_link): connect change_directory_signal from octave_qt_link to appropriate slots in editor and file browser
author Torsten <ttl@justmail.de>
date Sat, 21 Feb 2015 13:33:28 +0100
parents e195d8408ce8
children dfa608a9c36e
files libgui/src/m-editor/file-editor-tab.cc libgui/src/m-editor/file-editor-tab.h libgui/src/m-editor/file-editor.cc libgui/src/m-editor/file-editor.h libgui/src/main-window.cc
diffstat 5 files changed, 52 insertions(+), 48 deletions(-) [+]
line wrap: on
line diff
--- a/libgui/src/m-editor/file-editor-tab.cc	Sat Feb 21 01:45:45 2015 -0500
+++ b/libgui/src/m-editor/file-editor-tab.cc	Sat Feb 21 13:33:28 2015 +0100
@@ -69,16 +69,12 @@
 // WindowModal messages don't affect grandparents.
 file_editor_tab::file_editor_tab (const QString& directory_arg)
 {
-  QString directory = directory_arg;
   _lexer_apis = 0;
   _is_octave_file = true;
 
-  // Make sure there is a slash at the end of the directory name
-  // for identification when saved later.
-  if (directory.count () && directory.at (directory.count () - 1) != '/')
-    directory.append ("/");
+  _ced = directory_arg;
 
-  _file_name = directory;
+  _file_name = "";
   _file_system_watcher.setObjectName ("_qt_autotest_force_engine_poller");
 
   _edit_area = new octave_qscintilla (this);
@@ -200,6 +196,12 @@
 }
 
 void
+file_editor_tab::set_current_directory (const QString& dir)
+{
+  _ced = dir;
+}
+
+void
 file_editor_tab::handle_context_menu_edit (const QString& word_at_cursor)
 {
   // search for a subfunction in actual file (this is done at first because
@@ -255,8 +257,15 @@
   else if (type.isEmpty ())
     {
       // function not known to octave -> try directory of edited file
-      QFileInfo file = QFileInfo (_file_name);
-      file = QFileInfo (QDir (file.canonicalPath ()), word_at_cursor + ".m");
+      // get directory
+      QDir dir;
+      if (_file_name.isEmpty ())
+        dir = _ced;
+      else
+        dir = QDir (QFileInfo (_file_name).canonicalPath ());
+
+      // function not known to octave -> try directory of edited file
+      QFileInfo file = QFileInfo (dir, word_at_cursor + ".m");
 
       if (file.exists ())
         {
@@ -318,7 +327,7 @@
   update_lexer ();
 
   // update the file editor with current editing directory
-  emit editor_state_changed (_copy_available, _file_name, _is_octave_file);
+  emit editor_state_changed (_copy_available, _is_octave_file);
 
   // add the new file to the mru list
   emit mru_add_file (_file_name);
@@ -329,13 +338,15 @@
 bool
 file_editor_tab::valid_file_name (const QString& file)
 {
-  QString file_name;
   if (file.isEmpty ())
-    file_name = _file_name;
-  else
-    file_name = file;
-  return (! file_name.isEmpty ()
-          && file_name.at (file_name.count () - 1) != '/');
+    {
+      if (_file_name.isEmpty ())
+        return false;
+      else
+        return true;
+    }
+
+  return true;
 }
 
 void
@@ -1213,8 +1224,7 @@
 file_editor_tab::handle_copy_available (bool enableCopy)
 {
   _copy_available = enableCopy;
-  emit editor_state_changed (_copy_available, QDir::cleanPath (_file_name),
-                             _is_octave_file);
+  emit editor_state_changed (_copy_available, _is_octave_file);
 }
 
 // show_dialog: shows a modal or non modal dialog depending on input arg
@@ -1590,15 +1600,7 @@
   else
     {
       fileDialog->selectFile ("");
-
-      if (_file_name.isEmpty ())
-        fileDialog->setDirectory (QDir::currentPath ());
-      else
-        {
-          // The file name is actually the directory name from the
-          // constructor argument.
-          fileDialog->setDirectory (_file_name);
-        }
+      fileDialog->setDirectory (_ced);
 
       // propose a name corresponding to the function name
       QString fname = get_function_name ();
@@ -1945,8 +1947,7 @@
       _find_dialog->show ();
     }
 
-  emit editor_state_changed (_copy_available, QDir::cleanPath (_file_name),
-                             _is_octave_file);
+  emit editor_state_changed (_copy_available, _is_octave_file);
 }
 
 void
--- a/libgui/src/m-editor/file-editor-tab.h	Sat Feb 21 01:45:45 2015 -0500
+++ b/libgui/src/m-editor/file-editor-tab.h	Sat Feb 21 13:33:28 2015 +0100
@@ -74,6 +74,7 @@
   void file_name_query (const QWidget *ID);
 
   void set_focus (const QWidget *ID);
+  void set_current_directory (const QString& dir);
   void context_help (const QWidget *ID, bool);
   void context_edit (const QWidget *ID);
   void check_modified_file (void);
@@ -129,8 +130,7 @@
 signals:
 
   void file_name_changed (const QString& fileName, const QString& toolTip);
-  void editor_state_changed (bool copy_available, const QString& fileName,
-                             bool is_octave_file);
+  void editor_state_changed (bool copy_available, bool is_octave_file);
   void tab_remove_request ();
   void add_filename_to_list (const QString&, QWidget *);
   void mru_add_file (const QString& file_name);
@@ -230,6 +230,7 @@
 
   QString _file_name;
   QString _file_name_short;
+  QString _ced;
 
   bool _long_title;
   bool _copy_available;
--- a/libgui/src/m-editor/file-editor.cc	Sat Feb 21 01:45:45 2015 -0500
+++ b/libgui/src/m-editor/file-editor.cc	Sat Feb 21 13:33:28 2015 +0100
@@ -118,6 +118,13 @@
     emit fetab_set_focus (fileEditorTab);
 }
 
+void
+file_editor::update_octave_directory (const QString& dir)
+{
+  ced = dir;
+  emit fetab_set_directory (ced);  // for save dialog
+}
+
 QMenu *
 file_editor::debug_menu (void)
 {
@@ -1101,7 +1108,6 @@
 
 void
 file_editor::handle_editor_state_changed (bool copy_available,
-                                          const QString& file_name,
                                           bool is_octave_file)
 {
   // In case there is some scenario where traffic could be coming from
@@ -1113,17 +1119,6 @@
       _run_selection_action->setEnabled (copy_available);
       _run_action->setEnabled (is_octave_file);
 
-      if (!file_name.isEmpty ())
-        {
-          ced = QDir::cleanPath (file_name);
-          int lastslash = ced.lastIndexOf ('/');
-
-          // Test against > 0 because if somehow the directory is "/" the
-          // slash should be retained.  Otherwise, last slash is removed.
-          if (lastslash > 0 && lastslash != ced.count ())
-            ced = ced.left (lastslash);
-        }
-
       setFocusProxy (_tab_widget->currentWidget ());
     }
 }
@@ -1614,8 +1609,8 @@
            this, SLOT (handle_file_name_changed (const QString&,
                                                  const QString&)));
 
-  connect (f, SIGNAL (editor_state_changed (bool, const QString&, bool)),
-           this, SLOT (handle_editor_state_changed (bool, const QString&, bool)));
+  connect (f, SIGNAL (editor_state_changed (bool, bool)),
+           this, SLOT (handle_editor_state_changed (bool, bool)));
 
   connect (f, SIGNAL (tab_remove_request ()),
            this, SLOT (handle_tab_remove_request ()));
@@ -1656,6 +1651,9 @@
            f, SLOT (check_modified_file (void)));
 
   // Signals from the file_editor trivial operations
+  connect (this, SIGNAL (fetab_set_directory (const QString&)),
+           f, SLOT (set_current_directory (const QString&)));
+
   connect (this, SIGNAL (fetab_zoom_in (const QWidget*)),
            f, SLOT (zoom_in (const QWidget*)));
   connect (this, SIGNAL (fetab_zoom_out (const QWidget*)),
--- a/libgui/src/m-editor/file-editor.h	Sat Feb 21 01:45:45 2015 -0500
+++ b/libgui/src/m-editor/file-editor.h	Sat Feb 21 13:33:28 2015 +0100
@@ -110,6 +110,8 @@
   void fetab_zoom_out (const QWidget* ID);
   void fetab_zoom_normal (const QWidget* ID);
 
+  void fetab_set_directory (const QString& dir);
+
   void request_settings_dialog (const QString&);
   void execute_command_in_terminal_signal (const QString&);
   void file_loaded_signal ();
@@ -187,8 +189,7 @@
   void handle_tab_remove_request (void);
   void handle_add_filename_to_list (const QString& fileName, QWidget *ID);
   void active_tab_changed (int index);
-  void handle_editor_state_changed (bool enableCopy, const QString& fileName,
-                                    bool is_octave_file);
+  void handle_editor_state_changed (bool enableCopy, bool is_octave_file);
   void handle_mru_add_file (const QString& file_name);
   void check_conflict_save (const QString& fileName, bool remove_on_success);
 
@@ -206,6 +207,7 @@
 
   void handle_visibility (bool visible);
 
+  void update_octave_directory (const QString& dir);
 
 protected slots:
   void copyClipboard ();
--- a/libgui/src/main-window.cc	Sat Feb 21 01:45:45 2015 -0500
+++ b/libgui/src/main-window.cc	Sat Feb 21 13:33:28 2015 +0100
@@ -813,8 +813,6 @@
 
   _current_directory_combo_box->insertItem (0, dir);
   _current_directory_combo_box->setCurrentIndex (0);
-
-  file_browser_window->update_octave_directory (dir);
 }
 
 void
@@ -1457,6 +1455,10 @@
 
   connect (_octave_qt_link, SIGNAL (change_directory_signal (QString)),
            this, SLOT (change_directory (QString)));
+  connect (_octave_qt_link, SIGNAL (change_directory_signal (QString)),
+           file_browser_window, SLOT (update_octave_directory (QString)));
+  connect (_octave_qt_link, SIGNAL (change_directory_signal (QString)),
+           editor_window, SLOT (update_octave_directory (QString)));
 
   connect (_octave_qt_link,
            SIGNAL (execute_command_in_terminal_signal (QString)),