13
0

Change the template pulldown menu into a tree list. Populate the Description view when a template is selected.

This commit is contained in:
Ben Loftis 2017-08-14 16:14:42 -05:00
parent 0a0eec2adc
commit 47d86cf54d
4 changed files with 94 additions and 67 deletions

View File

@ -116,7 +116,6 @@ SessionDialog::SessionDialog (bool require_new, const std::string& session_name,
} }
if (!template_name.empty()) { if (!template_name.empty()) {
use_template_button.set_active (false);
load_template_override = template_name; load_template_override = template_name;
} }
@ -126,14 +125,6 @@ SessionDialog::SessionDialog (bool require_new, const std::string& session_name,
populate_session_templates (); 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) { if (recent_session_model) {
int cnt = redisplay_recent_sessions (); int cnt = redisplay_recent_sessions ();
if (cnt > 0) { if (cnt > 0) {
@ -218,7 +209,7 @@ SessionDialog::use_session_template ()
return true; return true;
} }
if (use_template_button.get_active()) { if (template_chooser.get_selection()->count_selected_rows() > 0) {
return true; return true;
} }
@ -233,11 +224,13 @@ SessionDialog::session_template_name ()
return Glib::build_filename (the_path, load_template_override + ARDOUR::template_suffix); return Glib::build_filename (the_path, load_template_override + ARDOUR::template_suffix);
} }
if (use_template_button.get_active()) { if (template_chooser.get_selection()->count_selected_rows() > 0) {
TreeModel::iterator iter = template_chooser.get_active (); TreeIter iter = template_chooser.get_selection()->get_selected();
TreeModel::Row row = (*iter);
string s = row[session_template_columns.path]; if (iter) {
return s; string s = (*iter)[session_template_columns.path];
return s;
}
} }
return string(); return string();
@ -506,10 +499,25 @@ SessionDialog::populate_session_templates ()
{ {
vector<TemplateInfo> templates; vector<TemplateInfo> templates;
find_session_templates (templates); find_session_templates (templates, true);
template_model->clear (); template_model->clear ();
// 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) {
TreeModel::Row row;
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.description] = (*s)->description;
row[session_template_columns.created_with] = _("{Factory Template}");
}
for (vector<TemplateInfo>::iterator x = templates.begin(); x != templates.end(); ++x) { for (vector<TemplateInfo>::iterator x = templates.begin(); x != templates.end(); ++x) {
TreeModel::Row row; TreeModel::Row row;
@ -517,22 +525,10 @@ SessionDialog::populate_session_templates ()
row[session_template_columns.name] = (*x).name; row[session_template_columns.name] = (*x).name;
row[session_template_columns.path] = (*x).path; row[session_template_columns.path] = (*x).path;
row[session_template_columns.desc] = (*x).description; row[session_template_columns.description] = (*x).description;
row[session_template_columns.created_with] = (*x).created_with;
} }
LuaScriptList& ms (LuaScripting::instance ().scripts (LuaScriptInfo::SessionSetup));
for (LuaScriptList::const_iterator s = ms.begin(); s != ms.end(); ++s) {
TreeModel::Row row;
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;
}
if (!templates.empty()) {
/* select first row */
template_chooser.set_active (0);
}
} }
void void
@ -606,7 +602,7 @@ SessionDialog::setup_new_session_page ()
VBox *vbox2 = manage (new VBox); VBox *vbox2 = manage (new VBox);
HBox* hbox3 = manage (new HBox); HBox* hbox3 = manage (new HBox);
template_model = ListStore::create (session_template_columns); template_model = TreeStore::create (session_template_columns);
vbox2->set_spacing (6); vbox2->set_spacing (6);
@ -614,32 +610,29 @@ SessionDialog::setup_new_session_page ()
vbox3->set_spacing (6); 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); 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->set_spacing (6);
hbox4a->pack_start (use_template_button, false, false); hbox4a->pack_start (template_chooser, false, false);
hbox4a->pack_start (template_chooser, true, true); 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); Gtk::CellRendererText* text_renderer = Gtk::manage (new Gtk::CellRendererText);
text_renderer->property_editable() = false; text_renderer->property_editable() = false;
template_chooser.pack_start (*text_renderer); template_chooser.set_model (template_model);
template_chooser.add_attribute (text_renderer->property_text(), session_template_columns.name); template_chooser.set_size_request(300,400);
template_chooser.set_active (0); 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); vbox3->pack_start (*hbox4a, false, false);
@ -654,21 +647,16 @@ SessionDialog::setup_new_session_page ()
more_new_session_options_button.add (more_options_vbox); more_new_session_options_button.add (more_options_vbox);
vbox3->pack_start (*hbox5, false, false); 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); vbox2->pack_start (*hbox3, false, false);
/* --- */ /* --- */
session_new_vbox.pack_start (*vbox2, false, false); session_new_vbox.pack_start (*vbox2, false, false);
session_new_vbox.show_all (); session_new_vbox.show_all ();
template_checkbox_toggled ();
}
void
SessionDialog::template_checkbox_toggled ()
{
template_chooser.set_sensitive (use_template_button.get_active());
} }
void 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 void
SessionDialog::setup_more_options_box () SessionDialog::setup_more_options_box ()
{ {

View File

@ -30,6 +30,7 @@
#include <gtkmm/radiobutton.h> #include <gtkmm/radiobutton.h>
#include <gtkmm/filechooserbutton.h> #include <gtkmm/filechooserbutton.h>
#include <gtkmm/scrolledwindow.h> #include <gtkmm/scrolledwindow.h>
#include <gtkmm/textview.h>
#include <gtkmm/treeview.h> #include <gtkmm/treeview.h>
#include <gtkmm/treestore.h> #include <gtkmm/treestore.h>
#include <gtkmm/checkbutton.h> #include <gtkmm/checkbutton.h>
@ -165,26 +166,31 @@ private:
SessionTemplateColumns () { SessionTemplateColumns () {
add (name); add (name);
add (path); add (path);
add (desc); add (description);
add (created_with);
} }
Gtk::TreeModelColumn<std::string> name; Gtk::TreeModelColumn<std::string> name;
Gtk::TreeModelColumn<std::string> path; 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; 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_new_vbox;
Gtk::VBox session_existing_vbox; Gtk::VBox session_existing_vbox;
Gtk::Expander more_new_session_options_button; Gtk::Expander more_new_session_options_button;
Gtk::CheckButton use_template_button;
std::string load_template_override; std::string load_template_override;
void template_checkbox_toggled ();
void more_new_session_options_button_clicked(); void more_new_session_options_button_clicked();
void new_name_changed (); void new_name_changed ();
void new_name_activated (); void new_name_activated ();

View File

@ -38,6 +38,7 @@ namespace ARDOUR {
std::string name; std::string name;
std::string path; std::string path;
std::string description; std::string description;
std::string created_with;
}; };
LIBARDOUR_API void find_route_templates (std::vector<TemplateInfo>& template_names); LIBARDOUR_API void find_route_templates (std::vector<TemplateInfo>& template_names);

View File

@ -33,6 +33,8 @@
#include "ardour/search_paths.h" #include "ardour/search_paths.h"
#include "ardour/io.h" #include "ardour/io.h"
#include "pbd/i18n.h"
using namespace std; using namespace std;
using namespace PBD; using namespace PBD;
@ -103,8 +105,25 @@ find_session_templates (vector<TemplateInfo>& template_names, bool read_xml)
if (!tree.read (file.c_str())) { if (!tree.read (file.c_str())) {
continue; 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); template_names.push_back (rti);