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.
seqcomp();
the_paths.setup(window, threshold);
nway();
seqcomp();
the_paths.setup(window, threshold);
nway();
- // FIXME: once we implement a save feature we should remove this
- if (not analysis_name.empty()) {
- save();
- }
#include <QAction>
#include <QApplication>
#include <QAssistantClient>
#include <QAction>
#include <QApplication>
#include <QAssistantClient>
#include <QDir>
#include <QFileDialog>
#include <QHBoxLayout>
#include <QDir>
#include <QFileDialog>
#include <QHBoxLayout>
connect(createSubAnalysisAction, SIGNAL(triggered()),
this, SLOT(createSubAnalysis()));
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()));
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()));
editMotifsAction = new QAction(tr("Edit Motifs"), this);;
connect(editMotifsAction, SIGNAL(triggered()), this, SLOT(editMotifs()));
+void MussaWindow::closeEvent(QCloseEvent *event)
+{
+ if(isClearingAnalysisSafe()) {
+ event->accept();
+ } else {
+ event->ignore();
+ }
+}
+
void MussaWindow::setupMainMenu()
{
// we need to run setupActions first
void MussaWindow::setupMainMenu()
{
// we need to run setupActions first
newMenu->addAction(loadMupaAction);
newMenu->addAction(loadSavedAnalysisAction);
newMenu->addAction(saveAnalysisAction);
newMenu->addAction(loadMupaAction);
newMenu->addAction(loadSavedAnalysisAction);
newMenu->addAction(saveAnalysisAction);
+ newMenu->addAction(saveAnalysisAsAction);
newMenu->addSeparator();
newMenu->addAction(loadMotifListAction);
newMenu->addAction(saveMotifListAction);
newMenu->addSeparator();
newMenu->addAction(loadMotifListAction);
newMenu->addAction(saveMotifListAction);
}
void MussaWindow::saveAnalysis()
}
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);
{
std::auto_ptr<QFileDialog> dialog(new QFileDialog(this));
dialog->setAcceptMode(QFileDialog::AcceptSave);
analysis->save(save_path);
}
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) {
void MussaWindow::editMotifs()
{
if (motif_editor != 0) {
//! switch to a new analysis
void setAnalysis(Mussa *new_analysis);
//! 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();
public slots:
//! display an about box, contemplating the politics of the author list
void about();
void createSubAnalysis();
//! save an analysis
void saveAnalysis();
void createSubAnalysis();
//! save an analysis
void saveAnalysis();
+ //! save an analysis after prompting for new name
+ void saveAnalysisAs();
//\@}
//! \defgroup MotifHandling Handling of motif lists
//\@}
//! \defgroup MotifHandling Handling of motif lists
QAction *createNewAnalysisAction;
QAction *createSubAnalysisAction;
QAction *saveAnalysisAction;
QAction *createNewAnalysisAction;
QAction *createSubAnalysisAction;
QAction *saveAnalysisAction;
+ QAction *saveAnalysisAsAction;
QAction *editMotifsAction;
QAction *loadMotifListAction;
QAction *loadMupaAction;
QAction *editMotifsAction;
QAction *loadMotifListAction;
QAction *loadMupaAction;
//! initialze the actions
void setupActions();
//! 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
//! initialize this windows menu object
void setupMainMenu();
//! initialize assistant client