changeset 17706:97ed9dd479ab

make sure all entries in the editor's mru-menu have an absolute path * file_editor_tab.cc(set_file_name): do not use QDir::cleanPath (); (load_file): get absolute path of file to load if possible; (save_file): get absolute path of file to save if possible, set_file_name is always calles with absolute path * file-editor.cc(request_open_file): add file eith absolute path into mru menu
author Torsten <ttl@justmail.de>
date Sun, 20 Oct 2013 20:08:32 +0200
parents 292319fb7fcc
children e26b47e9285e
files libgui/src/m-editor/file-editor-tab.cc libgui/src/m-editor/file-editor.cc
diffstat 2 files changed, 34 insertions(+), 12 deletions(-) [+]
line wrap: on
line diff
--- a/libgui/src/m-editor/file-editor-tab.cc	Sun Oct 20 17:57:17 2013 +0100
+++ b/libgui/src/m-editor/file-editor-tab.cc	Sun Oct 20 20:08:32 2013 +0200
@@ -189,9 +189,10 @@
   update_lexer ();
 
   // update the file editor with current editing directory
-  emit editor_state_changed (_copy_available, QDir::cleanPath (_file_name));
+  emit editor_state_changed (_copy_available, _file_name);
   // add the new file to the mru list
-  emit mru_add_file (QDir::cleanPath (_file_name));
+
+  emit mru_add_file (_file_name);
 }
 
 void
@@ -931,7 +932,14 @@
 QString
 file_editor_tab::load_file (const QString& fileName)
 {
-  QFile file (fileName);
+  // get the absolute path
+  QFileInfo file_info = QFileInfo (fileName);
+  QString file_to_load;
+  if (file_info.exists ())
+    file_to_load = file_info.canonicalFilePath ();
+  else
+    file_to_load = fileName;
+  QFile file (file_to_load);
   if (!file.open (QFile::ReadOnly))
     return file.errorString ();
 
@@ -941,7 +949,7 @@
   QApplication::restoreOverrideCursor ();
 
   _copy_available = false;     // no selection yet available
-  set_file_name (fileName);
+  set_file_name (file_to_load);
   update_window_title (false); // window title (no modification)
   _edit_area->setModified (false); // loaded file is not modified yet
 
@@ -967,27 +975,34 @@
       save_file_as (remove_on_success);
       return;
     }
+  // get the absolute path (if existing)
+  QFileInfo file_info = QFileInfo (saveFileName);
+  QString file_to_save;
+  if (file_info.exists ())
+    file_to_save = file_info.canonicalFilePath ();
+  else
+    file_to_save = saveFileName;
+  QFile file (file_to_save);
 
   // stop watching file
   QStringList trackedFiles = _file_system_watcher.files ();
-  if (!trackedFiles.isEmpty ())
-    _file_system_watcher.removePath (saveFileName);
+  if (trackedFiles.contains (file_to_save))
+    _file_system_watcher.removePath (file_to_save);
 
   // open the file for writing
-  QFile file (saveFileName);
   if (!file.open (QIODevice::WriteOnly))
     {
       // Unsuccessful, begin watching file again if it was being
       // watched previously.
-      if (trackedFiles.contains (saveFileName))
-        _file_system_watcher.addPath (saveFileName);
+      if (trackedFiles.contains (file_to_save))
+        _file_system_watcher.addPath (file_to_save);
 
       // Create a NonModal message about error.
       QMessageBox* msgBox
         = new QMessageBox (QMessageBox::Critical,
                            tr ("Octave Editor"),
                            tr ("Could not open file %1 for write:\n%2.").
-                           arg (saveFileName).arg (file.errorString ()),
+                           arg (file_to_save).arg (file.errorString ()),
                            QMessageBox::Ok, 0);
       msgBox->setWindowModality (Qt::NonModal);
       msgBox->setAttribute (Qt::WA_DeleteOnClose);
@@ -1000,11 +1015,17 @@
   QTextStream out (&file);
   QApplication::setOverrideCursor (Qt::WaitCursor);
   out << _edit_area->text ();
+  out.flush ();
   QApplication::restoreOverrideCursor ();
+  file.flush ();
   file.close ();
 
+  // file exists now
+  file_info = QFileInfo (file);
+  file_to_save = file_info.canonicalFilePath ();
+
   // save file name after closing file as set_file_name starts watching again
-  set_file_name (saveFileName);
+  set_file_name (file_to_save);   // make absolute
 
   // set the window title to actual file name (not modified)
   update_window_title (false);
--- a/libgui/src/m-editor/file-editor.cc	Sun Oct 20 17:57:17 2013 +0100
+++ b/libgui/src/m-editor/file-editor.cc	Sun Oct 20 20:08:32 2013 +0200
@@ -277,7 +277,8 @@
                   add_file_editor_tab (fileEditorTab, "");
                   fileEditorTab->update_window_title (false);
                   // file already loaded, add file to mru list here
-                  handle_mru_add_file (QDir::cleanPath (openFileName));
+                  QFileInfo file_info = QFileInfo (openFileName);
+                  handle_mru_add_file (file_info.canonicalFilePath ());
 
                   if (line > 0)
                     {