Allow deleting templates from context-menu in session dialog
This commit is contained in:
parent
51471138d7
commit
029b2e4b47
@ -620,6 +620,47 @@ SessionDialog::setup_untitled_session ()
|
||||
new_name_was_edited = false;
|
||||
}
|
||||
|
||||
void
|
||||
SessionDialog::delete_selected_template ()
|
||||
{
|
||||
Gtk::TreeModel::const_iterator current_selection = template_chooser.get_selection()->get_selected ();
|
||||
|
||||
if (!current_selection) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!current_selection->get_value (session_template_columns.removable)) {
|
||||
ArdourMessageDialog msg (("This type of template cannot be deleted"));
|
||||
msg.run ();
|
||||
return; //cannot delete built-in scripts
|
||||
}
|
||||
|
||||
PBD::remove_directory (current_selection->get_value (session_template_columns.path));
|
||||
|
||||
template_model->erase (current_selection);
|
||||
|
||||
populate_session_templates ();
|
||||
}
|
||||
bool
|
||||
SessionDialog::template_button_press (GdkEventButton* ev)
|
||||
{
|
||||
if (Gtkmm2ext::Keyboard::is_context_menu_event (ev)) {
|
||||
show_template_context_menu (ev->button, ev->time);
|
||||
/* return false to select item under the mouse */
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void
|
||||
SessionDialog::show_template_context_menu (int button, int time)
|
||||
{
|
||||
using namespace Gtk::Menu_Helpers;
|
||||
Gtk::Menu* menu = ARDOUR_UI::instance()->shared_popup_menu ();
|
||||
MenuList& items = menu->items ();
|
||||
items.push_back (MenuElem (_("Delete the selected Template"), hide_return (sigc::mem_fun (*this, &SessionDialog::delete_selected_template))));
|
||||
menu->popup (button, time);
|
||||
}
|
||||
|
||||
void
|
||||
SessionDialog::populate_session_templates ()
|
||||
{
|
||||
@ -649,6 +690,7 @@ SessionDialog::populate_session_templates ()
|
||||
row[session_template_columns.description] = (*s)->description;
|
||||
row[session_template_columns.modified_with_short] = string_compose ("{%1}", _("Factory Template"));
|
||||
row[session_template_columns.modified_with_long] = string_compose ("{%1}", _("Factory Template"));
|
||||
row[session_template_columns.removable] = false;
|
||||
}
|
||||
|
||||
//Add any "template sessions" found in the user's preferences folder
|
||||
@ -662,6 +704,7 @@ SessionDialog::populate_session_templates ()
|
||||
row[session_template_columns.description] = (*x).description;
|
||||
row[session_template_columns.modified_with_long] = (*x).modified_with;
|
||||
row[session_template_columns.modified_with_short] = (*x).modified_with.substr(0, (*x).modified_with.find(" "));
|
||||
row[session_template_columns.removable] = true;
|
||||
}
|
||||
|
||||
//Add an explicit 'Empty Template' item
|
||||
@ -671,6 +714,7 @@ SessionDialog::populate_session_templates ()
|
||||
row[session_template_columns.description] = _("An empty session with factory default settings.\n\nSelect this option if you are importing files to mix.");
|
||||
row[session_template_columns.modified_with_short] = ("");
|
||||
row[session_template_columns.modified_with_long] = ("");
|
||||
row[session_template_columns.removable] = false;
|
||||
|
||||
//auto-select the first item in the list
|
||||
Gtk::TreeModel::Row first = template_model->children()[0];
|
||||
@ -785,6 +829,7 @@ SessionDialog::setup_new_session_page ()
|
||||
#endif
|
||||
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.signal_button_press_event ().connect (sigc::mem_fun (*this, &SessionDialog::template_button_press), false);
|
||||
template_chooser.set_sensitive (true);
|
||||
if (UIConfiguration::instance().get_use_tooltips()) {
|
||||
template_chooser.set_tooltip_column(4); // modified_with_long
|
||||
|
@ -81,6 +81,10 @@ public:
|
||||
void clear_name ();
|
||||
bool was_new_name_edited() const { return new_name_was_edited; }
|
||||
|
||||
void delete_selected_template();
|
||||
void show_template_context_menu (int button, int time);
|
||||
bool template_button_press (GdkEventButton*);
|
||||
|
||||
private:
|
||||
bool on_delete_event (GdkEventAny*);
|
||||
|
||||
@ -184,6 +188,7 @@ private:
|
||||
add (description);
|
||||
add (modified_with_short);
|
||||
add (modified_with_long);
|
||||
add (removable);
|
||||
}
|
||||
|
||||
Gtk::TreeModelColumn<std::string> name;
|
||||
@ -191,6 +196,7 @@ private:
|
||||
Gtk::TreeModelColumn<std::string> description;
|
||||
Gtk::TreeModelColumn<std::string> modified_with_short;
|
||||
Gtk::TreeModelColumn<std::string> modified_with_long;
|
||||
Gtk::TreeModelColumn<bool> removable;
|
||||
};
|
||||
|
||||
SessionTemplateColumns session_template_columns;
|
||||
|
Loading…
Reference in New Issue
Block a user