diff gui/src/m-editor/file-editor-tab.cc @ 14788:85daba52b2d4 gui

Fixed bug with editor complaining that a file has been modified by another application when saving. * file-editor-tab.cc: Now "unwatching" file before saving. * file-editor-tab: Renamed slot to update window title. * file-editor.cc: Renamed slot to update window title.
author Jacob Dawid <jacob.dawid@googlemail.com>
date Thu, 21 Jun 2012 20:18:30 +0200
parents b4db843b1f26
children e3ae0850b105
line wrap: on
line diff
--- a/gui/src/m-editor/file-editor-tab.cc
+++ b/gui/src/m-editor/file-editor-tab.cc
@@ -79,14 +79,14 @@
 
   // connect modified signal
   connect (_edit_area, SIGNAL (modificationChanged (bool)),
-           this, SLOT (new_title (bool)));
+           this, SLOT (update_window_title (bool)));
   connect (_edit_area, SIGNAL (copyAvailable (bool)),
            this, SLOT (handle_copy_available (bool)));
   connect (&_file_system_watcher, SIGNAL (fileChanged (QString)),
            this, SLOT (file_has_changed (QString)));
 
   _file_name = "";
-  new_title (false);
+  update_window_title (false);
 }
 
 bool
@@ -180,7 +180,7 @@
 }
 
 void
-file_editor_tab::new_title(bool modified)
+file_editor_tab::update_window_title(bool modified)
 {
   QString title(_file_name);
   if ( !_long_title )
@@ -371,7 +371,7 @@
   update_tracked_file ();
 
 
-  new_title (false); // window title (no modification)
+  update_window_title (false); // window title (no modification)
   _edit_area->setModified (false); // loaded file is not modified yet
 }
 
@@ -384,7 +384,7 @@
     }
 
   set_file_name (UNNAMED_FILE);
-  new_title (false); // window title (no modification)
+  update_window_title (false); // window title (no modification)
   _edit_area->setText ("");
   _edit_area->setModified (false); // new file is not modified yet
 }
@@ -403,6 +403,9 @@
       return save_file_as();
     }
 
+  QStringList watched_files = _file_system_watcher.files();
+  _file_system_watcher.removePaths(watched_files);
+
   // open the file for writing
   QFile file (saveFileName);
   if (!file.open (QFile::WriteOnly))
@@ -410,6 +413,7 @@
       QMessageBox::warning (this, tr ("Octave Editor"),
                             tr ("Could not open file %1 for write:\n%2.").
                             arg (saveFileName).arg (file.errorString ()));
+      _file_system_watcher.addPaths (watched_files);
       return false;
     }
 
@@ -418,9 +422,12 @@
   QApplication::setOverrideCursor (Qt::WaitCursor);
   out << _edit_area->text ();
   QApplication::restoreOverrideCursor ();
-  set_file_name (saveFileName);  // save file name for later use
-  new_title (false);      // set the window title to actual file name (not modified)
+  _file_name = saveFileName; // save file name for later use
+  update_window_title (false);      // set the window title to actual file name (not modified)
   _edit_area->setModified (false); // files is save -> not modified
+  file.close();
+
+  _file_system_watcher.addPaths (watched_files);
   return true;
 }
 
@@ -501,7 +508,7 @@
           if (!save_file_as ())
             {
               set_file_name (UNNAMED_FILE);
-              new_title (true); // window title (no modification)
+              update_window_title (true); // window title (no modification)
               set_modified (true);
               update_tracked_file ();
             }