fix ordering of track view list & route list resync in editor, to avoid clearing...
[ardour.git] / gtk2_ardour / route_ui.cc
index cc4f5413855324142185e4b894daaf986e87244e..6cbb5290d47ca98e02e479c17579aa69644b00e3 100644 (file)
@@ -23,6 +23,7 @@
 #include <gtkmm2ext/doi.h>
 #include <gtkmm2ext/bindable_button.h>
 #include <gtkmm2ext/gtk_ui.h>
+#include <gtkmm2ext/prompter.h>
 
 #include <ardour/route_group.h>
 #include <pbd/memento_command.h>
@@ -41,6 +42,7 @@
 #include <ardour/audio_track.h>
 #include <ardour/audio_diskstream.h>
 #include <ardour/profile.h>
+#include <ardour/utils.h>
 
 #include "i18n.h"
 using namespace sigc;
@@ -68,6 +70,7 @@ RouteUI::RouteUI (boost::shared_ptr<ARDOUR::Route> rt,
 void
 RouteUI::init ()
 {
+       self_destruct = true;
        xml_node = 0;
        mute_menu = 0;
        solo_menu = 0;
@@ -147,7 +150,9 @@ RouteUI::set_route (boost::shared_ptr<Route> rp)
           up when the route is destroyed.
        */
 
-       new PairedShiva<Route,RouteUI> (*_route, *this);
+       if (self_destruct) {
+               new PairedShiva<Route,RouteUI> (*_route, *this);
+       }
 
        mute_button->set_controllable (&_route->mute_control());
        mute_button->set_label (m_name);
@@ -187,7 +192,9 @@ RouteUI::set_route (boost::shared_ptr<Route> rp)
 
 RouteUI::~RouteUI()
 {
-       GoingAway (); /* EMIT SIGNAL */
+       /* derived classes should emit GoingAway so that they receive the signal
+          when the object is still a legal derived instance.
+        */
 
        if (solo_menu) {
                delete solo_menu;
@@ -1170,3 +1177,38 @@ RouteUI::map_frozen ()
        }
 }
 
+void
+RouteUI::save_as_template ()
+{
+       Glib::ustring path;
+       Glib::ustring safe_name;
+       std::string name;
+       
+       path = Session::route_template_dir();
+       
+       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_prompt (_("Template name:"));
+       switch (p.run()) {
+       case RESPONSE_ACCEPT:
+               break;
+       default:
+               return;
+       }
+       
+       p.hide ();
+       p.get_result (name, true);
+       
+       safe_name = legalize_for_path (name);
+       safe_name += Session::template_suffix ();
+       
+       path = Glib::build_filename (path, safe_name);
+       
+       _route->save_as_template (path, name);
+}
+