remember the last directory we were did something in
authorDiane Trout <diane@caltech.edu>
Fri, 15 Sep 2006 22:30:15 +0000 (22:30 +0000)
committerDiane Trout <diane@caltech.edu>
Fri, 15 Sep 2006 22:30:15 +0000 (22:30 +0000)
and then default new operations to that directory.

AKA if we open a mupa file /this/path/to.mupa the next time we open a dialog
to do some IO it will default to /this/path

qui/MussaWindow.cpp
qui/MussaWindow.hpp

index f10e8b4ca5ddb788279ee6e97584e8b3bfcbeaff..f3166d7c3b73248a500653d01799ead271ac4ad0 100644 (file)
@@ -32,6 +32,7 @@ using namespace std;
 MussaWindow::MussaWindow(Mussa *analysis_, QWidget *parent) :
   QMainWindow(parent),
   analysis(analysis_),
+  default_dir(QDir::home().absolutePath().toStdString(), fs::native),
   motif_editor(0),
   setup_analysis_dialog(this),
   browser(this),
@@ -347,7 +348,7 @@ void MussaWindow::saveAnalysisAs()
   std::auto_ptr<QFileDialog> dialog(new QFileDialog(this));
   dialog->setAcceptMode(QFileDialog::AcceptSave);
   dialog->setFileMode(QFileDialog::AnyFile);
-  dialog->setDirectory(QDir::home());
+  dialog->setDirectory(QDir(default_dir.native_directory_string().c_str()));
 
   QStringList fileNames;
   if (not dialog->exec()) {
@@ -374,6 +375,7 @@ void MussaWindow::saveAnalysisAs()
     return;
   }
   analysis->save(save_path);
+  default_dir = (save_path / "..").normalize();
 }
 
 bool MussaWindow::isClearingAnalysisSafe()
@@ -421,10 +423,11 @@ void MussaWindow::loadMotifList()
 {
   QString caption("Load a motif list");
   QString filter("Motif list(*.txt *.mtl)");
+  QDir default_qdir(default_dir.native_directory_string().c_str());
   QString path = QFileDialog::getOpenFileName(this,
-                                                   caption, 
-                                                   QDir::currentPath(),
-                                                   filter);
+                                              caption, 
+                                              default_qdir.absolutePath(),
+                                              filter);
   // user hit cancel?
   if (path.isNull()) 
     return;
@@ -432,6 +435,7 @@ void MussaWindow::loadMotifList()
   try {
     fs::path converted_path(path.toStdString(), fs::native);
     analysis->load_motifs(converted_path);
+    default_dir = converted_path.branch_path();
   } catch (runtime_error e) {
     QString msg("Unable to load ");
     msg += path;
@@ -451,10 +455,14 @@ void MussaWindow::loadMupa()
 {
   QString caption("Load a mussa parameter file");
   QString filter("Mussa Parameters (*.mupa)");
-  QString mupa_path = QFileDialog::getOpenFileName(this,
-                                                   caption, 
-                                                   QDir::currentPath(),
-                                                   filter);
+  QDir default_qdir(QDir(default_dir.native_directory_string().c_str()));
+
+  QString mupa_path = QFileDialog::getOpenFileName(
+                         this,
+                         caption, 
+                         default_qdir.absolutePath(),
+                         filter
+                      );
   // user hit cancel?
   if (mupa_path.isNull()) 
     return;
@@ -472,6 +480,8 @@ void MussaWindow::loadMupa()
     m->analyze();
     setAnalysis(m);
     setWindowTitle(converted_path.native_file_string().c_str());
+    // grab the path ignoring the mupa file portion
+    default_dir = converted_path.branch_path();
   } catch (mussa_load_error e) {
     QString msg("Unable to load ");
     msg += mupa_path;
@@ -484,10 +494,13 @@ void MussaWindow::loadMupa()
 
 void MussaWindow::loadSavedAnalysis()
 {
+  QDir default_qdir(QDir(default_dir.native_directory_string().c_str()));
   QString caption("Load a previously run analysis");
-  QString muway_dir = QFileDialog::getExistingDirectory(this,
-                                                        caption, 
-                                                        QDir::currentPath());
+  QString muway_dir = QFileDialog::getExistingDirectory(
+                        this,
+                        caption, 
+                        default_qdir.absolutePath()
+                     );
   // user hit cancel?
   if (muway_dir.isNull()) 
     return;
@@ -505,6 +518,7 @@ void MussaWindow::loadSavedAnalysis()
     // only switch mussas if we loaded without error
     setAnalysis(m);
     setWindowTitle(converted_path.native_file_string().c_str());
+    default_dir = converted_path.branch_path();
   } catch (mussa_load_error e) {
     QString msg("Unable to load ");
     msg += muway_dir;
index ff23a5c96b756337e7dbc194a16dfc29bd257a86..d81d027b621debb87be8603f2424128113b7247c 100644 (file)
@@ -93,7 +93,10 @@ signals:
   void changedAnnotations();
 
 protected:
+  //! reference to our analysis
   Mussa *analysis;
+  //! the default directory we should loand and save from
+  boost::filesystem::path default_dir;
   std::list<boost::shared_ptr<MussaAlignedWindow> > aligned_windows;
   MotifEditor *motif_editor;
   MussaSetupDialog setup_analysis_dialog;