diff libgui/src/m-editor/file-editor-tab.cc @ 30745:2f6904439d3c

fix updating the name of renamed editor files * files-dock-widget.cc (contextmenu_delete): emit file_renamed_signal in nay case, not only on errors while deleting the file * file-editor-tab.cc (set_file_name): update window title here; (enable_file_watcher): new function for en-/disabling the file watcher for the current file; (load_file): set modified state before setting the file name, do not set window title, which is done in set_file_name; (do_save_file): dito * file-editor-tab.h: new function enable_file_watcher, function set_file_name public * file-editor.cc (handle_file_remove): use removed_file_data instead of session_data, only disable file watching and remember editor tab and new file name; (handle_file_renamed): if succesfully renamed/removed, update the file name or close the file, otherwise just re-enable file watcher (handle_dir_remove): use removed_file_data, disable file watcher, remember editor tab and new file name * file-editor.h: new struct removed_file_data, m_tmp_closed_files is of type removed_file_data
author Torsten Lilge <ttl-octave@mailbox.org>
date Tue, 15 Feb 2022 18:57:16 +0100
parents 83f9f8bda883
children a0c8c28c38cb
line wrap: on
line diff
--- a/libgui/src/m-editor/file-editor-tab.cc	Tue Feb 15 11:57:26 2022 -0500
+++ b/libgui/src/m-editor/file-editor-tab.cc	Tue Feb 15 18:57:16 2022 +0100
@@ -509,6 +509,9 @@
         update_lexer ();
       }
 
+    // set the window title to actual filename (not modified)
+    update_window_title (m_edit_area->isModified ());
+
     // update the file editor with current editing directory
     emit editor_state_changed (m_copy_available, m_is_octave_file,
                                m_edit_area->isModified ());
@@ -532,6 +535,14 @@
     return true;
   }
 
+  void file_editor_tab::enable_file_watcher (bool do_enable)
+  {
+    if (do_enable)
+      m_file_system_watcher.addPath (m_file_name);
+    else
+      m_file_system_watcher.removePath (m_file_name);
+  }
+
   // We cannot create a breakpoint when the file is modified
   // because the line number the editor is providing might
   // not match what Octave core is interpreting in the
@@ -1845,9 +1856,8 @@
     QApplication::restoreOverrideCursor ();
 
     m_copy_available = false;     // no selection yet available
+    m_edit_area->setModified (false); // loaded file is not modified yet
     set_file_name (file_to_load);
-    update_window_title (false); // window title (no modification)
-    m_edit_area->setModified (false); // loaded file is not modified yet
 
     update_eol_indicator ();
 
@@ -2251,16 +2261,13 @@
         QFileInfo file_info = QFileInfo (file.fileName ());
         QString full_file_to_save = file_info.canonicalFilePath ();
 
-        // save filename after closing file as set_file_name starts watching again
-        set_file_name (full_file_to_save);   // make absolute
-
-        // set the window title to actual filename (not modified)
-        update_window_title (false);
-
         // file is save -> not modified, update encoding in statusbar
         m_edit_area->setModified (false);
         m_enc_indicator->setText (m_encoding);
 
+        // save filename after closing file as set_file_name starts watching again
+        set_file_name (full_file_to_save);   // make absolute
+
         emit tab_ready_to_close ();
 
         if (remove_on_success)