diff options
author | Johannes Mueller <github@johannes-mueller.org> | 2017-08-19 13:49:33 +0200 |
---|---|---|
committer | Robin Gareus <robin@gareus.org> | 2017-08-20 21:09:30 +0200 |
commit | 245154d06aa79c7cb75d52a366a2ad3fa9c3a578 (patch) | |
tree | 58c811c962790710c07066d5ce7659f16c7e077d | |
parent | ae51d5fd4ebb90f782334ac0b4addc0c88e1629c (diff) |
Let user add a route template description on saving route templates
-rw-r--r-- | gtk2_ardour/ardour_ui.cc | 3 | ||||
-rw-r--r-- | gtk2_ardour/route_ui.cc | 59 | ||||
-rw-r--r-- | gtk2_ardour/route_ui.h | 3 | ||||
-rw-r--r-- | gtk2_ardour/save_template_dialog.cc | 4 | ||||
-rw-r--r-- | gtk2_ardour/save_template_dialog.h | 8 | ||||
-rw-r--r-- | libs/ardour/ardour/route.h | 2 | ||||
-rw-r--r-- | libs/ardour/route.cc | 10 |
7 files changed, 40 insertions, 49 deletions
diff --git a/gtk2_ardour/ardour_ui.cc b/gtk2_ardour/ardour_ui.cc index 873d114cf2..1a38773f2e 100644 --- a/gtk2_ardour/ardour_ui.cc +++ b/gtk2_ardour/ardour_ui.cc @@ -3192,9 +3192,10 @@ ARDOUR_UI::save_template () return; } - SaveTemplateDialog* d = new SaveTemplateDialog (*_session); + SaveTemplateDialog* d = new SaveTemplateDialog (_session->name()); d->signal_response().connect (sigc::bind (sigc::mem_fun (*this, &ARDOUR_UI::save_template_dialog_response), d)); + d->show (); } diff --git a/gtk2_ardour/route_ui.cc b/gtk2_ardour/route_ui.cc index eb1d4b58cf..f059a0adf0 100644 --- a/gtk2_ardour/route_ui.cc +++ b/gtk2_ardour/route_ui.cc @@ -70,6 +70,7 @@ #include "rgb_macros.h" #include "route_time_axis.h" #include "route_ui.h" +#include "save_template_dialog.h" #include "timers.h" #include "ui_config.h" #include "utils.h" @@ -1892,33 +1893,29 @@ RouteUI::adjust_latency () LatencyDialog dialog (_route->name() + _(" latency"), *(_route->output()), _session->frame_rate(), AudioEngine::instance()->samples_per_cycle()); } -bool -RouteUI::process_save_template_prompter (Prompter& prompter, const std::string& dir) -{ - std::string path; - std::string safe_name; - std::string name; - - prompter.get_result (name, true); - safe_name = legalize_for_path (name); - safe_name += template_suffix; - - path = Glib::build_filename (dir, safe_name); +void +RouteUI::save_as_template_dialog_response (int response, SaveTemplateDialog* d) +{ + if (response == RESPONSE_ACCEPT) { + const string name = d->get_template_name (); + const string desc = d->get_description (); + const string path = Glib::build_filename(ARDOUR::user_route_template_directory (), name); - if (Glib::file_test (path, Glib::FILE_TEST_EXISTS)) { - bool overwrite = overwrite_file_dialog (prompter, - _("Confirm Template Overwrite"), - _("A template already exists with that name. Do you want to overwrite it?")); + if (Glib::file_test (path, Glib::FILE_TEST_EXISTS)) { /* file already exists. */ + bool overwrite = overwrite_file_dialog (*d, + _("Confirm Template Overwrite"), + _("A template already exists with that name. Do you want to overwrite it?")); - if (!overwrite) { - return false; + if (!overwrite) { + d->show (); + return; + } } + _route->save_as_template (path, name, desc); } - _route->save_as_template (path, name); - - return true; + delete d; } void @@ -1933,23 +1930,10 @@ RouteUI::save_as_template () return; } - Prompter prompter (true); // modal - - prompter.set_title (_("Save As Template")); - prompter.set_prompt (_("Template name:")); - prompter.add_button (Gtk::Stock::SAVE, Gtk::RESPONSE_ACCEPT); + SaveTemplateDialog* d = new SaveTemplateDialog (_route->name()); - bool finished = false; - while (!finished) { - switch (prompter.run()) { - case RESPONSE_ACCEPT: - finished = process_save_template_prompter (prompter, dir); - break; - default: - finished = true; - break; - } - } + d->signal_response().connect (sigc::bind (sigc::mem_fun (*this, &RouteUI::save_as_template_dialog_response), d)); + d->show (); } void @@ -2415,4 +2399,3 @@ RouteUI::stripable () const { return _route; } - diff --git a/gtk2_ardour/route_ui.h b/gtk2_ardour/route_ui.h index 011498124e..4550abd4c2 100644 --- a/gtk2_ardour/route_ui.h +++ b/gtk2_ardour/route_ui.h @@ -63,6 +63,7 @@ namespace ArdourWidgets { class ArdourWindow; class IOSelectorWindow; class ControlSlaveUI; +class SaveTemplateDialog; class RoutePinWindowProxy : public WM::ProxyBase { @@ -243,7 +244,7 @@ public: virtual void map_frozen (); void adjust_latency (); - bool process_save_template_prompter (ArdourWidgets::Prompter& prompter, const std::string& dir); + void save_as_template_dialog_response (int response, SaveTemplateDialog* d); void save_as_template (); static Gtkmm2ext::ActiveState solo_active_state (boost::shared_ptr<ARDOUR::Stripable>); diff --git a/gtk2_ardour/save_template_dialog.cc b/gtk2_ardour/save_template_dialog.cc index ed803bf405..721c9c18ee 100644 --- a/gtk2_ardour/save_template_dialog.cc +++ b/gtk2_ardour/save_template_dialog.cc @@ -31,10 +31,10 @@ using namespace Gtk; using namespace ARDOUR; -SaveTemplateDialog::SaveTemplateDialog (const Session& s) +SaveTemplateDialog::SaveTemplateDialog (const std::string& name, const std::string& desc) : ArdourDialog (_("Save as template")) { - _name_editor.get_buffer()->set_text (s.name() + _("-template")); + _name_editor.get_buffer()->set_text (name + _("-template")); _description_editor.set_wrap_mode (Gtk::WRAP_WORD); _description_editor.set_size_request(400, 300); diff --git a/gtk2_ardour/save_template_dialog.h b/gtk2_ardour/save_template_dialog.h index 6b98d5cfba..c2cb8f8a7b 100644 --- a/gtk2_ardour/save_template_dialog.h +++ b/gtk2_ardour/save_template_dialog.h @@ -21,20 +21,18 @@ #ifndef __ardour_gtk_save_template_dialog_h__ #define __ardour_gtk_save_template_dialog_h__ +#include <string> + #include <gtkmm/entry.h> #include <gtkmm/textview.h> #include "ardour_dialog.h" -namespace ARDOUR -{ -class Session; -} class SaveTemplateDialog : public ArdourDialog { public: - SaveTemplateDialog (const ARDOUR::Session& s); + SaveTemplateDialog (const std::string& name, const std::string& description = ""); std::string get_template_name () const; std::string get_description () const; diff --git a/libs/ardour/ardour/route.h b/libs/ardour/ardour/route.h index f4f15ff4a9..e66e0784fe 100644 --- a/libs/ardour/ardour/route.h +++ b/libs/ardour/ardour/route.h @@ -381,7 +381,7 @@ public: boost::weak_ptr<Route> weakroute (); - int save_as_template (const std::string& path, const std::string& name); + int save_as_template (const std::string& path, const std::string& name, const std::string& description ); PBD::Signal1<void,void*> SelectedChanged; diff --git a/libs/ardour/route.cc b/libs/ardour/route.cc index d3412f0387..5cd9b576a5 100644 --- a/libs/ardour/route.cc +++ b/libs/ardour/route.cc @@ -4014,7 +4014,7 @@ Route::set_plugin_state_dir (boost::weak_ptr<Processor> p, const std::string& d) } int -Route::save_as_template (const string& path, const string& name) +Route::save_as_template (const string& path, const string& name, const string& description) { std::string state_dir = path.substr (0, path.find_last_of ('.')); // strip template_suffix PBD::Unwinder<std::string> uw (_session._template_state_dir, state_dir); @@ -4022,6 +4022,14 @@ Route::save_as_template (const string& path, const string& name) XMLNode& node (state (false)); node.set_property (X_("name"), name); + if (!description.empty()) { + XMLNode* desc = new XMLNode(X_("description")); + XMLNode* desc_cont = new XMLNode(X_("content"), description); + desc->add_child_nocopy (*desc_cont); + + node.add_child_nocopy (*desc); + } + XMLTree tree; IO::set_name_in_state (*node.children().front(), name); |