Confirmation on overwrite for track and session templates. -fixes #6587
authorAndré Nusser <andre.nusser@googlemail.com>
Mon, 12 Oct 2015 10:29:16 +0000 (12:29 +0200)
committerPaul Davis <paul@linuxaudiosystems.com>
Thu, 22 Oct 2015 03:28:44 +0000 (23:28 -0400)
gtk2_ardour/ardour_ui.cc
gtk2_ardour/route_ui.cc
gtk2_ardour/utils.cc
gtk2_ardour/utils.h

index e29c1bbf8de49a4a73ec94d5c6453d451ce2b132..4e016d266ae3a7ce14108acd9b9be40d9f3174e7 100644 (file)
@@ -2495,16 +2495,8 @@ ARDOUR_UI::snapshot_session (bool switch_to_it)
                vector<string> n = get_file_names_no_extension (p);
                if (find (n.begin(), n.end(), snapname) != n.end()) {
 
-                       ArdourDialog confirm (_("Confirm Snapshot Overwrite"), true);
-                       Label m (_("A snapshot already exists with that name.  Do you want to overwrite it?"));
-                       confirm.get_vbox()->pack_start (m, true, true);
-                       confirm.add_button (Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
-                       confirm.add_button (_("Overwrite"), Gtk::RESPONSE_ACCEPT);
-                       confirm.show_all ();
-                       switch (confirm.run()) {
-                       case RESPONSE_CANCEL:
-                               do_save = false;
-                       }
+                       do_save = overwrite_file_dialog (_("Confirm Snapshot Overwrite"),
+                                                        _("A snapshot already exists with that name. Do you want to overwrite it?"));
                }
 
                if (do_save) {
@@ -2690,7 +2682,16 @@ ARDOUR_UI::save_template ()
                prompter.get_result (name);
 
                if (name.length()) {
-                       _session->save_template (name);
+                       int failed = _session->save_template (name);
+
+                       if (failed == -2) { /* file already exists. */
+                               bool overwrite = overwrite_file_dialog (_("Confirm Template Overwrite"),
+                                                                       _("A template already exists with that name. Do you want to overwrite it?"));
+
+                               if (overwrite) {
+                                       _session->save_template (name, true);
+                               }
+                       }
                }
                break;
 
index 79506f7bd32b5a18ab1a9d1e00adc03a71c6732e..2f45756c27f25e64197395cb2eed822a7df3eeb6 100644 (file)
@@ -1863,13 +1863,20 @@ RouteUI::save_as_template ()
                return;
        }
 
-       p.hide ();
        p.get_result (name, true);
 
        safe_name = legalize_for_path (name);
        safe_name += template_suffix;
 
        path = Glib::build_filename (path, safe_name);
+       if (Glib::file_test (path, Glib::FILE_TEST_EXISTS)) {
+               bool overwrite = overwrite_file_dialog (_("Confirm Template Overwrite"),
+                                                       _("A template already exists with that name. Do you want to overwrite it?"));
+
+               if (!overwrite) {
+                       return;
+               }
+       }
 
        _route->save_as_template (path, name);
 }
index a04770836017642b6c8dee80d8d8d47be7ff8700..cf3ca7d7dde3d8f34f31f2bbba433ab9496c57db 100644 (file)
@@ -53,6 +53,7 @@
 #include "rgb_macros.h"
 #include "gui_thread.h"
 #include "ui_config.h"
+#include "ardour_dialog.h"
 
 using namespace std;
 using namespace Gtk;
@@ -926,3 +927,24 @@ ARDOUR_UI_UTILS::windows_overlap (Gtk::Window *a, Gtk::Window *b)
        }
        return false;
 }
+
+bool
+ARDOUR_UI_UTILS::overwrite_file_dialog (string title, string text)
+{
+       ArdourDialog dialog (title, true);
+       Label label (text);
+
+       dialog.get_vbox()->pack_start (label, true, true);
+       dialog.add_button (Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
+       dialog.add_button (_("Overwrite"), Gtk::RESPONSE_ACCEPT);
+       dialog.set_position (Gtk::WIN_POS_MOUSE);
+       dialog.show_all ();
+
+       switch (dialog.run()) {
+       case RESPONSE_ACCEPT:
+               return true;
+       case RESPONSE_CANCEL:
+       default:
+               return false;
+       }
+}
index a7f1e16f0beb9b6232bfbe6dbf3d4a96d0f46691..ebf966eba9c568415175288f170ddb9cb32c2881 100644 (file)
@@ -92,5 +92,7 @@ std::string rate_as_string (float r);
 
 bool windows_overlap (Gtk::Window *a, Gtk::Window *b);
 
+bool overwrite_file_dialog (std::string title, std::string text);
+
 } // namespace
 #endif /* __ardour_gtk_utils_h__ */