summaryrefslogtreecommitdiffstats
path: root/qt-ui/mainwindow.cpp
diff options
context:
space:
mode:
authorGravatar Dirk Hohndel <dirk@hohndel.org>2014-06-08 19:46:43 -0700
committerGravatar Dirk Hohndel <dirk@hohndel.org>2014-06-08 19:49:25 -0700
commit6f568fbecd018736cb7ea41d83e3d78b647185b3 (patch)
tree4114cdd8909bdb0e752b68cedfbf96170a7fd264 /qt-ui/mainwindow.cpp
parenta70a0662f5a1278260ba03180ea947032d8f6885 (diff)
downloadsubsurface-6f568fbecd018736cb7ea41d83e3d78b647185b3.tar.gz
Simplify the code that checks if it's OK to close the current file
And make sure it gets called whenever it needs to get called - it was missing from the openRecentFile case. Fixes #530 Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'qt-ui/mainwindow.cpp')
-rw-r--r--qt-ui/mainwindow.cpp34
1 files changed, 23 insertions, 11 deletions
diff --git a/qt-ui/mainwindow.cpp b/qt-ui/mainwindow.cpp
index 99539a0a4..8f9478a6a 100644
--- a/qt-ui/mainwindow.cpp
+++ b/qt-ui/mainwindow.cpp
@@ -175,16 +175,14 @@ void MainWindow::on_actionNew_triggered()
void MainWindow::on_actionOpen_triggered()
{
- if (DivePlannerPointsModel::instance()->currentMode() != DivePlannerPointsModel::NOTHING ||
- ui.InfoWidget->isEditing()) {
- QMessageBox::warning(this, tr("Warning"), tr("Please save or cancel the current dive edit before opening a new file."));
+ if (!okToClose(tr("Please save or cancel the current dive edit before opening a new file.")))
return;
- }
+
QString filename = QFileDialog::getOpenFileName(this, tr("Open File"), lastUsedDir(), filter());
if (filename.isEmpty())
return;
updateLastUsedDir(QFileInfo(filename).dir().path());
- on_actionClose_triggered();
+ closeCurrentFile();
loadFiles(QStringList() << filename);
}
@@ -234,16 +232,21 @@ void MainWindow::setToolButtonsEnabled(bool enabled)
ui.profHR->setEnabled(enabled);
}
-void MainWindow::on_actionClose_triggered()
+bool MainWindow::okToClose(QString message)
{
if (DivePlannerPointsModel::instance()->currentMode() != DivePlannerPointsModel::NOTHING ||
ui.InfoWidget->isEditing()) {
- QMessageBox::warning(this, tr("Warning"), tr("Please save or cancel the current dive edit before closing the file."));
- return;
+ QMessageBox::warning(this, tr("Warning"), message);
+ return false;
}
- if (unsaved_changes() && (askSaveChanges() == false))
- return;
+ if (unsaved_changes() && askSaveChanges() == false)
+ return false;
+ return true;
+}
+
+void MainWindow::closeCurrentFile()
+{
ui.newProfile->setEmptyState();
/* free the dives and trips */
clear_git_id();
@@ -263,6 +266,12 @@ void MainWindow::on_actionClose_triggered()
clear_events();
}
+void MainWindow::on_actionClose_triggered()
+{
+ if (okToClose(tr("Please save or cancel the current dive edit before closing the file.")))
+ closeCurrentFile();
+}
+
QString MainWindow::lastUsedDir()
{
QSettings settings;
@@ -1001,12 +1010,15 @@ void MainWindow::recentFileTriggered(bool checked)
{
Q_UNUSED(checked);
+ if (!okToClose(tr("Please save or cancel the current dive edit before opening a new file.")))
+ return;
+
QAction *actionRecent = (QAction *)sender();
const QString &filename = actionRecent->toolTip();
updateLastUsedDir(QFileInfo(filename).dir().path());
- on_actionClose_triggered();
+ closeCurrentFile();
loadFiles(QStringList() << filename);
}