changeset 313:eef5c50e7e34

Introduce a new canSaveAs which is active whenever there is a main model; avoid silently overwriting existing session file when saving to audio path
author Chris Cannam
date Fri, 13 Jun 2014 10:37:04 +0100
parents 111bf81a5c96
children 2a2fd6eb8fa8
files .hgsubstate src/MainWindow.cpp
diffstat 2 files changed, 21 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/.hgsubstate	Fri Jun 13 09:25:00 2014 +0100
+++ b/.hgsubstate	Fri Jun 13 10:37:04 2014 +0100
@@ -2,6 +2,6 @@
 236814e07bd07473958c1ff89103124536a0c3c8 dataquay
 b8ce40de83c25bf4585b3a03ddc67d215df31899 pyin
 553a5f65ef64811747a6613f759622d655db63c1 sv-dependency-builds
-2da91cceed643d914b4524c834990228d83eab8e svapp
+1f2a4ad79967cf85e976332a508d5161e386bd8d svapp
 e88a15c25a4a5323be1b339c03218c9a1001d0f3 svcore
 9c272d39c3e3124c64173404db9ecac3ddccde8e svgui
--- a/src/MainWindow.cpp	Fri Jun 13 09:25:00 2014 +0100
+++ b/src/MainWindow.cpp	Fri Jun 13 10:37:04 2014 +0100
@@ -475,16 +475,17 @@
     action->setShortcut(tr("Ctrl+Shift+S"));
     action->setStatusTip(tr("Save the current session into a new %1 session file").arg(QApplication::applicationName()));
     connect(action, SIGNAL(triggered()), this, SLOT(saveSessionAs()));
+    connect(this, SIGNAL(canSaveAs(bool)), action, SLOT(setEnabled(bool)));
     menu->addAction(action);
     toolbar->addAction(action);
 
     icon = il.load("filesave");
     icon.addPixmap(il.loadPixmap("filesave-22"));
-    action = new QAction(icon, tr("Save Session In &Audio Path"), this);
+    action = new QAction(icon, tr("Save Session to Audio &Path"), this);
     action->setShortcut(tr("Ctrl+Alt+S"));
-    action->setStatusTip(tr("Save the current session into a %1 session file with the same path and filename but .ton extension.").arg(QApplication::applicationName()));
+    action->setStatusTip(tr("Save the current session into a %1 session file with the same filename as the audio but a .ton extension.").arg(QApplication::applicationName()));
     connect(action, SIGNAL(triggered()), this, SLOT(saveSessionInAudioPath()));
-    connect(this, SIGNAL(canSave(bool)), action, SLOT(setEnabled(bool)));
+    connect(this, SIGNAL(canSaveAs(bool)), action, SLOT(setEnabled(bool)));
     menu->addAction(action);
 
     menu->addSeparator();
@@ -1804,7 +1805,6 @@
 void
 MainWindow::saveSessionInAudioPath()
 {
-
     if (m_audioFile == "") return;
 
     // We do not want to save mid-analysis regions -- that would cause
@@ -1819,6 +1819,22 @@
 
     cerr << path << endl;
 
+    // We don't want to overwrite an existing .ton file unless we put
+    // it there in the first place
+    bool shouldVerify = true;
+    if (m_sessionFile == path) {
+        shouldVerify = false;
+    }
+
+    if (shouldVerify && QFileInfo(path).exists()) {
+        if (QMessageBox::question(0, tr("File exists"),
+                                  tr("<b>File exists</b><p>The file \"%1\" already exists.\nDo you want to overwrite it?").arg(path),
+                                  QMessageBox::Ok,
+                                  QMessageBox::Cancel) != QMessageBox::Ok) {
+            return;
+        }
+    }
+
     if (!saveSessionFile(path)) {
         QMessageBox::critical(this, tr("Failed to save file"),
                               tr("Session file \"%1\" could not be saved.").arg(path));