[Kst] branches/work/kst/portto4/kst/src/libkstapp

Nicolas Brisset nicolas.brisset at eurocopter.com
Sat Jun 1 21:11:52 UTC 2013


SVN commit 1356751 by brisset:

Always use the absolute path to recent files in the menus, otherwise they're not reusable between sessions 
if kst2 is not started from the same directory. This should incidentally also fix the problem that we could 
have duplicate entries at the bottom of the File menu since only the file name was shown and the relative 
path was tested for duplicates.
Also restore the application directory after loading.


 M  +4 -1      document.cpp  
 M  +5 -3      mainwindow.cpp  


--- branches/work/kst/portto4/kst/src/libkstapp/document.cpp #1356750:1356751
@@ -233,7 +233,8 @@
     _lastError = QObject::tr("File could not be opened for reading.");
     return false;
   }
-  // Set the application dir to the current dir to be able to load data using the "fileRelative" attribute
+  // Temporarily set the application dir to the current dir to be able to load data using the "fileRelative" attribute
+  QString restorePath = QDir::currentPath();
   QDir::setCurrent(file.left(file.lastIndexOf('/')) + '/');
   _fileName = file;
 
@@ -414,6 +415,8 @@
 
   UpdateManager::self()->doUpdates(true);
   setChanged(false);
+  // Restore current app path
+  QDir::setCurrent(restorePath);
 
   return _isOpen = true;
 }
--- branches/work/kst/portto4/kst/src/libkstapp/mainwindow.cpp #1356750:1356751
@@ -350,6 +350,8 @@
 
 void MainWindow::updateRecentFiles(const QString& key, QMenu* menu, QList<QAction*>& actions, QMenu* submenu, const QString& newfilename, const char* openslot)
 {
+  // Always add absolute paths to the recent file lists, otherwise they are not very reusable
+  QString absoluteFilePath = newfilename.startsWith("/") ? newfilename : QDir::currentPath() + "/" + newfilename;
   foreach(QAction* it, actions) {
     menu->removeAction(it);
     delete it;
@@ -360,9 +362,9 @@
   if (recentFiles.removeDuplicates() > 0) {
     settings.setValue(key, recentFiles);
   }
-  if (!newfilename.isEmpty()) {
-    recentFiles.removeOne(newfilename);
-    recentFiles.push_front(newfilename);
+  if (!absoluteFilePath.isEmpty()) {
+    recentFiles.removeOne(absoluteFilePath);
+    recentFiles.push_front(absoluteFilePath);
     recentFiles = recentFiles.mid(0, 30);
     settings.setValue(key, recentFiles);
   }


More information about the Kst mailing list