|
From: Tapio V. <aa...@us...> - 2011-01-18 08:31:10
|
Module: editor
Branch: master
Commit: 735348034931f386d042eb1fb7f011f561d54faa
Author: Tapio Vierros <tap...@gm...>
Date: Tue Jan 18 10:30:06 2011 +0200
Refactor prompting for saving unsaved changes.
---
editorapp.cc | 51 +++++++++++++++++++++------------------------------
editorapp.hh | 6 +++++-
2 files changed, 26 insertions(+), 31 deletions(-)
diff --git a/editorapp.cc b/editorapp.cc
index 0ad985a..de36fac 100644
--- a/editorapp.cc
+++ b/editorapp.cc
@@ -132,21 +132,7 @@ void EditorApp::updateNoteInfo(NoteLabel *note)
void EditorApp::on_actionNew_triggered()
{
- // TODO: Check if a save prompt is in order
- if (hasUnsavedChanges) {
- QMessageBox::StandardButton b = QMessageBox::question(this, tr("Unsaved changes"),
- tr("There are unsaved changes. Do you wish to save before creating a new project?"),
- QMessageBox::Yes | QMessageBox::No | QMessageBox::Cancel);
- switch(b) {
- case QMessageBox::Yes:
- on_actionSave_triggered();
- case QMessageBox::No:
- noteGraph->clear();
- projectFileName = "";
- break;
- default: break;
- }
- } else {
+ if (promptSaving()) {
noteGraph->clear();
projectFileName = "";
}
@@ -155,6 +141,8 @@ void EditorApp::on_actionNew_triggered()
void EditorApp::on_actionOpen_triggered()
{
+ if (!promptSaving()) return;
+
QString fileName = QFileDialog::getOpenFileName(this, tr("Open File"),
QDir::homePath(),
tr("All supported formats") + "(*." + PROJECT_SAVE_FILE_EXTENSION + " *.xml *.mid *.ini *.txt);;" +
@@ -234,6 +222,23 @@ void EditorApp::on_actionSaveAs_triggered()
}
}
+bool EditorApp::promptSaving()
+{
+ if (hasUnsavedChanges) {
+ QMessageBox::StandardButton b = QMessageBox::question(this, tr("Unsaved changes"),
+ tr("There are unsaved changes, which would be lost. Save now?"),
+ QMessageBox::Yes | QMessageBox::No | QMessageBox::Cancel);
+ switch(b) {
+ case QMessageBox::Yes:
+ on_actionSave_triggered();
+ case QMessageBox::No:
+ return true;
+ default: break;
+ }
+ }
+ return false;
+}
+
void EditorApp::saveProject(QString fileName)
{
QFile f(fileName);
@@ -285,21 +290,7 @@ void EditorApp::on_actionFoFMIDI_triggered()
void EditorApp::on_actionExit_triggered()
{
- // TODO: Check if a save prompt is in order
- if (hasUnsavedChanges) {
- QMessageBox::StandardButton b = QMessageBox::question(this, tr("Unsaved changes"),
- tr("There are unsaved changes. Do you wish to save before quitting?"),
- QMessageBox::Yes | QMessageBox::No | QMessageBox::Cancel);
- switch(b) {
- case QMessageBox::Yes:
- on_actionSave_triggered();
- case QMessageBox::No:
- close(); break;
- default: break;
- }
- } else {
- close();
- }
+ if (promptSaving()) close();
}
void EditorApp::on_actionUndo_triggered()
diff --git a/editorapp.hh b/editorapp.hh
index 81b400d..4f72627 100644
--- a/editorapp.hh
+++ b/editorapp.hh
@@ -1,6 +1,7 @@
#pragma once
#include <QtMultimediaKit/QMediaPlayer>
+#include <QMessageBox>
#include "ui_editor.h"
#include "operation.hh"
#include "song.hh"
@@ -17,9 +18,12 @@ public:
EditorApp(QWidget *parent = 0);
void updateSongMeta(bool readFromSongToUI = false);
+ void updateMenuStates();
+
+private:
+ bool promptSaving();
void saveProject(QString fileName);
void doOpStack();
- void updateMenuStates();
public slots:
void operationDone(const Operation &op);
|