Let the user add a template description on saving session templates
authorJohannes Mueller <github@johannes-mueller.org>
Fri, 18 Aug 2017 17:53:46 +0000 (19:53 +0200)
committerRobin Gareus <robin@gareus.org>
Sun, 20 Aug 2017 19:09:30 +0000 (21:09 +0200)
gtk2_ardour/ardour_ui.cc
gtk2_ardour/ardour_ui.h
gtk2_ardour/save_template_dialog.cc [new file with mode: 0644]
gtk2_ardour/save_template_dialog.h [new file with mode: 0644]
gtk2_ardour/wscript
libs/ardour/ardour/session.h
libs/ardour/session_state.cc

index 8d931bbbd39c3dc21b36bfbdc741f323bef73efc..873d114cf24f1889911bd5d816f08ae3e977d6bc 100644 (file)
@@ -169,6 +169,7 @@ typedef uint64_t microseconds_t;
 #include "route_time_axis.h"
 #include "route_params_ui.h"
 #include "save_as_dialog.h"
+#include "save_template_dialog.h"
 #include "script_selector.h"
 #include "session_archive_dialog.h"
 #include "session_dialog.h"
@@ -3158,60 +3159,43 @@ ARDOUR_UI::transport_rec_enable_blink (bool onoff)
        }
 }
 
-bool
-ARDOUR_UI::process_save_template_prompter (Prompter& prompter)
+void
+ARDOUR_UI::save_template_dialog_response (int response, SaveTemplateDialog* d)
 {
-       string name;
+       if (response == RESPONSE_ACCEPT) {
+               const string name = d->get_template_name ();
+               const string desc = d->get_description ();
 
-       prompter.get_result (name);
-
-       if (name.length()) {
-               int failed = _session->save_template (name);
+               int failed = _session->save_template (name, desc);
 
                if (failed == -2) { /* file already exists. */
-                       bool overwrite = overwrite_file_dialog (prompter,
+                       bool overwrite = overwrite_file_dialog (*d,
                                                                _("Confirm Template Overwrite"),
                                                                _("A template already exists with that name. Do you want to overwrite it?"));
 
                        if (overwrite) {
-                               _session->save_template (name, true);
+                               _session->save_template (name, desc, true);
                        }
                        else {
-                               return false;
+                               d->show ();
+                               return;
                        }
                }
        }
-
-       return true;
+       delete d;
 }
 
 void
 ARDOUR_UI::save_template ()
 {
-       Prompter prompter (true);
-
        if (!check_audioengine (_main_window)) {
                return;
        }
 
-       prompter.set_name (X_("Prompter"));
-       prompter.set_title (_("Save Template"));
-       prompter.set_prompt (_("Name for template:"));
-       prompter.set_initial_text(_session->name() + _("-template"));
-       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);
-                       break;
+       SaveTemplateDialog* d = new SaveTemplateDialog (*_session);
 
-               default:
-                       finished = true;
-                       break;
-               }
-       }
+       d->signal_response().connect (sigc::bind (sigc::mem_fun (*this, &ARDOUR_UI::save_template_dialog_response), d));
+       d->show ();
 }
 
 void ARDOUR_UI::manage_templates ()
index aed1be2e6b270b107a53e45babcc0304d34a6af3..fbe1486736008289c3ded60fb763f32d274a93a6 100644 (file)
@@ -127,6 +127,7 @@ class MainClock;
 class Mixer_UI;
 class PublicEditor;
 class SaveAsDialog;
+class SaveTemplateDialog;
 class SessionDialog;
 class SessionOptionEditorWindow;
 class Splash;
@@ -621,7 +622,7 @@ private:
 
        void open_session ();
        void open_recent_session ();
-       bool process_save_template_prompter (ArdourWidgets::Prompter& prompter);
+       void save_template_dialog_response (int response, SaveTemplateDialog* d);
        void save_template ();
        void manage_templates ();
 
diff --git a/gtk2_ardour/save_template_dialog.cc b/gtk2_ardour/save_template_dialog.cc
new file mode 100644 (file)
index 0000000..ed803bf
--- /dev/null
@@ -0,0 +1,71 @@
+/*
+    Copyright (C) 2017 Paul Davis
+    Author: Johannes Mueller
+
+    This program is free software; you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation; either version 2 of the License, or
+    (at your option) any later version.
+
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with this program; if not, write to the Free Software
+    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+
+*/
+
+#include <gtkmm/box.h>
+#include <gtkmm/frame.h>
+#include <gtkmm/label.h>
+#include <gtkmm/stock.h>
+
+#include "pbd/i18n.h"
+#include "ardour/session.h"
+
+#include "save_template_dialog.h"
+
+using namespace Gtk;
+using namespace ARDOUR;
+
+SaveTemplateDialog::SaveTemplateDialog (const Session& s)
+       : ArdourDialog (_("Save as template"))
+{
+       _name_editor.get_buffer()->set_text (s.name() + _("-template"));
+       _description_editor.set_wrap_mode (Gtk::WRAP_WORD);
+       _description_editor.set_size_request(400, 300);
+
+       HBox* hb = manage (new HBox);
+       hb->set_spacing (8);
+       Label* lb = manage (new Label(_("Template name:")));
+       hb->pack_start (*lb, false, true);
+       hb->pack_start (_name_editor, true, true);
+
+       Frame* fd = manage (new Frame(_("Description:")));
+       fd->add (_description_editor);
+
+       get_vbox()->set_spacing (8);
+       get_vbox()->pack_start (*fd);
+       get_vbox()->pack_start (*hb);
+
+       add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
+       add_button(Gtk::Stock::SAVE, Gtk::RESPONSE_ACCEPT);
+
+       show_all_children ();
+}
+
+
+std::string
+SaveTemplateDialog::get_template_name () const
+{
+       return _name_editor.get_buffer()->get_text();
+}
+
+std::string
+SaveTemplateDialog::get_description () const
+{
+       return _description_editor.get_buffer()->get_text();
+}
diff --git a/gtk2_ardour/save_template_dialog.h b/gtk2_ardour/save_template_dialog.h
new file mode 100644 (file)
index 0000000..6b98d5c
--- /dev/null
@@ -0,0 +1,47 @@
+/*
+    Copyright (C) 2017 Paul Davis
+    Author: Johannes Mueller
+
+    This program is free software; you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation; either version 2 of the License, or
+    (at your option) any later version.
+
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with this program; if not, write to the Free Software
+    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+
+*/
+
+#ifndef __ardour_gtk_save_template_dialog_h__
+#define __ardour_gtk_save_template_dialog_h__
+
+#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);
+
+       std::string get_template_name () const;
+       std::string get_description () const;
+
+private:
+       Gtk::Entry _name_editor;
+       Gtk::TextView _description_editor;
+};
+
+#endif /* __ardour_gtk_save_template_dialog_h__ */
index b0106c683d1bd9cb21a9389c55dc68509680b72b..598674079ae865704c7fa86793b99df66c6c6b6a 100644 (file)
@@ -218,6 +218,7 @@ gtk2_ardour_sources = [
         'route_ui.cc',
         'ruler_dialog.cc',
         'save_as_dialog.cc',
+        'save_template_dialog.cc',
         'search_path_option.cc',
         'script_selector.cc',
         'selection.cc',
index 6fe760c2b842891159ee7b7520486d982541eac7..0581d706ff0057d4075108e013d86a076c3b92f5 100644 (file)
@@ -259,7 +259,7 @@ class LIBARDOUR_API Session : public PBD::StatefulDestructible, public PBD::Scop
         */
        RouteList new_route_from_template (uint32_t how_many, PresentationInfo::order_t insert_at, const std::string& template_path, const std::string& name, PlaylistDisposition pd = NewPlaylist);
        RouteList new_route_from_template (uint32_t how_many, PresentationInfo::order_t insert_at, XMLNode&, const std::string& name, PlaylistDisposition pd = NewPlaylist);
-       std::vector<std::string> get_paths_for_new_sources (bool allow_replacing, const std::string& import_file_path, 
+       std::vector<std::string> get_paths_for_new_sources (bool allow_replacing, const std::string& import_file_path,
                                                            uint32_t channels, std::vector<std::string> const & smf_track_names);
 
        int bring_all_sources_into_session (boost::function<void(uint32_t,uint32_t,std::string)> callback);
@@ -531,7 +531,7 @@ class LIBARDOUR_API Session : public PBD::StatefulDestructible, public PBD::Scop
        int archive_session (const std::string&, const std::string&, ArchiveEncode compress_audio = FLAC_16BIT, bool only_used_sources = false, Progress* p = 0);
 
        int restore_state (std::string snapshot_name);
-       int save_template (std::string template_name, bool replace_existing = false);
+       int save_template (const std::string& template_name, const std::string& description = "", 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);
index 0a1eb2ace689bce14d487b60b48bf7d5f8081f70..0bf09f76c696e7a0c48c3f55b20a91a591aadd69 100644 (file)
@@ -2356,7 +2356,7 @@ Session::XMLSourceFactory (const XMLNode& node)
 }
 
 int
-Session::save_template (string template_name, bool replace_existing)
+Session::save_template (const string& template_name, const string& description, bool replace_existing)
 {
        if ((_state_of_the_state & CannotSave) || template_name.empty ()) {
                return -1;
@@ -2411,12 +2411,22 @@ Session::save_template (string template_name, bool replace_existing)
        SessionSaveUnderway (); /* EMIT SIGNAL */
 
        XMLTree tree;
-
+       XMLNode* root;
        {
                PBD::Unwinder<std::string> uw (_template_state_dir, template_dir_path);
-               tree.set_root (&get_template());
+               root = &get_template();
+       }
+
+       if (!description.empty()) {
+               XMLNode* desc = new XMLNode(X_("description"));
+               XMLNode* desc_cont = new XMLNode(X_("content"), description);
+               desc->add_child_nocopy (*desc_cont);
+
+               root->add_child_nocopy (*desc);
        }
 
+       tree.set_root (root);
+
        if (!tree.write (template_file_path)) {
                error << _("template not saved") << endmsg;
                return -1;