a-fluidsynth: implement LV2_BANKPATCH__notify
[ardour.git] / gtk2_ardour / template_dialog.cc
index 696cb29decbb8e45ff3339e06d4eb214a03c71fc..a5bbcd4089cd20397b135eed2dcba22f2c680a2c 100644 (file)
@@ -63,7 +63,7 @@ class TemplateManager : public Gtk::HBox,
 public:
        virtual ~TemplateManager () {}
 
-       void init ();
+       virtual void init () = 0;
        void handle_dirty_description ();
 
        PBD::Signal0<void> TemplatesImported;
@@ -71,6 +71,9 @@ public:
 protected:
        TemplateManager ();
 
+       Gtk::TextView _description_editor;
+       Gtk::Button _save_desc;
+
        void setup_model (const std::vector<ARDOUR::TemplateInfo>& templates);
 
        void row_selection_changed ();
@@ -125,8 +128,6 @@ private:
        Gtk::CellRendererText _validating_cellrenderer;
        Gtk::TreeView::Column _validated_column;
 
-       Gtk::TextView _description_editor;
-       Gtk::Button _save_desc;
        bool _desc_dirty;
 
        Gtk::Button _remove_button;
@@ -146,6 +147,8 @@ public:
        SessionTemplateManager () : TemplateManager () {}
        ~SessionTemplateManager () {}
 
+       void init ();
+
        void get_templates (vector<TemplateInfo>& templates) const;
 
 private:
@@ -165,6 +168,8 @@ public:
        RouteTemplateManager () : TemplateManager () {}
        ~RouteTemplateManager () {}
 
+       void init ();
+
        void get_templates (vector<TemplateInfo>& templates) const;
 
 private:
@@ -203,8 +208,8 @@ TemplateDialog::TemplateDialog ()
 
        signal_hide().connect (sigc::mem_fun (session_tm, &TemplateManager::handle_dirty_description));
        signal_hide().connect (sigc::mem_fun (route_tm, &TemplateManager::handle_dirty_description));
-       nb->signal_switch_page().connect (boost::bind (&TemplateManager::handle_dirty_description, session_tm));
-       nb->signal_switch_page().connect (boost::bind (&TemplateManager::handle_dirty_description, route_tm));
+       nb->signal_switch_page().connect (sigc::hide (sigc::hide (sigc::mem_fun (session_tm, &TemplateManager::handle_dirty_description))));
+       nb->signal_switch_page().connect (sigc::hide (sigc::hide (sigc::mem_fun (route_tm, &TemplateManager::handle_dirty_description))));
 }
 
 TemplateManager::TemplateManager ()
@@ -284,18 +289,6 @@ TemplateManager::TemplateManager ()
        _progress_bar.hide ();
 }
 
-void
-TemplateManager::init ()
-{
-       vector<TemplateInfo> templates;
-       get_templates (templates);
-       setup_model (templates);
-
-       _progress_bar.hide ();
-       _description_editor.set_sensitive (false);
-       _save_desc.set_sensitive (false);
-}
-
 void
 TemplateManager::setup_model (const vector<TemplateInfo>& templates)
 {
@@ -435,13 +428,14 @@ TemplateManager::save_template_desc ()
                return;
        }
 
-       tree.root()->remove_nodes (X_("description"));
-       XMLNode* desc = new XMLNode (X_("description"));
+       tree.root()->remove_nodes_and_delete (X_("description"));
 
-       XMLNode* dn = new XMLNode (X_("content"), desc_txt);
-       desc->add_child_nocopy (*dn);
-
-       tree.root()->add_child_nocopy (*desc);
+       if (!desc_txt.empty ()) {
+               XMLNode* desc = new XMLNode (X_("description"));
+               XMLNode* dn = new XMLNode (X_("content"), desc_txt);
+               desc->add_child_nocopy (*dn);
+               tree.root()->add_child_nocopy (*desc);
+       }
 
        if (!tree.write ()) {
                error << string_compose(X_("Could not write to template file \"%1\"."), file_path) << endmsg;
@@ -467,13 +461,14 @@ TemplateManager::key_event (GdkEventKey* ev)
        return false;
 }
 
-static
-bool accept_all_files (string const &, void *)
+static bool
+accept_all_files (string const &, void *)
 {
        return true;
 }
 
-static void _set_progress (Progress* p, size_t n, size_t t)
+static void
+_set_progress (Progress* p, size_t n, size_t t)
 {
        p->set_progress (float (n) / float(t));
 }
@@ -668,13 +663,38 @@ TemplateManager::update_progress_gui (float p)
        _progress_bar.set_fraction (p);
 }
 
+void
+SessionTemplateManager::init ()
+{
+       vector<TemplateInfo> templates;
+       get_templates (templates);
+       setup_model (templates);
+
+       _progress_bar.hide ();
+       _description_editor.set_sensitive (false);
+       _save_desc.set_sensitive (false);
+}
+
+void
+RouteTemplateManager::init ()
+{
+       vector<TemplateInfo> templates;
+       get_templates (templates);
+       setup_model (templates);
+
+       _progress_bar.hide ();
+       _description_editor.set_sensitive (false);
+       _save_desc.set_sensitive (false);
+}
+
 void
 SessionTemplateManager::get_templates (vector<TemplateInfo>& templates) const
 {
        find_session_templates (templates, /* read_xml = */ true);
 }
 
-void RouteTemplateManager::get_templates (vector<TemplateInfo>& templates) const
+void
+RouteTemplateManager::get_templates (vector<TemplateInfo>& templates) const
 {
        find_route_templates (templates);
 }