From 47d86cf54d64ae2f65c7ffa961ccc583d33f3382 Mon Sep 17 00:00:00 2001 From: Ben Loftis Date: Mon, 14 Aug 2017 16:14:42 -0500 Subject: [PATCH] Change the template pulldown menu into a tree list. Populate the Description view when a template is selected. --- gtk2_ardour/session_dialog.cc | 115 ++++++++++++++-------------- gtk2_ardour/session_dialog.h | 20 +++-- libs/ardour/ardour/template_utils.h | 1 + libs/ardour/template_utils.cc | 23 +++++- 4 files changed, 93 insertions(+), 66 deletions(-) diff --git a/gtk2_ardour/session_dialog.cc b/gtk2_ardour/session_dialog.cc index 08f7b15c16..8d8fa54e74 100644 --- a/gtk2_ardour/session_dialog.cc +++ b/gtk2_ardour/session_dialog.cc @@ -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 templates; - find_session_templates (templates); + find_session_templates (templates, true); template_model->clear (); - for (vector::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::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 () { diff --git a/gtk2_ardour/session_dialog.h b/gtk2_ardour/session_dialog.h index 5f4062fc1b..5cb85a75ef 100644 --- a/gtk2_ardour/session_dialog.h +++ b/gtk2_ardour/session_dialog.h @@ -30,6 +30,7 @@ #include #include #include +#include #include #include #include @@ -165,26 +166,31 @@ private: SessionTemplateColumns () { add (name); add (path); - add (desc); + add (description); + add (created_with); } Gtk::TreeModelColumn name; Gtk::TreeModelColumn path; - Gtk::TreeModelColumn desc; + Gtk::TreeModelColumn description; + Gtk::TreeModelColumn created_with; }; SessionTemplateColumns session_template_columns; - Glib::RefPtr template_model; - Gtk::ComboBox template_chooser; + + Glib::RefPtr 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 (); diff --git a/libs/ardour/ardour/template_utils.h b/libs/ardour/ardour/template_utils.h index d89d0bcdaf..07ba1d62ae 100644 --- a/libs/ardour/ardour/template_utils.h +++ b/libs/ardour/ardour/template_utils.h @@ -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& template_names); diff --git a/libs/ardour/template_utils.cc b/libs/ardour/template_utils.cc index d355231115..75c8d5b9af 100644 --- a/libs/ardour/template_utils.cc +++ b/libs/ardour/template_utils.cc @@ -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& 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); -- 2.30.2