Improve behavior of overwrite_file_dialog.
authorAndré Nusser <andre.nusser@googlemail.com>
Sun, 1 Nov 2015 20:00:05 +0000 (21:00 +0100)
committerPaul Davis <paul@linuxaudiosystems.com>
Wed, 4 Nov 2015 22:52:00 +0000 (17:52 -0500)
- Make overwrite file dialogs transient.
- Cancelling the overwrite dialog doesn't close initial dialog.

12 files changed:
gtk2_ardour/ardour_ui.cc
gtk2_ardour/ardour_ui.h
gtk2_ardour/editor.h
gtk2_ardour/editor_export_audio.cc
gtk2_ardour/export_video_dialog.cc
gtk2_ardour/route_ui.cc
gtk2_ardour/route_ui.h
gtk2_ardour/transcode_video_dialog.cc
gtk2_ardour/utils.cc
gtk2_ardour/utils.h
gtk2_ardour/utils_videotl.cc
gtk2_ardour/utils_videotl.h

index 15106d79ef229edbb1bf818045f03f348dafb196..e9d9938e3433439b1d39d0789ea59dafcafe71a6 100644 (file)
@@ -2442,6 +2442,47 @@ ARDOUR_UI::save_session_as ()
        }
 }
 
+bool
+ARDOUR_UI::process_snapshot_session_prompter (ArdourPrompter& prompter, bool switch_to_it)
+{
+       string snapname;
+
+       prompter.get_result (snapname);
+
+       bool do_save = (snapname.length() != 0);
+
+       if (do_save) {
+               char illegal = Session::session_name_is_legal(snapname);
+               if (illegal) {
+                       MessageDialog msg (string_compose (_("To ensure compatibility with various systems\n"
+                                            "snapshot names may not contain a '%1' character"), illegal));
+                       msg.run ();
+                       return false;
+               }
+       }
+
+       vector<std::string> p;
+       get_state_files_in_directory (_session->session_directory().root_path(), p);
+       vector<string> n = get_file_names_no_extension (p);
+
+       if (find (n.begin(), n.end(), snapname) != n.end()) {
+
+               do_save = overwrite_file_dialog (prompter,
+                                                _("Confirm Snapshot Overwrite"),
+                                                _("A snapshot already exists with that name. Do you want to overwrite it?"));
+       }
+
+       if (do_save) {
+               save_state (snapname, switch_to_it);
+       }
+       else {
+               return false;
+       }
+
+       return true;
+}
+
+
 /** Ask the user for the name of a new snapshot and then take it.
  */
 
@@ -2449,7 +2490,6 @@ void
 ARDOUR_UI::snapshot_session (bool switch_to_it)
 {
        ArdourPrompter prompter (true);
-       string snapname;
 
        prompter.set_name ("Prompter");
        prompter.add_button (Gtk::Stock::SAVE, Gtk::RESPONSE_ACCEPT);
@@ -2472,41 +2512,19 @@ ARDOUR_UI::snapshot_session (bool switch_to_it)
                prompter.set_initial_text (timebuf);
        }
 
-  again:
-       switch (prompter.run()) {
-       case RESPONSE_ACCEPT:
-       {
-               prompter.get_result (snapname);
-
-               bool do_save = (snapname.length() != 0);
-
-               if (do_save) {
-                       char illegal = Session::session_name_is_legal(snapname);
-                       if (illegal) {
-                               MessageDialog msg (string_compose (_("To ensure compatibility with various systems\n"
-                                                    "snapshot names may not contain a '%1' character"), illegal));
-                               msg.run ();
-                               goto again;
-                       }
-               }
-
-               vector<std::string> p;
-               get_state_files_in_directory (_session->session_directory().root_path(), p);
-               vector<string> n = get_file_names_no_extension (p);
-               if (find (n.begin(), n.end(), snapname) != n.end()) {
-
-                       do_save = overwrite_file_dialog (_("Confirm Snapshot Overwrite"),
-                                                        _("A snapshot already exists with that name. Do you want to overwrite it?"));
+       bool finished = false;
+       while (!finished) {
+               switch (prompter.run()) {
+               case RESPONSE_ACCEPT:
+               {
+                       finished = process_snapshot_session_prompter (prompter, switch_to_it);
+                       break;
                }
 
-               if (do_save) {
-                       save_state (snapname, switch_to_it);
+               default:
+                       finished = true;
+                       break;
                }
-               break;
-       }
-
-       default:
-               break;
        }
 }
 
@@ -2661,11 +2679,37 @@ ARDOUR_UI::transport_rec_enable_blink (bool onoff)
        }
 }
 
+bool
+ARDOUR_UI::process_save_template_prompter (ArdourPrompter& prompter)
+{
+       string name;
+
+       prompter.get_result (name);
+
+       if (name.length()) {
+               int failed = _session->save_template (name);
+
+               if (failed == -2) { /* file already exists. */
+                       bool overwrite = overwrite_file_dialog (prompter,
+                                                               _("Confirm Template Overwrite"),
+                                                               _("A template already exists with that name. Do you want to overwrite it?"));
+
+                       if (overwrite) {
+                               _session->save_template (name, true);
+                       }
+                       else {
+                               return false;
+                       }
+               }
+       }
+
+       return true;
+}
+
 void
 ARDOUR_UI::save_template ()
 {
        ArdourPrompter prompter (true);
-       string name;
 
        if (!check_audioengine(*editor)) {
                return;
@@ -2677,26 +2721,17 @@ ARDOUR_UI::save_template ()
        prompter.set_initial_text(_session->name() + _("-template"));
        prompter.add_button (Gtk::Stock::SAVE, Gtk::RESPONSE_ACCEPT);
 
-       switch (prompter.run()) {
-       case RESPONSE_ACCEPT:
-               prompter.get_result (name);
-
-               if (name.length()) {
-                       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?"));
+       bool finished = false;
+       while (!finished) {
+               switch (prompter.run()) {
+               case RESPONSE_ACCEPT:
+                       finished = process_save_template_prompter (prompter);
+                       break;
 
-                               if (overwrite) {
-                                       _session->save_template (name, true);
-                               }
-                       }
+               default:
+                       finished = true;
+                       break;
                }
-               break;
-
-       default:
-               break;
        }
 }
 
index 1c00d9893f0c97869dccb066c8ecb3ed22fefcd9..b43b2d62a248ce32fae272750964d5f7c3c25b80 100644 (file)
@@ -114,6 +114,7 @@ class ButtonJoiner;
 class ConnectionEditor;
 class MainClock;
 class Mixer_UI;
+class ArdourPrompter;
 class PublicEditor;
 class SaveAsDialog;
 class SessionDialog;
@@ -555,6 +556,7 @@ class ARDOUR_UI : public Gtkmm2ext::UI, public ARDOUR::SessionHandlePtr
 
        void open_session ();
        void open_recent_session ();
+       bool process_save_template_prompter (ArdourPrompter& prompter);
        void save_template ();
 
        void edit_metadata ();
@@ -598,6 +600,7 @@ class ARDOUR_UI : public Gtkmm2ext::UI, public ARDOUR::SessionHandlePtr
 
        guint32  last_key_press_time;
 
+       bool process_snapshot_session_prompter (ArdourPrompter& prompter, bool switch_to_it);
        void snapshot_session (bool switch_to_it);
 
        SaveAsDialog* save_as_dialog;
index c38e355c05bd39a0a914d5f6e29b9776ef26cd65..77156cbb4cafe4c173186007be78a5c7503f6def 100644 (file)
@@ -74,6 +74,7 @@ namespace ARDOUR {
        class Filter;
        class Location;
        class MidiOperator;
+       class MidiRegion;
        class MidiTrack;
        class Playlist;
        class Region;
@@ -113,6 +114,7 @@ class GroupedButtons;
 class GUIObjectState;
 class ArdourMarker;
 class MidiRegionView;
+class MidiExportDialog;
 class MixerStrip;
 class MouseCursors;
 class NoteBase;
@@ -282,6 +284,8 @@ class Editor : public PublicEditor, public PBD::ScopedConnectionList, public ARD
        void export_range ();
        void export_region ();
 
+       bool process_midi_export_dialog (MidiExportDialog& dialog, boost::shared_ptr<ARDOUR::MidiRegion> midi_region);
+
        void add_transport_frame (Gtk::Container&);
        void add_toplevel_menu (Gtk::Container&);
        Gtk::HBox& get_status_bar_packer()  { return status_bar_hpacker; }
index c886885dd23849fd6fa5652620bd0e6316748c69..2bd607f10871a9a833aced746997eed9b4bccb61 100644 (file)
@@ -104,6 +104,32 @@ Editor::export_range ()
        }
 }
 
+bool
+Editor::process_midi_export_dialog (MidiExportDialog& dialog, boost::shared_ptr<MidiRegion> midi_region)
+{
+       string path = dialog.get_path ();
+
+       if (Glib::file_test (path, Glib::FILE_TEST_EXISTS)) {
+               bool overwrite = ARDOUR_UI_UTILS::overwrite_file_dialog (dialog,
+                                                                        _("Confirm MIDI File Overwrite"),
+                                                                        _("A file with the same name already exists. Do you want to overwrite it?"));
+
+               if (!overwrite) {
+                       return false;
+               }
+
+               /* 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);
+
+       return true;
+}
+
 /** Export the first selected region */
 void
 Editor::export_region ()
@@ -129,34 +155,18 @@ Editor::export_region ()
 
                MidiExportDialog dialog (*this, midi_region);
                dialog.set_session (_session);
-               int ret = dialog.run ();
-               switch (ret) {
-               case Gtk::RESPONSE_ACCEPT:
-                       break;
-               default:
-                       return;
-               }
-
-               dialog.hide ();
-
-               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?"));
-
-                       if (!overwrite) {
+               bool finished = false;
+               while (!finished) {
+                       switch (dialog.run ()) {
+                       case Gtk::RESPONSE_ACCEPT:
+                               finished = process_midi_export_dialog (dialog, midi_region);
+                               break;
+                       default:
+                               finished = true;
                                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);
        }
 }
 
index a21a9037e2d99be6d4aaf51fc6d51e484b8f4ced..98f5306ad073815363f26d3c48605921b90fc5e6 100644 (file)
@@ -619,7 +619,7 @@ ExportVideoDialog::launch_export ()
        _session->add_extra_xml (get_state());
 
        std::string outfn = outfn_path_entry.get_text();
-       if (!confirm_video_outfn(outfn)) { return; }
+       if (!confirm_video_outfn(*this, outfn)) { return; }
 
        vbox->hide();
        cancel_button->hide();
index 2f45756c27f25e64197395cb2eed822a7df3eeb6..8cb91020c3d01ffd41e3b2b7b01c4728ff6a1375 100644 (file)
@@ -1837,48 +1837,64 @@ RouteUI::adjust_latency ()
        LatencyDialog dialog (_route->name() + _(" latency"), *(_route->output()), _session->frame_rate(), AudioEngine::instance()->samples_per_cycle());
 }
 
-void
-RouteUI::save_as_template ()
+bool
+RouteUI::process_save_template_prompter (ArdourPrompter& prompter, const std::string& dir)
 {
        std::string path;
        std::string safe_name;
-       string name;
-
-       path = ARDOUR::user_route_template_directory ();
-
-       if (g_mkdir_with_parents (path.c_str(), 0755)) {
-               error << string_compose (_("Cannot create route template directory %1"), path) << endmsg;
-               return;
-       }
-
-       Prompter p (true); // modal
+       std::string name;
 
-       p.set_title (_("Save As Template"));
-       p.set_prompt (_("Template name:"));
-       p.add_button (Gtk::Stock::SAVE, Gtk::RESPONSE_ACCEPT);
-       switch (p.run()) {
-       case RESPONSE_ACCEPT:
-               break;
-       default:
-               return;
-       }
-
-       p.get_result (name, true);
+       prompter.get_result (name, true);
 
        safe_name = legalize_for_path (name);
        safe_name += template_suffix;
 
-       path = Glib::build_filename (path, safe_name);
+       path = Glib::build_filename (dir, safe_name);
+
        if (Glib::file_test (path, Glib::FILE_TEST_EXISTS)) {
-               bool overwrite = overwrite_file_dialog (_("Confirm Template Overwrite"),
+               bool overwrite = overwrite_file_dialog (prompter,
+                                                       _("Confirm Template Overwrite"),
                                                        _("A template already exists with that name. Do you want to overwrite it?"));
 
                if (!overwrite) {
-                       return;
+                       return false;
                }
        }
 
        _route->save_as_template (path, name);
+
+       return true;
+}
+
+void
+RouteUI::save_as_template ()
+{
+       std::string dir;
+
+       dir = ARDOUR::user_route_template_directory ();
+
+       if (g_mkdir_with_parents (dir.c_str(), 0755)) {
+               error << string_compose (_("Cannot create route template directory %1"), dir) << endmsg;
+               return;
+       }
+
+       ArdourPrompter prompter (true); // modal
+
+       prompter.set_title (_("Save As Template"));
+       prompter.set_prompt (_("Template name:"));
+       prompter.add_button (Gtk::Stock::SAVE, Gtk::RESPONSE_ACCEPT);
+
+       bool finished = false;
+       while (!finished) {
+               switch (prompter.run()) {
+               case RESPONSE_ACCEPT:
+                       finished = process_save_template_prompter (prompter, dir);
+                       break;
+               default:
+                       finished = true;
+                       break;
+               }
+       }
 }
 
 void
index 7bc434f37ff3206caab936c218e8ee162abfa2d5..8ef85af0b94d547d04341e3b1b258768f12f0b20 100644 (file)
@@ -219,6 +219,7 @@ class RouteUI : public virtual AxisView
        virtual void map_frozen ();
 
        void adjust_latency ();
+       bool process_save_template_prompter (ArdourPrompter& prompter, const std::string& dir);
        void save_as_template ();
        void open_remote_control_id_dialog ();
 
index ad4b46dbda641cd393f96a0e87b30bd9d47b310c..9c33cdb206d8852d4f62483e28d2ffd00927aff9 100644 (file)
@@ -404,7 +404,7 @@ TranscodeVideoDialog::launch_transcode ()
                return;
        }
        std::string outfn = path_entry.get_text();
-       if (!confirm_video_outfn(outfn, video_get_docroot(Config))) return;
+       if (!confirm_video_outfn(*this, outfn, video_get_docroot(Config))) return;
        progress_label.set_text (_("Transcoding Video.."));
        dialog_progress_mode();
 #if 1 /* tentative debug mode */
index cf3ca7d7dde3d8f34f31f2bbba433ab9496c57db..997079a2498a3ed3efb6563be94f2161546eb4e9 100644 (file)
@@ -929,9 +929,9 @@ ARDOUR_UI_UTILS::windows_overlap (Gtk::Window *a, Gtk::Window *b)
 }
 
 bool
-ARDOUR_UI_UTILS::overwrite_file_dialog (string title, string text)
+ARDOUR_UI_UTILS::overwrite_file_dialog (Gtk::Window& parent, string title, string text)
 {
-       ArdourDialog dialog (title, true);
+       ArdourDialog dialog (parent, title, true);
        Label label (text);
 
        dialog.get_vbox()->pack_start (label, true, true);
index ebf966eba9c568415175288f170ddb9cb32c2881..c6df93839488ee4c8569f5308ee0fa477fd961ff 100644 (file)
@@ -92,7 +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);
+bool overwrite_file_dialog (Gtk::Window& parent, std::string title, std::string text);
 
 } // namespace
 #endif /* __ardour_gtk_utils_h__ */
index 0c94f378f02bfa9ac3376cfc2d3507a252af1de7..b62ac9433c93813e30dfcc2831090ee93ba02191 100644 (file)
@@ -46,7 +46,7 @@ using namespace ARDOUR;
 using namespace VideoUtils;
 
 bool
-VideoUtils::confirm_video_outfn (std::string outfn, std::string docroot)
+VideoUtils::confirm_video_outfn (Gtk::Window& parent, std::string outfn, std::string docroot)
 {
        /* replace docroot's '/' to G_DIR_SEPARATOR for the comparison */
        size_t look_here = 0;
@@ -68,7 +68,8 @@ VideoUtils::confirm_video_outfn (std::string outfn, std::string docroot)
        }
 
        if (Glib::file_test(outfn, Glib::FILE_TEST_EXISTS)) {
-               bool overwrite = ARDOUR_UI_UTILS::overwrite_file_dialog (_("Confirm Overwrite"),
+               bool overwrite = ARDOUR_UI_UTILS::overwrite_file_dialog (parent,
+                                                                        _("Confirm Overwrite"),
                                                                         _("A file with the same name already exists. Do you want to overwrite it?"));
 
                if (!overwrite) {
index 7f6f6052af0ec9500eb89cea93c5f57bd7adba42..a7d0908a34a32b50017950aec643b1583741353a 100644 (file)
@@ -34,7 +34,7 @@
 
 namespace VideoUtils {
 
-bool confirm_video_outfn (std::string, std::string docroot="");
+bool confirm_video_outfn (Gtk::Window& parent, std::string, std::string docroot="");
 std::string video_dest_dir (const std::string, const std::string);
 std::string video_dest_file (const std::string, const std::string);
 std::string strip_file_extension (const std::string infile);