implement "typical" save and close conventions.
authorDiane Trout <diane@caltech.edu>
Tue, 12 Sep 2006 23:37:27 +0000 (23:37 +0000)
committerDiane Trout <diane@caltech.edu>
Tue, 12 Sep 2006 23:37:27 +0000 (23:37 +0000)
After running an analysis if it hasn't been saved, and you try to close
the window, mussa will ask if you want to save, not save, or cancel the close.
Saving also uses the recently implemented tracking the analysis_path to
determine if it should just offer to save or to use save as.

the only real issue is the dirty flag might get tripped for things
that aren't actually being saved yet.

alg/mussa.cpp
qui/MussaWindow.cpp
qui/MussaWindow.hpp

index 194501dad670fbb497756da0f507ffac40f4d79e..cc5825ef68999dfacbe6370b3f38fbe0e00df20d 100644 (file)
@@ -446,10 +446,6 @@ Mussa::analyze()
   seqcomp();
   the_paths.setup(window, threshold);
   nway();
-  // FIXME: once we implement a save feature we should remove this
-  if (not analysis_name.empty()) {
-    save();
-  }
 }
 
 void
index 1e8d06cb3ddfb1adb9572633eada961da07968d4..8d51ab542d208b2d6b473a1adeaeab5225e9ee79 100644 (file)
@@ -5,6 +5,7 @@
 #include <QAction>
 #include <QApplication>
 #include <QAssistantClient>
+#include <QCloseEvent>
 #include <QDir>
 #include <QFileDialog>
 #include <QHBoxLayout>
@@ -130,9 +131,15 @@ void MussaWindow::setupActions()
   connect(createSubAnalysisAction, SIGNAL(triggered()), 
           this, SLOT(createSubAnalysis()));
 
-  saveAnalysisAction = new QAction(tr("Save Analysis"), this);
+  saveAnalysisAction = new QAction(tr("&Save Analysis"), this);
   connect(saveAnalysisAction, SIGNAL(triggered()), 
           this, SLOT(saveAnalysis()));
+  saveAnalysisAction->setIcon(QIcon(":/icons/filesave.png"));
+
+  saveAnalysisAsAction = new QAction(tr("Save Analysis &As"), this);
+  connect(saveAnalysisAsAction, SIGNAL(triggered()), 
+          this, SLOT(saveAnalysisAs()));
+  saveAnalysisAsAction->setIcon(QIcon(":/icons/filesave.png"));
 
   editMotifsAction = new QAction(tr("Edit Motifs"), this);;
   connect(editMotifsAction, SIGNAL(triggered()), this, SLOT(editMotifs()));
@@ -202,6 +209,15 @@ void MussaWindow::setupActions()
 
 }
 
+void MussaWindow::closeEvent(QCloseEvent *event)
+{
+  if(isClearingAnalysisSafe()) {
+    event->accept();
+  } else {
+    event->ignore();
+  }
+}
+
 void MussaWindow::setupMainMenu()
 {
   // we need to run setupActions first
@@ -214,6 +230,7 @@ void MussaWindow::setupMainMenu()
   newMenu->addAction(loadMupaAction);
   newMenu->addAction(loadSavedAnalysisAction);
   newMenu->addAction(saveAnalysisAction);
+  newMenu->addAction(saveAnalysisAsAction);
   newMenu->addSeparator();
   newMenu->addAction(loadMotifListAction);
   newMenu->addAction(saveMotifListAction);
@@ -311,6 +328,21 @@ void MussaWindow::createSubAnalysis()
 }
 
 void MussaWindow::saveAnalysis()
+{
+  // if we've got an analysis
+  if (analysis and not analysis->empty()) {
+    // if it doesn't have a name we need to pick one
+    if (analysis->get_analysis_path().empty()) {
+      saveAnalysisAs();
+    }      
+    // if we've got a name, has it changed any?
+    else if (analysis->is_dirty()) {
+      analysis->save();
+    }
+  }
+}
+
+void MussaWindow::saveAnalysisAs()
 {
   std::auto_ptr<QFileDialog> dialog(new QFileDialog(this));
   dialog->setAcceptMode(QFileDialog::AcceptSave);
@@ -343,6 +375,35 @@ void MussaWindow::saveAnalysis()
   analysis->save(save_path);
 }
 
+bool MussaWindow::isClearingAnalysisSafe()
+{
+  if (analysis and not analysis->empty() and analysis->is_dirty()) {
+    switch (QMessageBox::question(
+      this,
+      tr("Save Unsaved Changes -- Mussa"),
+      tr("There are unsaved changes,\ndo you want to save?"),
+      tr("&Yes"), tr("&No"), tr("&Cancel"),
+      0, 2)) {
+    case 0:
+      // save
+      saveAnalysis();
+      break;
+    case 1:
+      // don't save
+      break;
+    case 2:
+      // don't replace 
+      return false;
+      break;
+    default:
+      // error
+      throw runtime_error("isClearingAnalysis QMesageBox failure");
+    }
+  } 
+  // if we're here we've been saved and can replace
+  return true;
+}
+
 void MussaWindow::editMotifs()
 {
   if (motif_editor != 0) {
index fede80b8ee23dc72cf4a42e535a9e58d7b8ce121..ff23a5c96b756337e7dbc194a16dfc29bd257a86 100644 (file)
@@ -37,6 +37,11 @@ public:
 
   //! switch to a new analysis
   void setAnalysis(Mussa *new_analysis);
+
+  //! ask the user what to do if we're going to lose data
+  //! returns true if getting rid of this analysis is safe
+  bool isClearingAnalysisSafe();
+
 public slots:
   //! display an about box, contemplating the politics of the author list
   void about();
@@ -49,6 +54,8 @@ public slots:
   void createSubAnalysis();
   //! save an analysis
   void saveAnalysis();
+  //! save an analysis after prompting for new name
+  void saveAnalysisAs();
   //\@}
 
   //! \defgroup MotifHandling Handling of motif lists
@@ -104,6 +111,7 @@ protected:
   QAction *createNewAnalysisAction;
   QAction *createSubAnalysisAction;
   QAction *saveAnalysisAction;
+  QAction *saveAnalysisAsAction;
   QAction *editMotifsAction;
   QAction *loadMotifListAction;
   QAction *loadMupaAction;
@@ -121,6 +129,8 @@ protected:
 
   //! initialze the actions
   void setupActions();
+  //! handle close events (AKA prompt if we should save)
+  void closeEvent(QCloseEvent *event);
   //! initialize this windows menu object
   void setupMainMenu();
   //! initialize assistant client