From 67f557b1f4fd1f1ecd9d38f14d83a12a294cb455 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Nusser?= Date: Mon, 12 Oct 2015 12:27:28 +0200 Subject: [PATCH 1/3] Add overwrite option to save_template. (default = false) Before it could not overwrite. --- libs/ardour/ardour/session.h | 2 +- libs/ardour/session_state.cc | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/libs/ardour/ardour/session.h b/libs/ardour/ardour/session.h index 054862ce8a..0a2cb786ce 100644 --- a/libs/ardour/ardour/session.h +++ b/libs/ardour/ardour/session.h @@ -459,7 +459,7 @@ class LIBARDOUR_API Session : public PBD::StatefulDestructible, public PBD::Scop int save_as (SaveAs&); int save_state (std::string snapshot_name, bool pending = false, bool switch_to_snapshot = false, bool template_only = false); int restore_state (std::string snapshot_name); - int save_template (std::string template_name); + int save_template (std::string template_name, bool replace_existing = false); int save_history (std::string snapshot_name = ""); int restore_history (std::string snapshot_name); void remove_state (std::string snapshot_name); diff --git a/libs/ardour/session_state.cc b/libs/ardour/session_state.cc index 3ccc4d606f..036e023dff 100644 --- a/libs/ardour/session_state.cc +++ b/libs/ardour/session_state.cc @@ -2102,7 +2102,7 @@ Session::XMLSourceFactory (const XMLNode& node) } int -Session::save_template (string template_name) +Session::save_template (string template_name, bool replace_existing) { if ((_state_of_the_state & CannotSave) || template_name.empty ()) { return -1; @@ -2128,10 +2128,10 @@ Session::save_template (string template_name) } if (!ARDOUR::Profile->get_trx()) { - if (Glib::file_test (template_dir_path, Glib::FILE_TEST_EXISTS)) { + if (!replace_existing && Glib::file_test (template_dir_path, Glib::FILE_TEST_EXISTS)) { warning << string_compose(_("Template \"%1\" already exists - new version not created"), template_dir_path) << endmsg; - return -1; + return -2; } if (g_mkdir_with_parents (template_dir_path.c_str(), 0755) != 0) { From 5d50abed75de5428c025e61224068387ab15e26d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Nusser?= Date: Mon, 12 Oct 2015 12:29:16 +0200 Subject: [PATCH 2/3] Confirmation on overwrite for track and session templates. -fixes #6587 --- gtk2_ardour/ardour_ui.cc | 23 ++++++++++++----------- gtk2_ardour/route_ui.cc | 9 ++++++++- gtk2_ardour/utils.cc | 22 ++++++++++++++++++++++ gtk2_ardour/utils.h | 2 ++ 4 files changed, 44 insertions(+), 12 deletions(-) diff --git a/gtk2_ardour/ardour_ui.cc b/gtk2_ardour/ardour_ui.cc index e29c1bbf8d..4e016d266a 100644 --- a/gtk2_ardour/ardour_ui.cc +++ b/gtk2_ardour/ardour_ui.cc @@ -2495,16 +2495,8 @@ ARDOUR_UI::snapshot_session (bool switch_to_it) vector 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; diff --git a/gtk2_ardour/route_ui.cc b/gtk2_ardour/route_ui.cc index 79506f7bd3..2f45756c27 100644 --- a/gtk2_ardour/route_ui.cc +++ b/gtk2_ardour/route_ui.cc @@ -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); } diff --git a/gtk2_ardour/utils.cc b/gtk2_ardour/utils.cc index a047708360..cf3ca7d7dd 100644 --- a/gtk2_ardour/utils.cc +++ b/gtk2_ardour/utils.cc @@ -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; + } +} diff --git a/gtk2_ardour/utils.h b/gtk2_ardour/utils.h index a7f1e16f0b..ebf966eba9 100644 --- a/gtk2_ardour/utils.h +++ b/gtk2_ardour/utils.h @@ -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__ */ From 2c4e79d0a087ab1aafb5aa53ce0e88c3b74220bc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Nusser?= Date: Mon, 12 Oct 2015 13:01:05 +0200 Subject: [PATCH 3/3] Also use overwrite_file_dialog at all the other places. --- gtk2_ardour/editor_export_audio.cc | 34 ++++++++---------------------- gtk2_ardour/utils_videotl.cc | 14 ++++++------ 2 files changed, 16 insertions(+), 32 deletions(-) diff --git a/gtk2_ardour/editor_export_audio.cc b/gtk2_ardour/editor_export_audio.cc index 57baf2ce2d..c886885dd2 100644 --- a/gtk2_ardour/editor_export_audio.cc +++ b/gtk2_ardour/editor_export_audio.cc @@ -51,6 +51,7 @@ #include "public_editor.h" #include "selection.h" #include "time_axis_view.h" +#include "utils.h" #include "i18n.h" @@ -141,35 +142,18 @@ Editor::export_region () string path = dialog.get_path (); if (Glib::file_test (path, Glib::FILE_TEST_EXISTS)) { + bool overwrite = ARDOUR_UI_UTILS::overwrite_file_dialog (_("Confirm MIDI File Overwrite"), + _("A file with the same name already exists. Do you want to overwrite it?")); - MessageDialog checker (_("File Exists!"), - true, - Gtk::MESSAGE_WARNING, - Gtk::BUTTONS_NONE); - - checker.set_title (_("File Exists!")); - - checker.add_button (Stock::CANCEL, RESPONSE_CANCEL); - checker.add_button (_("Overwrite Existing File"), RESPONSE_ACCEPT); - checker.set_default_response (RESPONSE_CANCEL); - - checker.set_wmclass (X_("midi_export_file_exists"), PROGRAM_NAME); - checker.set_position (Gtk::WIN_POS_MOUSE); - - ret = checker.run (); - - switch (ret) { - case Gtk::RESPONSE_ACCEPT: - /* force ::g_unlink because the backend code will - go wrong if it tries to open an existing - file for writing. - */ - ::g_unlink (path.c_str()); - break; - default: + if (!overwrite) { return; } + /* force ::g_unlink because the backend code will + go wrong if it tries to open an existing + file for writing. + */ + ::g_unlink (path.c_str()); } (void) midi_region->clone (path); diff --git a/gtk2_ardour/utils_videotl.cc b/gtk2_ardour/utils_videotl.cc index 51cbe1a1dd..0c94f378f0 100644 --- a/gtk2_ardour/utils_videotl.cc +++ b/gtk2_ardour/utils_videotl.cc @@ -28,6 +28,7 @@ #include "ardour/session_directory.h" #include "video_image_frame.h" #include "utils_videotl.h" +#include "utils.h" #ifdef WAF_BUILD #include "gtk2ardour-version.h" @@ -67,13 +68,12 @@ VideoUtils::confirm_video_outfn (std::string outfn, std::string docroot) } if (Glib::file_test(outfn, Glib::FILE_TEST_EXISTS)) { - ArdourDialog confirm (_("Confirm Overwrite"), true); - Label m (_("A file with the same name already exists. 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 (); - if (confirm.run() == RESPONSE_CANCEL) { return false; } + bool overwrite = ARDOUR_UI_UTILS::overwrite_file_dialog (_("Confirm Overwrite"), + _("A file with the same name already exists. Do you want to overwrite it?")); + + if (!overwrite) { + return false; + } } std::string dir = Glib::path_get_dirname (outfn);