From e8a832f03f300ff532f108f24663a4bded7e7e0d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Nusser?= Date: Sun, 1 Nov 2015 21:56:09 +0100 Subject: [PATCH 1/4] no-op; reordering of class forward declarations in editor.h. --- gtk2_ardour/editor.h | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/gtk2_ardour/editor.h b/gtk2_ardour/editor.h index be018d6b9b..c38e355c05 100644 --- a/gtk2_ardour/editor.h +++ b/gtk2_ardour/editor.h @@ -67,20 +67,20 @@ namespace Gtkmm2ext { } namespace ARDOUR { - class RouteGroup; - class Playlist; class AudioPlaylist; class AudioRegion; - class Region; - class Location; - class TempoSection; - class Session; - class Filter; - class ChanCount; - class MidiOperator; - class Track; - class MidiTrack; class AudioTrack; + class ChanCount; + class Filter; + class Location; + class MidiOperator; + class MidiTrack; + class Playlist; + class Region; + class RouteGroup; + class Session; + class TempoSection; + class Track; } namespace LADSPA { From 6ccffbaf0937c7814f3c49510859d13bc033df99 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Nusser?= Date: Sun, 1 Nov 2015 21:00:05 +0100 Subject: [PATCH 2/4] Improve behavior of overwrite_file_dialog. - Make overwrite file dialogs transient. - Cancelling the overwrite dialog doesn't close initial dialog. --- gtk2_ardour/ardour_ui.cc | 139 ++++++++++++++++---------- gtk2_ardour/ardour_ui.h | 3 + gtk2_ardour/editor.h | 4 + gtk2_ardour/editor_export_audio.cc | 58 ++++++----- gtk2_ardour/export_video_dialog.cc | 2 +- gtk2_ardour/route_ui.cc | 68 ++++++++----- gtk2_ardour/route_ui.h | 1 + gtk2_ardour/transcode_video_dialog.cc | 2 +- gtk2_ardour/utils.cc | 4 +- gtk2_ardour/utils.h | 2 +- gtk2_ardour/utils_videotl.cc | 5 +- gtk2_ardour/utils_videotl.h | 2 +- 12 files changed, 180 insertions(+), 110 deletions(-) diff --git a/gtk2_ardour/ardour_ui.cc b/gtk2_ardour/ardour_ui.cc index 15106d79ef..e9d9938e34 100644 --- a/gtk2_ardour/ardour_ui.cc +++ b/gtk2_ardour/ardour_ui.cc @@ -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 p; + get_state_files_in_directory (_session->session_directory().root_path(), p); + vector 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; - } + bool finished = false; + while (!finished) { + switch (prompter.run()) { + case RESPONSE_ACCEPT: + { + finished = process_snapshot_session_prompter (prompter, switch_to_it); + break; } - vector p; - get_state_files_in_directory (_session->session_directory().root_path(), p); - vector 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?")); + default: + finished = true; + break; } - - if (do_save) { - save_state (snapname, switch_to_it); - } - 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); + bool finished = false; + while (!finished) { + switch (prompter.run()) { + case RESPONSE_ACCEPT: + finished = process_save_template_prompter (prompter); + break; - 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?")); - - if (overwrite) { - _session->save_template (name, true); - } - } + default: + finished = true; + break; } - break; - - default: - break; } } diff --git a/gtk2_ardour/ardour_ui.h b/gtk2_ardour/ardour_ui.h index 1c00d9893f..b43b2d62a2 100644 --- a/gtk2_ardour/ardour_ui.h +++ b/gtk2_ardour/ardour_ui.h @@ -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; diff --git a/gtk2_ardour/editor.h b/gtk2_ardour/editor.h index c38e355c05..77156cbb4c 100644 --- a/gtk2_ardour/editor.h +++ b/gtk2_ardour/editor.h @@ -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 midi_region); + void add_transport_frame (Gtk::Container&); void add_toplevel_menu (Gtk::Container&); Gtk::HBox& get_status_bar_packer() { return status_bar_hpacker; } diff --git a/gtk2_ardour/editor_export_audio.cc b/gtk2_ardour/editor_export_audio.cc index c886885dd2..2bd607f108 100644 --- a/gtk2_ardour/editor_export_audio.cc +++ b/gtk2_ardour/editor_export_audio.cc @@ -104,6 +104,32 @@ Editor::export_range () } } +bool +Editor::process_midi_export_dialog (MidiExportDialog& dialog, boost::shared_ptr 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); } } diff --git a/gtk2_ardour/export_video_dialog.cc b/gtk2_ardour/export_video_dialog.cc index a21a9037e2..98f5306ad0 100644 --- a/gtk2_ardour/export_video_dialog.cc +++ b/gtk2_ardour/export_video_dialog.cc @@ -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(); diff --git a/gtk2_ardour/route_ui.cc b/gtk2_ardour/route_ui.cc index 2f45756c27..8cb91020c3 100644 --- a/gtk2_ardour/route_ui.cc +++ b/gtk2_ardour/route_ui.cc @@ -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; + std::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 - - 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 diff --git a/gtk2_ardour/route_ui.h b/gtk2_ardour/route_ui.h index 7bc434f37f..8ef85af0b9 100644 --- a/gtk2_ardour/route_ui.h +++ b/gtk2_ardour/route_ui.h @@ -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 (); diff --git a/gtk2_ardour/transcode_video_dialog.cc b/gtk2_ardour/transcode_video_dialog.cc index ad4b46dbda..9c33cdb206 100644 --- a/gtk2_ardour/transcode_video_dialog.cc +++ b/gtk2_ardour/transcode_video_dialog.cc @@ -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 */ diff --git a/gtk2_ardour/utils.cc b/gtk2_ardour/utils.cc index cf3ca7d7dd..997079a249 100644 --- a/gtk2_ardour/utils.cc +++ b/gtk2_ardour/utils.cc @@ -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); diff --git a/gtk2_ardour/utils.h b/gtk2_ardour/utils.h index ebf966eba9..c6df938394 100644 --- a/gtk2_ardour/utils.h +++ b/gtk2_ardour/utils.h @@ -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__ */ diff --git a/gtk2_ardour/utils_videotl.cc b/gtk2_ardour/utils_videotl.cc index 0c94f378f0..b62ac9433c 100644 --- a/gtk2_ardour/utils_videotl.cc +++ b/gtk2_ardour/utils_videotl.cc @@ -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) { diff --git a/gtk2_ardour/utils_videotl.h b/gtk2_ardour/utils_videotl.h index 7f6f6052af..a7d0908a34 100644 --- a/gtk2_ardour/utils_videotl.h +++ b/gtk2_ardour/utils_videotl.h @@ -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); From be442690ba8c9a33b78d3ed5fbe916f8924da6dc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Nusser?= Date: Sun, 1 Nov 2015 22:23:01 +0100 Subject: [PATCH 3/4] Fix ordering of buttons in midi export dialog. [Cancel] [Save] instead of [Save] [Cancel]. --- gtk2_ardour/midi_export_dialog.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gtk2_ardour/midi_export_dialog.cc b/gtk2_ardour/midi_export_dialog.cc index 34469adc39..3e91ca4f9f 100644 --- a/gtk2_ardour/midi_export_dialog.cc +++ b/gtk2_ardour/midi_export_dialog.cc @@ -37,8 +37,8 @@ MidiExportDialog::MidiExportDialog (PublicEditor&, boost::shared_ptr { set_border_width (12); - add_button (Gtk::Stock::SAVE, Gtk::RESPONSE_ACCEPT); add_button (Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL); + add_button (Gtk::Stock::SAVE, Gtk::RESPONSE_ACCEPT); get_vbox()->set_border_width (12); get_vbox()->pack_start (file_chooser); From 4898614f9029672c23ef0785568e60d95106ca38 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Nusser?= Date: Sun, 1 Nov 2015 22:24:02 +0100 Subject: [PATCH 4/4] Remove explicit positioning of overwrite_file_dialog. ArdourDialog takes care of this. --- gtk2_ardour/utils.cc | 1 - 1 file changed, 1 deletion(-) diff --git a/gtk2_ardour/utils.cc b/gtk2_ardour/utils.cc index 997079a249..60498b9fac 100644 --- a/gtk2_ardour/utils.cc +++ b/gtk2_ardour/utils.cc @@ -937,7 +937,6 @@ ARDOUR_UI_UTILS::overwrite_file_dialog (Gtk::Window& parent, string title, strin 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()) {