From ee234bc9b856097bd7910f883a0bbfcd9f24f3b9 Mon Sep 17 00:00:00 2001 From: Diane Trout Date: Tue, 12 Sep 2006 23:37:27 +0000 Subject: [PATCH] implement "typical" save and close conventions. 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 | 4 --- qui/MussaWindow.cpp | 63 ++++++++++++++++++++++++++++++++++++++++++++- qui/MussaWindow.hpp | 10 +++++++ 3 files changed, 72 insertions(+), 5 deletions(-) diff --git a/alg/mussa.cpp b/alg/mussa.cpp index 194501d..cc5825e 100644 --- a/alg/mussa.cpp +++ b/alg/mussa.cpp @@ -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 diff --git a/qui/MussaWindow.cpp b/qui/MussaWindow.cpp index 1e8d06c..8d51ab5 100644 --- a/qui/MussaWindow.cpp +++ b/qui/MussaWindow.cpp @@ -5,6 +5,7 @@ #include #include #include +#include #include #include #include @@ -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 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) { diff --git a/qui/MussaWindow.hpp b/qui/MussaWindow.hpp index fede80b..ff23a5c 100644 --- a/qui/MussaWindow.hpp +++ b/qui/MussaWindow.hpp @@ -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 -- 2.30.2