#include <QAction>
#include <QApplication>
#include <QAssistantClient>
+#include <QCloseEvent>
#include <QDir>
#include <QFileDialog>
#include <QHBoxLayout>
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()));
}
+void MussaWindow::closeEvent(QCloseEvent *event)
+{
+ if(isClearingAnalysisSafe()) {
+ event->accept();
+ } else {
+ event->ignore();
+ }
+}
+
void MussaWindow::setupMainMenu()
{
// we need to run setupActions first
newMenu->addAction(loadMupaAction);
newMenu->addAction(loadSavedAnalysisAction);
newMenu->addAction(saveAnalysisAction);
+ newMenu->addAction(saveAnalysisAsAction);
newMenu->addSeparator();
newMenu->addAction(loadMotifListAction);
newMenu->addAction(saveMotifListAction);
}
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);
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) {
//! 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();
void createSubAnalysis();
//! save an analysis
void saveAnalysis();
+ //! save an analysis after prompting for new name
+ void saveAnalysisAs();
//\@}
//! \defgroup MotifHandling Handling of motif lists
QAction *createNewAnalysisAction;
QAction *createSubAnalysisAction;
QAction *saveAnalysisAction;
+ QAction *saveAnalysisAsAction;
QAction *editMotifsAction;
QAction *loadMotifListAction;
QAction *loadMupaAction;
//! 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