2 Copyright (C) 2010 Paul Davis
3 Author: Johannes Mueller
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
25 #include <glib/gstdio.h>
27 #include <gtkmm/filechooserdialog.h>
28 #include <gtkmm/frame.h>
29 #include <gtkmm/liststore.h>
30 #include <gtkmm/notebook.h>
31 #include <gtkmm/progressbar.h>
32 #include <gtkmm/separator.h>
33 #include <gtkmm/scrolledwindow.h>
34 #include <gtkmm/stock.h>
35 #include <gtkmm/textview.h>
36 #include <gtkmm/treeiter.h>
37 #include <gtkmm/treeview.h>
39 #include "pbd/basename.h"
40 #include "pbd/error.h"
41 #include "pbd/file_archive.h"
42 #include "pbd/file_utils.h"
44 #include "pbd/xml++.h"
46 #include "gtkmm2ext/gui_thread.h"
48 #include "ardour/filesystem_paths.h"
49 #include "ardour/template_utils.h"
51 #include "progress_reporter.h"
53 #include "template_dialog.h"
58 using namespace ARDOUR;
60 class TemplateManager : public Gtk::HBox,
61 public ProgressReporter
64 virtual ~TemplateManager () {}
67 void handle_dirty_description ();
69 PBD::Signal0<void> TemplatesImported;
74 void setup_model (const std::vector<ARDOUR::TemplateInfo>& templates);
76 void row_selection_changed ();
78 virtual void delete_selected_template () = 0;
79 bool adjust_plugin_paths (XMLNode* node, const std::string& name, const std::string& new_name) const;
81 struct SessionTemplateColumns : public Gtk::TreeModel::ColumnRecord {
82 SessionTemplateColumns () {
88 Gtk::TreeModelColumn<std::string> name;
89 Gtk::TreeModelColumn<std::string> path;
90 Gtk::TreeModelColumn<std::string> description;
93 Glib::RefPtr<Gtk::ListStore> _template_model;
94 SessionTemplateColumns _template_columns;
96 Gtk::TreeModel::const_iterator _current_selection;
98 Gtk::ProgressBar _progress_bar;
99 std::string _current_action;
102 void render_template_names (Gtk::CellRenderer* rnd, const Gtk::TreeModel::iterator& it);
103 void validate_edit (const Glib::ustring& path_string, const Glib::ustring& new_name);
106 void set_desc_dirty ();
108 bool key_event (GdkEventKey* ev);
110 virtual void get_templates (vector<TemplateInfo>& templates) const = 0;
112 virtual void rename_template (Gtk::TreeModel::iterator& item, const Glib::ustring& new_name) = 0;
114 virtual void save_template_desc ();
116 void export_all_templates ();
117 void import_template_set ();
119 virtual std::string templates_dir () const = 0;
120 virtual std::string template_file (const Gtk::TreeModel::const_iterator& item) const = 0;
122 virtual bool adjust_xml_tree (XMLTree& tree, const std::string& old_name, const std::string& new_name) const = 0;
124 Gtk::TreeView _template_treeview;
125 Gtk::CellRendererText _validating_cellrenderer;
126 Gtk::TreeView::Column _validated_column;
128 Gtk::TextView _description_editor;
129 Gtk::Button _save_desc;
132 Gtk::Button _remove_button;
133 Gtk::Button _rename_button;
135 Gtk::Button _export_all_templates_button;
136 Gtk::Button _import_template_set_button;
138 sigc::connection _cursor_changed_connection;
140 void update_progress_gui (float p);
143 class SessionTemplateManager : public TemplateManager
146 SessionTemplateManager () : TemplateManager () {}
147 ~SessionTemplateManager () {}
149 void get_templates (vector<TemplateInfo>& templates) const;
152 void rename_template (Gtk::TreeModel::iterator& item, const Glib::ustring& new_name);
153 void delete_selected_template ();
155 std::string templates_dir () const;
156 std::string template_file (const Gtk::TreeModel::const_iterator& item) const;
158 bool adjust_xml_tree (XMLTree& tree, const std::string& old_name, const std::string& new_name) const;
162 class RouteTemplateManager : public TemplateManager
165 RouteTemplateManager () : TemplateManager () {}
166 ~RouteTemplateManager () {}
168 void get_templates (vector<TemplateInfo>& templates) const;
171 void rename_template (Gtk::TreeModel::iterator& item, const Glib::ustring& new_name);
172 void delete_selected_template ();
174 std::string templates_dir () const;
175 std::string template_file (const Gtk::TreeModel::const_iterator& item) const;
177 bool adjust_xml_tree (XMLTree& tree, const std::string& old_name, const std::string& new_name) const;
182 TemplateDialog::TemplateDialog ()
183 : ArdourDialog ("Manage Templates")
185 Notebook* nb = manage (new Notebook);
187 SessionTemplateManager* session_tm = manage (new SessionTemplateManager);
188 nb->append_page (*session_tm, _("Session Templates"));
190 RouteTemplateManager* route_tm = manage (new RouteTemplateManager);
191 nb->append_page (*route_tm, _("Track Templates"));
193 get_vbox()->pack_start (*nb);
194 add_button (_("Done"), Gtk::RESPONSE_OK);
196 get_vbox()->show_all();
201 session_tm->TemplatesImported.connect (*this, invalidator (*this), boost::bind (&RouteTemplateManager::init, route_tm), gui_context ());
202 route_tm->TemplatesImported.connect (*this, invalidator (*this), boost::bind (&SessionTemplateManager::init, session_tm), gui_context ());
204 signal_hide().connect (sigc::mem_fun (session_tm, &TemplateManager::handle_dirty_description));
205 signal_hide().connect (sigc::mem_fun (route_tm, &TemplateManager::handle_dirty_description));
206 nb->signal_switch_page().connect (boost::bind (&TemplateManager::handle_dirty_description, session_tm));
207 nb->signal_switch_page().connect (boost::bind (&TemplateManager::handle_dirty_description, route_tm));
210 TemplateManager::TemplateManager ()
212 , ProgressReporter ()
213 , _save_desc (_("Save Description"))
214 , _desc_dirty (false)
215 , _remove_button (_("Remove"))
216 , _rename_button (_("Rename"))
217 , _export_all_templates_button (_("Export all"))
218 , _import_template_set_button (_("Import"))
220 _template_model = ListStore::create (_template_columns);
221 _template_treeview.set_model (_template_model);
223 _validated_column.set_title (_("Template Name"));
224 _validated_column.pack_start (_validating_cellrenderer);
225 _template_treeview.append_column (_validated_column);
226 _validating_cellrenderer.property_editable() = true;
228 _validated_column.set_cell_data_func (_validating_cellrenderer, sigc::mem_fun (*this, &TemplateManager::render_template_names));
229 _validating_cellrenderer.signal_edited().connect (sigc::mem_fun (*this, &TemplateManager::validate_edit));
230 _cursor_changed_connection = _template_treeview.signal_cursor_changed().connect (sigc::mem_fun (*this, &TemplateManager::row_selection_changed));
231 _template_treeview.signal_key_press_event().connect (sigc::mem_fun (*this, &TemplateManager::key_event));
233 ScrolledWindow* sw = manage (new ScrolledWindow);
234 sw->property_hscrollbar_policy() = POLICY_AUTOMATIC;
235 sw->add (_template_treeview);
236 sw->set_size_request (300, 200);
238 VBox* vb_btns = manage (new VBox);
239 vb_btns->set_spacing (4);
240 vb_btns->pack_start (_rename_button, false, false);
241 vb_btns->pack_start (_remove_button, false, false);
242 vb_btns->pack_start (_save_desc, false, false);
244 _rename_button.set_sensitive (false);
245 _rename_button.signal_clicked().connect (sigc::mem_fun (*this, &TemplateManager::start_edit));
246 _remove_button.set_sensitive (false);
247 _remove_button.signal_clicked().connect (sigc::mem_fun (*this, &TemplateManager::delete_selected_template));
249 vb_btns->pack_start (*(manage (new VSeparator ())));
251 vb_btns->pack_start (_export_all_templates_button, false, false);
252 vb_btns->pack_start (_import_template_set_button, false, false);
254 _export_all_templates_button.set_sensitive (false);
255 _export_all_templates_button.signal_clicked().connect (sigc::mem_fun (*this, &TemplateManager::export_all_templates));
257 _import_template_set_button.set_sensitive (true);
258 _import_template_set_button.signal_clicked().connect (sigc::mem_fun (*this, &TemplateManager::import_template_set));
262 VBox* vb = manage (new VBox);
263 vb->pack_start (*sw);
264 vb->pack_start (_progress_bar);
266 Frame* desc_frame = manage (new Frame (_("Description")));
268 _description_editor.set_wrap_mode (Gtk::WRAP_WORD);
269 _description_editor.set_size_request (300,400);
270 _description_editor.set_border_width (6);
272 _save_desc.set_sensitive (false);
273 _save_desc.signal_clicked().connect (sigc::mem_fun (*this, &TemplateManager::save_template_desc));
275 _description_editor.get_buffer()->signal_changed().connect (sigc::mem_fun (*this, &TemplateManager::set_desc_dirty));
277 desc_frame->add (_description_editor);
280 pack_start (*desc_frame);
281 pack_start (*vb_btns);
283 show_all_children ();
284 _progress_bar.hide ();
288 TemplateManager::init ()
290 vector<TemplateInfo> templates;
291 get_templates (templates);
292 setup_model (templates);
294 _progress_bar.hide ();
295 _description_editor.set_sensitive (false);
296 _save_desc.set_sensitive (false);
300 TemplateManager::setup_model (const vector<TemplateInfo>& templates)
302 _template_model->clear ();
304 for (vector<TemplateInfo>::const_iterator it = templates.begin(); it != templates.end(); ++it) {
306 row = *(_template_model->append ());
308 row[_template_columns.name] = it->name;
309 row[_template_columns.path] = it->path;
310 row[_template_columns.description] = it->description;
313 _export_all_templates_button.set_sensitive (!templates.empty ());
317 TemplateManager::handle_dirty_description ()
319 if (_desc_dirty && _current_selection) {
320 ArdourDialog dlg (_("Description not saved"), true);
321 const string name = _current_selection->get_value (_template_columns.name);
322 Label msg (string_compose (_("The discription of template \"%1\" has been modfied but has not been saved yet.\n"
323 "Do you want to save it?"), name));
324 dlg.get_vbox()->pack_start (msg);
326 dlg.add_button (_("Save"), RESPONSE_ACCEPT);
327 dlg.add_button (_("Discard"), RESPONSE_REJECT);
328 dlg.set_default_response (RESPONSE_REJECT);
330 int response = dlg.run ();
332 if (response == RESPONSE_ACCEPT) {
333 save_template_desc ();
335 _description_editor.get_buffer()->set_text (_current_selection->get_value (_template_columns.description));
341 TemplateManager::row_selection_changed ()
343 if (_current_selection) {
344 handle_dirty_description ();
346 _description_editor.get_buffer()->set_text ("");
349 _current_selection = _template_treeview.get_selection()->get_selected ();
350 if (_current_selection) {
351 const string desc = _current_selection->get_value (_template_columns.description);
352 _description_editor.get_buffer()->set_text (desc);
356 _save_desc.set_sensitive (false);
358 _description_editor.set_sensitive (_current_selection);
359 _rename_button.set_sensitive (_current_selection);
360 _remove_button.set_sensitive (_current_selection);
364 TemplateManager::render_template_names (Gtk::CellRenderer*, const Gtk::TreeModel::iterator& it)
367 _validating_cellrenderer.property_text () = it->get_value (_template_columns.name);
372 TemplateManager::validate_edit (const Glib::ustring& path_string, const Glib::ustring& new_name)
374 const TreePath path (path_string);
375 TreeModel::iterator current = _template_model->get_iter (path);
377 if (current->get_value (_template_columns.name) == new_name) {
381 TreeModel::Children rows = _template_model->children ();
384 for (TreeModel::Children::const_iterator it = rows.begin(); it != rows.end(); ++it) {
385 if (it->get_value (_template_columns.name) == new_name) {
392 error << string_compose (_("Template of name \"%1\" already exists"), new_name) << endmsg;
397 rename_template (current, new_name);
401 TemplateManager::start_edit ()
403 TreeModel::Path path;
405 _template_treeview.get_cursor (path, col);
406 _cursor_changed_connection.block ();
407 _template_treeview.set_cursor (path, *col, /*set_editing =*/ true);
408 _cursor_changed_connection.unblock ();
412 TemplateManager::set_desc_dirty ()
415 _save_desc.set_sensitive (true);
419 TemplateManager::save_template_desc ()
421 const string file_path = template_file (_current_selection);
423 string desc_txt = _description_editor.get_buffer()->get_text ();
424 string::reverse_iterator wss = desc_txt.rbegin();
425 while (wss != desc_txt.rend() && isspace (*wss)) {
426 desc_txt.erase (--(wss++).base());
429 _current_selection->set_value (_template_columns.description, desc_txt);
433 if (!tree.read(file_path)) {
434 error << string_compose (_("Could not parse template file \"%1\"."), file_path) << endmsg;
438 tree.root()->remove_nodes_and_delete (X_("description"));
439 XMLNode* desc = new XMLNode (X_("description"));
441 XMLNode* dn = new XMLNode (X_("content"), desc_txt);
442 desc->add_child_nocopy (*dn);
444 tree.root()->add_child_nocopy (*desc);
446 if (!tree.write ()) {
447 error << string_compose(X_("Could not write to template file \"%1\"."), file_path) << endmsg;
451 _save_desc.set_sensitive (false);
456 TemplateManager::key_event (GdkEventKey* ev)
458 if (ev->keyval == GDK_KEY_F2) {
462 if (ev->keyval == GDK_KEY_Delete) {
463 delete_selected_template ();
471 bool accept_all_files (string const &, void *)
476 static void _set_progress (Progress* p, size_t n, size_t t)
478 p->set_progress (float (n) / float(t));
483 TemplateManager::export_all_templates ()
486 char* td = g_dir_make_tmp ("ardour-templates-XXXXXX", &err);
489 error << string_compose(_("Could not make tmpdir: %1"), err->message) << endmsg;
492 const string tmpdir (td);
494 g_clear_error (&err);
496 FileChooserDialog dialog(_("Save Exported Template Archive"), FILE_CHOOSER_ACTION_SAVE);
497 dialog.set_filename (X_("templates.tar.xz"));
499 dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
500 dialog.add_button(Gtk::Stock::OK, Gtk::RESPONSE_OK);
502 FileFilter archive_filter;
503 archive_filter.add_pattern (X_("*.tar.xz"));
504 archive_filter.set_name (_("Template archives"));
505 dialog.add_filter (archive_filter);
507 int result = dialog.run ();
509 if (result != RESPONSE_OK || !dialog.get_filename().length()) {
510 PBD::remove_directory (tmpdir);
514 string filename = dialog.get_filename ();
515 if (filename.compare (filename.size () - 7, 7, ".tar.xz")) {
516 filename += ".tar.xz";
519 if (g_file_test (filename.c_str(), G_FILE_TEST_EXISTS)) {
520 ArdourDialog dlg (_("File exists"), true);
521 Label msg (string_compose (_("The file %1 already exists."), filename));
522 dlg.get_vbox()->pack_start (msg);
524 dlg.add_button (_("Overwrite"), RESPONSE_ACCEPT);
525 dlg.add_button (_("Cancel"), RESPONSE_REJECT);
526 dlg.set_default_response (RESPONSE_REJECT);
530 if (result == RESPONSE_REJECT) {
531 PBD::remove_directory (tmpdir);
536 PBD::copy_recurse (templates_dir (), Glib::build_filename (tmpdir, Glib::path_get_basename (templates_dir ())));
538 vector<string> files;
539 PBD::find_files_matching_regex (files, tmpdir, string ("\\.template$"), /* recurse = */ true);
541 vector<string>::const_iterator it;
542 for (it = files.begin(); it != files.end(); ++it) {
543 const string bn = PBD::basename_nosuffix (*it);
544 const string old_path = Glib::build_filename (templates_dir (), bn);
545 const string new_path = Glib::build_filename ("$TEMPLATEDIR", bn);
548 if (!tree.read (*it)) {
551 if (adjust_xml_tree (tree, old_path, new_path)) {
556 find_files_matching_filter (files, tmpdir, accept_all_files, 0, false, true, true);
558 std::map<std::string, std::string> filemap;
559 for (it = files.begin(); it != files.end(); ++it) {
560 filemap[*it] = it->substr (tmpdir.size()+1, it->size() - tmpdir.size() - 1);
563 _current_action = _("Exporting templates");
565 PBD::FileArchive ar (filename);
566 PBD::ScopedConnectionList progress_connection;
567 ar.progress.connect_same_thread (progress_connection, boost::bind (&_set_progress, this, _1, _2));
570 PBD::remove_directory (tmpdir);
574 TemplateManager::import_template_set ()
576 FileChooserDialog dialog (_("Import template archives"));
577 dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
578 dialog.add_button(Gtk::Stock::OK, Gtk::RESPONSE_OK);
580 FileFilter archive_filter;
581 archive_filter.add_pattern (X_("*.tar.xz"));
582 archive_filter.set_name (_("Template archives"));
583 dialog.add_filter (archive_filter);
585 int result = dialog.run ();
587 if (result != RESPONSE_OK || !dialog.get_filename().length()) {
591 _current_action = _("Importing templates");
593 FileArchive ar (dialog.get_filename ());
594 PBD::ScopedConnectionList progress_connection;
595 ar.progress.connect_same_thread (progress_connection, boost::bind (&_set_progress, this, _1, _2));
596 ar.inflate (user_config_directory ());
598 vector<string> files;
599 PBD::find_files_matching_regex (files, templates_dir (), string ("\\.template$"), /* recurse = */ true);
601 vector<string>::const_iterator it;
602 for (it = files.begin(); it != files.end(); ++it) {
603 const string bn = PBD::basename_nosuffix (*it);
604 const string old_path = Glib::build_filename ("$TEMPLATEDIR", bn);
605 const string new_path = Glib::build_filename (templates_dir (), bn);
608 if (!tree.read (*it)) {
611 if (adjust_xml_tree (tree, old_path, new_path)) {
617 TemplatesImported (); /* emit signal */
621 TemplateManager::adjust_plugin_paths (XMLNode* node, const string& name, const string& new_name) const
623 bool adjusted = false;
625 const XMLNodeList& procs = node->children (X_("Processor"));
626 XMLNodeConstIterator pit;
627 for (pit = procs.begin(); pit != procs.end(); ++pit) {
628 XMLNode* lv2_node = (*pit)->child (X_("lv2"));
634 if (!lv2_node->get_property (X_("template-dir"), template_dir)) {
638 const int suffix_pos = template_dir.size() - name.size();
639 if (suffix_pos < 0) {
640 cerr << "Template name\"" << name << "\" longer than template-dir \"" << template_dir << "\", WTH?" << endl;
644 if (template_dir.compare (suffix_pos, template_dir.size(), name)) {
645 cerr << "Template name \"" << name << "\" no suffix of template-dir \"" << template_dir << "\"" << endl;
649 const string new_template_dir = template_dir.substr (0, suffix_pos) + new_name;
650 lv2_node->set_property (X_("template-dir"), new_template_dir);
659 TemplateManager::update_progress_gui (float p)
662 _progress_bar.hide ();
666 _progress_bar.show ();
667 _progress_bar.set_text (_current_action);
668 _progress_bar.set_fraction (p);
672 SessionTemplateManager::get_templates (vector<TemplateInfo>& templates) const
674 find_session_templates (templates, /* read_xml = */ true);
677 void RouteTemplateManager::get_templates (vector<TemplateInfo>& templates) const
679 find_route_templates (templates);
685 SessionTemplateManager::rename_template (TreeModel::iterator& item, const Glib::ustring& new_name_)
687 const string old_path = item->get_value (_template_columns.path);
688 const string old_name = item->get_value (_template_columns.name);
689 const string new_name = string (new_name_);
691 const string old_file_old_path = Glib::build_filename (old_path, old_name+".template");
695 if (!tree.read(old_file_old_path)) {
696 error << string_compose (_("Could not parse template file \"%1\"."), old_file_old_path) << endmsg;
699 XMLNode* root = tree.root();
701 const XMLNode* const routes_node = root->child (X_("Routes"));
703 const XMLNodeList& routes = routes_node->children (X_("Route"));
704 XMLNodeConstIterator rit;
705 for (rit = routes.begin(); rit != routes.end(); ++rit) {
706 adjust_plugin_paths (*rit, old_name, new_name);
710 const string new_file_old_path = Glib::build_filename (old_path, new_name+".template");
712 tree.set_filename (new_file_old_path);
714 if (!tree.write ()) {
715 error << string_compose(_("Could not write to new template file \"%1\"."), new_file_old_path);
719 const string new_path = Glib::build_filename (user_template_directory (), new_name);
721 if (g_rename (old_path.c_str(), new_path.c_str()) != 0) {
722 error << string_compose (_("Could not rename template directory from \"%1\" to \"%2\": %3"),
723 old_path, new_path, strerror (errno)) << endmsg;
724 g_unlink (new_file_old_path.c_str());
728 const string old_file_new_path = Glib::build_filename (new_path, old_name+".template");
729 if (g_unlink (old_file_new_path.c_str())) {
730 error << string_compose (X_("Could not delete old template file \"%1\": %2"),
731 old_file_new_path, strerror (errno)) << endmsg;
734 item->set_value (_template_columns.name, new_name);
735 item->set_value (_template_columns.path, new_path);
739 SessionTemplateManager::delete_selected_template ()
741 if (!_current_selection) {
745 PBD::remove_directory (_current_selection->get_value (_template_columns.path));
747 _template_model->erase (_current_selection);
748 _current_selection = TreeIter ();
749 row_selection_changed ();
753 SessionTemplateManager::templates_dir () const
755 return user_template_directory ();
760 SessionTemplateManager::template_file (const TreeModel::const_iterator& item) const
762 const string path = item->get_value (_template_columns.path);
763 const string name = item->get_value (_template_columns.name);
764 return Glib::build_filename (path, name+".template");
768 SessionTemplateManager::adjust_xml_tree (XMLTree& tree, const std::string& old_name, const std::string& new_name) const
770 bool adjusted = false;
771 XMLNode* root = tree.root();
773 const XMLNode* const routes_node = root->child (X_("Routes"));
775 const XMLNodeList& routes = routes_node->children (X_("Route"));
776 XMLNodeConstIterator rit;
777 for (rit = routes.begin(); rit != routes.end(); ++rit) {
778 if (adjust_plugin_paths (*rit, old_name, new_name)) {
789 RouteTemplateManager::rename_template (TreeModel::iterator& item, const Glib::ustring& new_name)
791 const string old_name = item->get_value (_template_columns.name);
792 const string old_filepath = item->get_value (_template_columns.path);
793 const string new_filepath = Glib::build_filename (user_route_template_directory(), new_name+".template");
796 if (!tree.read (old_filepath)) {
797 error << string_compose (_("Could not parse template file \"%1\"."), old_filepath) << endmsg;
800 tree.root()->set_property (X_("name"), new_name);
801 tree.root()->children().front()->set_property (X_("name"), new_name);
803 const bool adjusted = adjust_plugin_paths (tree.root(), old_name, string (new_name));
805 const string old_state_dir = Glib::build_filename (user_route_template_directory(), old_name);
806 const string new_state_dir = Glib::build_filename (user_route_template_directory(), new_name);
809 if (g_file_test (old_state_dir.c_str(), G_FILE_TEST_EXISTS)) {
810 if (g_rename (old_state_dir.c_str(), new_state_dir.c_str()) != 0) {
811 error << string_compose (_("Could not rename state dir \"%1\" to \"%22\": %3"), old_state_dir, new_state_dir, strerror (errno)) << endmsg;
817 tree.set_filename (new_filepath);
819 if (!tree.write ()) {
820 error << string_compose(_("Could not write new template file \"%1\"."), new_filepath) << endmsg;
822 g_rename (new_state_dir.c_str(), old_state_dir.c_str());
827 if (g_unlink (old_filepath.c_str()) != 0) {
828 error << string_compose (_("Could not remove old template file \"%1\": %2"), old_filepath, strerror (errno)) << endmsg;
831 item->set_value (_template_columns.name, string (new_name));
832 item->set_value (_template_columns.path, new_filepath);
836 RouteTemplateManager::delete_selected_template ()
838 if (!_current_selection) {
842 const string file_path = _current_selection->get_value (_template_columns.path);
844 if (g_unlink (file_path.c_str()) != 0) {
845 error << string_compose(_("Could not delete template file \"%1\": %2"), file_path, strerror (errno)) << endmsg;
848 PBD::remove_directory (Glib::build_filename (user_route_template_directory (),
849 _current_selection->get_value (_template_columns.name)));
851 _template_model->erase (_current_selection);
852 row_selection_changed ();
856 RouteTemplateManager::templates_dir () const
858 return user_route_template_directory ();
863 RouteTemplateManager::template_file (const TreeModel::const_iterator& item) const
865 return item->get_value (_template_columns.path);
869 RouteTemplateManager::adjust_xml_tree (XMLTree& tree, const std::string& old_name, const std::string& new_name) const
871 return adjust_plugin_paths (tree.root(), old_name, string (new_name));