Change the template pulldown menu into a tree list. Populate the Description view...
authorBen Loftis <ben@harrisonconsoles.com>
Mon, 14 Aug 2017 21:14:42 +0000 (16:14 -0500)
committerBen Loftis <ben@harrisonconsoles.com>
Mon, 14 Aug 2017 21:14:42 +0000 (16:14 -0500)
gtk2_ardour/session_dialog.cc
gtk2_ardour/session_dialog.h
libs/ardour/ardour/template_utils.h
libs/ardour/template_utils.cc

index 08f7b15c165e7ebdd3274927ee9998f8b594a88a..8d8fa54e74ac6acdba27b310d083b74e6eaef155 100644 (file)
@@ -116,7 +116,6 @@ SessionDialog::SessionDialog (bool require_new, const std::string& session_name,
        }
 
        if (!template_name.empty()) {
-               use_template_button.set_active (false);
                load_template_override = template_name;
        }
 
@@ -126,14 +125,6 @@ SessionDialog::SessionDialog (bool require_new, const std::string& session_name,
 
        populate_session_templates ();
 
-       if (!template_model->children().empty()) {
-               use_template_button.show();
-               template_chooser.show ();
-       } else {
-               use_template_button.hide();
-               template_chooser.hide ();
-       }
-
        if (recent_session_model) {
                int cnt = redisplay_recent_sessions ();
                if (cnt > 0) {
@@ -218,7 +209,7 @@ SessionDialog::use_session_template ()
                return true;
        }
 
-       if (use_template_button.get_active()) {
+       if (template_chooser.get_selection()->count_selected_rows() > 0) {
                return true;
        }
 
@@ -233,11 +224,13 @@ SessionDialog::session_template_name ()
                return Glib::build_filename (the_path, load_template_override + ARDOUR::template_suffix);
        }
 
-       if (use_template_button.get_active()) {
-               TreeModel::iterator iter = template_chooser.get_active ();
-               TreeModel::Row row = (*iter);
-               string s = row[session_template_columns.path];
-               return s;
+       if (template_chooser.get_selection()->count_selected_rows() > 0) {
+               TreeIter iter = template_chooser.get_selection()->get_selected();
+
+               if (iter) {
+                       string s = (*iter)[session_template_columns.path];
+                       return s;
+               }
        }
 
        return string();
@@ -506,19 +499,14 @@ SessionDialog::populate_session_templates ()
 {
        vector<TemplateInfo> templates;
 
-       find_session_templates (templates);
+       find_session_templates (templates, true);
 
        template_model->clear ();
 
-       for (vector<TemplateInfo>::iterator x = templates.begin(); x != templates.end(); ++x) {
-               TreeModel::Row row;
-
-               row = *(template_model->append ());
-
-               row[session_template_columns.name] = (*x).name;
-               row[session_template_columns.path] = (*x).path;
-               row[session_template_columns.desc] = (*x).description;
-       }
+//  ToDo:  maybe add an explicit 'no template' item?
+//     TreeModel::Row row = *template_model->prepend ();
+//     row[session_template_columns.name] = (_("no template"));
+//     row[session_template_columns.path] = string();
 
        LuaScriptList& ms (LuaScripting::instance ().scripts (LuaScriptInfo::SessionSetup));
        for (LuaScriptList::const_iterator s = ms.begin(); s != ms.end(); ++s) {
@@ -526,13 +514,21 @@ SessionDialog::populate_session_templates ()
                row = *(template_model->append ());
                row[session_template_columns.name] = "Meta: " + (*s)->name;
                row[session_template_columns.path] = "urn:ardour:" + (*s)->path;
-               row[session_template_columns.desc] = "urn:ardour:" + (*s)->description;
+               row[session_template_columns.description] = (*s)->description;
+        row[session_template_columns.created_with] = _("{Factory Template}");
        }
 
-       if (!templates.empty()) {
-               /* select first row */
-               template_chooser.set_active (0);
+       for (vector<TemplateInfo>::iterator x = templates.begin(); x != templates.end(); ++x) {
+               TreeModel::Row row;
+
+               row = *(template_model->append ());
+
+               row[session_template_columns.name] = (*x).name;
+               row[session_template_columns.path] = (*x).path;
+        row[session_template_columns.description] = (*x).description;
+        row[session_template_columns.created_with] = (*x).created_with;
        }
+
 }
 
 void
@@ -606,7 +602,7 @@ SessionDialog::setup_new_session_page ()
 
        VBox *vbox2 = manage (new VBox);
        HBox* hbox3 = manage (new HBox);
-       template_model = ListStore::create (session_template_columns);
+       template_model = TreeStore::create (session_template_columns);
 
        vbox2->set_spacing (6);
 
@@ -614,32 +610,29 @@ SessionDialog::setup_new_session_page ()
 
        vbox3->set_spacing (6);
 
-       /* we may want to hide this and show it at various
-          times depending on the existence of templates.
-       */
-       template_chooser.set_no_show_all (true);
-       use_template_button.set_no_show_all (true);
-
        HBox* hbox4a = manage (new HBox);
-       use_template_button.set_label (_("Use this template"));
-       use_template_button.signal_toggled().connect(sigc::mem_fun (*this, &SessionDialog::template_checkbox_toggled));
-
-       TreeModel::Row row = *template_model->prepend ();
-       row[session_template_columns.name] = (_("no template"));
-       row[session_template_columns.path] = string();
 
        hbox4a->set_spacing (6);
-       hbox4a->pack_start (use_template_button, false, false);
-       hbox4a->pack_start (template_chooser, true, true);
+       hbox4a->pack_start (template_chooser, false, false);
+       hbox4a->pack_start (template_desc, true, true);
 
-       template_chooser.set_model (template_model);
+       template_desc.set_editable (false);
+       template_desc.set_wrap_mode (Gtk::WRAP_WORD);
+       template_desc.set_size_request(300,400);
+       template_desc.set_left_margin(6);
+       template_desc.set_right_margin(6);
 
        Gtk::CellRendererText* text_renderer = Gtk::manage (new Gtk::CellRendererText);
        text_renderer->property_editable() = false;
 
-       template_chooser.pack_start (*text_renderer);
-       template_chooser.add_attribute (text_renderer->property_text(), session_template_columns.name);
-       template_chooser.set_active (0);
+       template_chooser.set_model (template_model);
+       template_chooser.set_size_request(300,400);
+       template_chooser.append_column (_("Template"), session_template_columns.name);
+       template_chooser.append_column (_("Created With"), session_template_columns.created_with);
+       template_chooser.set_headers_visible (true);
+       template_chooser.get_selection()->set_mode (SELECTION_SINGLE);
+       template_chooser.get_selection()->signal_changed().connect (sigc::mem_fun (*this, &SessionDialog::template_row_selected));
+       template_chooser.set_sensitive (true);
 
        vbox3->pack_start (*hbox4a, false, false);
 
@@ -654,21 +647,16 @@ SessionDialog::setup_new_session_page ()
        more_new_session_options_button.add (more_options_vbox);
 
        vbox3->pack_start (*hbox5, false, false);
-       hbox3->pack_start (*vbox3, true, true, 8);
+
+       /* --- */
+
+       hbox3->pack_start (*vbox3, true, true);
        vbox2->pack_start (*hbox3, false, false);
 
        /* --- */
 
        session_new_vbox.pack_start (*vbox2, false, false);
        session_new_vbox.show_all ();
-
-       template_checkbox_toggled ();
-}
-
-void
-SessionDialog::template_checkbox_toggled ()
-{
-       template_chooser.set_sensitive (use_template_button.get_active());
 }
 
 void
@@ -928,6 +916,19 @@ SessionDialog::recent_session_row_selected ()
        }
 }
 
+void
+SessionDialog::template_row_selected ()
+{
+       if (template_chooser.get_selection()->count_selected_rows() > 0) {
+               TreeIter iter = template_chooser.get_selection()->get_selected();
+
+               if (iter) {
+                       string s = (*iter)[session_template_columns.description];
+                       template_desc.get_buffer()->set_text (s);
+               }
+       }
+}
+
 void
 SessionDialog::setup_more_options_box ()
 {
index 5f4062fc1bdd3a5badd783ec6e7472b761e8371f..5cb85a75ef8541ae5922c9767f0d804ca71c24ad 100644 (file)
@@ -30,6 +30,7 @@
 #include <gtkmm/radiobutton.h>
 #include <gtkmm/filechooserbutton.h>
 #include <gtkmm/scrolledwindow.h>
+#include <gtkmm/textview.h>
 #include <gtkmm/treeview.h>
 #include <gtkmm/treestore.h>
 #include <gtkmm/checkbutton.h>
@@ -165,26 +166,31 @@ private:
                SessionTemplateColumns () {
                        add (name);
                        add (path);
-                       add (desc);
+                       add (description);
+                       add (created_with);
                }
 
                Gtk::TreeModelColumn<std::string> name;
                Gtk::TreeModelColumn<std::string> path;
-               Gtk::TreeModelColumn<std::string> desc;
+               Gtk::TreeModelColumn<std::string> description;
+               Gtk::TreeModelColumn<std::string> created_with;
        };
 
        SessionTemplateColumns session_template_columns;
-       Glib::RefPtr<Gtk::ListStore>  template_model;
-       Gtk::ComboBox template_chooser;
+
+    Glib::RefPtr<Gtk::TreeStore>  template_model;
+    Gtk::TreeView                 template_chooser;
+       Gtk::ScrolledWindow           template_scroller;
+
+       void template_row_selected ();
+
+       Gtk::TextView template_desc;
 
        Gtk::VBox session_new_vbox;
        Gtk::VBox session_existing_vbox;
        Gtk::Expander more_new_session_options_button;
-       Gtk::CheckButton use_template_button;
        std::string load_template_override;
 
-       void template_checkbox_toggled ();
-
        void more_new_session_options_button_clicked();
        void new_name_changed ();
        void new_name_activated ();
index d89d0bcdafff31f42d99330d180663b0f0584b6d..07ba1d62ae178aed8aa0934328442ca3979f8306 100644 (file)
@@ -38,6 +38,7 @@ namespace ARDOUR {
                std::string name;
                std::string path;
                std::string description;
+               std::string created_with;
        };
 
        LIBARDOUR_API void find_route_templates (std::vector<TemplateInfo>& template_names);
index d355231115f13beebceeb44292f8435018bda47f..75c8d5b9afce60e4ccd8e85f97ff50f11f62c2e9 100644 (file)
@@ -33,6 +33,8 @@
 #include "ardour/search_paths.h"
 #include "ardour/io.h"
 
+#include "pbd/i18n.h"
+
 using namespace std;
 using namespace PBD;
 
@@ -103,8 +105,25 @@ find_session_templates (vector<TemplateInfo>& template_names, bool read_xml)
                        if (!tree.read (file.c_str())) {
                                continue;
                        }
-                       // TODO extract description,
-                       // compare to Session::get_info_from_path
+
+                       string created_with = "(unknown)";
+                       XMLNode *pv = tree.root()->child("ProgramVersion");
+                       if (pv != 0) {
+                               pv->get_property (X_("created-with"), created_with);
+                       }
+                       
+                       string description = "No Description";
+                       XMLNode *md = tree.root()->child("Metadata");
+                       if (md != 0) {
+                               XMLNode *desc = md->child("description");
+                               if (desc != 0) {
+                                       description = desc->attribute_value();
+                               }
+                       }
+                       
+                       rti.created_with = created_with;
+                       rti.description = description;
+                       
                }
 
                template_names.push_back (rti);