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 () {}
66 virtual void init () = 0;
67 void handle_dirty_description ();
69 PBD::Signal0<void> TemplatesImported;
74 Gtk::TextView _description_editor;
75 Gtk::Button _save_desc;
77 void setup_model (const std::vector<ARDOUR::TemplateInfo>& templates);
79 void row_selection_changed ();
81 virtual void delete_selected_template () = 0;
82 bool adjust_plugin_paths (XMLNode* node, const std::string& name, const std::string& new_name) const;
84 struct SessionTemplateColumns : public Gtk::TreeModel::ColumnRecord {
85 SessionTemplateColumns () {
91 Gtk::TreeModelColumn<std::string> name;
92 Gtk::TreeModelColumn<std::string> path;
93 Gtk::TreeModelColumn<std::string> description;
96 Glib::RefPtr<Gtk::ListStore> _template_model;
97 SessionTemplateColumns _template_columns;
99 Gtk::TreeModel::const_iterator _current_selection;
101 Gtk::ProgressBar _progress_bar;
102 std::string _current_action;
105 void render_template_names (Gtk::CellRenderer* rnd, const Gtk::TreeModel::iterator& it);
106 void validate_edit (const Glib::ustring& path_string, const Glib::ustring& new_name);
109 void set_desc_dirty ();
111 bool key_event (GdkEventKey* ev);
113 virtual void get_templates (vector<TemplateInfo>& templates) const = 0;
115 virtual void rename_template (Gtk::TreeModel::iterator& item, const Glib::ustring& new_name) = 0;
117 virtual void save_template_desc ();
119 void export_all_templates ();
120 void import_template_set ();
122 virtual std::string templates_dir () const = 0;
123 virtual std::string template_file (const Gtk::TreeModel::const_iterator& item) const = 0;
125 virtual bool adjust_xml_tree (XMLTree& tree, const std::string& old_name, const std::string& new_name) const = 0;
127 Gtk::TreeView _template_treeview;
128 Gtk::CellRendererText _validating_cellrenderer;
129 Gtk::TreeView::Column _validated_column;
133 Gtk::Button _remove_button;
134 Gtk::Button _rename_button;
136 Gtk::Button _export_all_templates_button;
137 Gtk::Button _import_template_set_button;
139 sigc::connection _cursor_changed_connection;
141 void update_progress_gui (float p);
144 class SessionTemplateManager : public TemplateManager
147 SessionTemplateManager () : TemplateManager () {}
148 ~SessionTemplateManager () {}
152 void get_templates (vector<TemplateInfo>& templates) const;
155 void rename_template (Gtk::TreeModel::iterator& item, const Glib::ustring& new_name);
156 void delete_selected_template ();
158 std::string templates_dir () const;
159 std::string template_file (const Gtk::TreeModel::const_iterator& item) const;
161 bool adjust_xml_tree (XMLTree& tree, const std::string& old_name, const std::string& new_name) const;
165 class RouteTemplateManager : public TemplateManager
168 RouteTemplateManager () : TemplateManager () {}
169 ~RouteTemplateManager () {}
173 void get_templates (vector<TemplateInfo>& templates) const;
176 void rename_template (Gtk::TreeModel::iterator& item, const Glib::ustring& new_name);
177 void delete_selected_template ();
179 std::string templates_dir () const;
180 std::string template_file (const Gtk::TreeModel::const_iterator& item) const;
182 bool adjust_xml_tree (XMLTree& tree, const std::string& old_name, const std::string& new_name) const;
187 TemplateDialog::TemplateDialog ()
188 : ArdourDialog ("Manage Templates")
190 Notebook* nb = manage (new Notebook);
192 SessionTemplateManager* session_tm = manage (new SessionTemplateManager);
193 nb->append_page (*session_tm, _("Session Templates"));
195 RouteTemplateManager* route_tm = manage (new RouteTemplateManager);
196 nb->append_page (*route_tm, _("Track Templates"));
198 get_vbox()->pack_start (*nb);
199 add_button (_("Done"), Gtk::RESPONSE_OK);
201 get_vbox()->show_all();
206 session_tm->TemplatesImported.connect (*this, invalidator (*this), boost::bind (&RouteTemplateManager::init, route_tm), gui_context ());
207 route_tm->TemplatesImported.connect (*this, invalidator (*this), boost::bind (&SessionTemplateManager::init, session_tm), gui_context ());
209 signal_hide().connect (sigc::mem_fun (session_tm, &TemplateManager::handle_dirty_description));
210 signal_hide().connect (sigc::mem_fun (route_tm, &TemplateManager::handle_dirty_description));
211 nb->signal_switch_page().connect (sigc::hide (sigc::hide (sigc::mem_fun (session_tm, &TemplateManager::handle_dirty_description))));
212 nb->signal_switch_page().connect (sigc::hide (sigc::hide (sigc::mem_fun (route_tm, &TemplateManager::handle_dirty_description))));
215 TemplateManager::TemplateManager ()
217 , ProgressReporter ()
218 , _save_desc (_("Save Description"))
219 , _desc_dirty (false)
220 , _remove_button (_("Remove"))
221 , _rename_button (_("Rename"))
222 , _export_all_templates_button (_("Export all"))
223 , _import_template_set_button (_("Import"))
225 _template_model = ListStore::create (_template_columns);
226 _template_treeview.set_model (_template_model);
228 _validated_column.set_title (_("Template Name"));
229 _validated_column.pack_start (_validating_cellrenderer);
230 _template_treeview.append_column (_validated_column);
231 _validating_cellrenderer.property_editable() = true;
233 _validated_column.set_cell_data_func (_validating_cellrenderer, sigc::mem_fun (*this, &TemplateManager::render_template_names));
234 _validating_cellrenderer.signal_edited().connect (sigc::mem_fun (*this, &TemplateManager::validate_edit));
235 _cursor_changed_connection = _template_treeview.signal_cursor_changed().connect (sigc::mem_fun (*this, &TemplateManager::row_selection_changed));
236 _template_treeview.signal_key_press_event().connect (sigc::mem_fun (*this, &TemplateManager::key_event));
238 ScrolledWindow* sw = manage (new ScrolledWindow);
239 sw->property_hscrollbar_policy() = POLICY_AUTOMATIC;
240 sw->add (_template_treeview);
241 sw->set_size_request (300, 200);
243 VBox* vb_btns = manage (new VBox);
244 vb_btns->set_spacing (4);
245 vb_btns->pack_start (_rename_button, false, false);
246 vb_btns->pack_start (_remove_button, false, false);
247 vb_btns->pack_start (_save_desc, false, false);
249 _rename_button.set_sensitive (false);
250 _rename_button.signal_clicked().connect (sigc::mem_fun (*this, &TemplateManager::start_edit));
251 _remove_button.set_sensitive (false);
252 _remove_button.signal_clicked().connect (sigc::mem_fun (*this, &TemplateManager::delete_selected_template));
254 vb_btns->pack_start (*(manage (new VSeparator ())));
256 vb_btns->pack_start (_export_all_templates_button, false, false);
257 vb_btns->pack_start (_import_template_set_button, false, false);
259 _export_all_templates_button.set_sensitive (false);
260 _export_all_templates_button.signal_clicked().connect (sigc::mem_fun (*this, &TemplateManager::export_all_templates));
262 _import_template_set_button.set_sensitive (true);
263 _import_template_set_button.signal_clicked().connect (sigc::mem_fun (*this, &TemplateManager::import_template_set));
267 VBox* vb = manage (new VBox);
268 vb->pack_start (*sw);
269 vb->pack_start (_progress_bar);
271 Frame* desc_frame = manage (new Frame (_("Description")));
273 _description_editor.set_wrap_mode (Gtk::WRAP_WORD);
274 _description_editor.set_size_request (300,400);
275 _description_editor.set_border_width (6);
277 _save_desc.set_sensitive (false);
278 _save_desc.signal_clicked().connect (sigc::mem_fun (*this, &TemplateManager::save_template_desc));
280 _description_editor.get_buffer()->signal_changed().connect (sigc::mem_fun (*this, &TemplateManager::set_desc_dirty));
282 desc_frame->add (_description_editor);
285 pack_start (*desc_frame);
286 pack_start (*vb_btns);
288 show_all_children ();
289 _progress_bar.hide ();
293 TemplateManager::setup_model (const vector<TemplateInfo>& templates)
295 _template_model->clear ();
297 for (vector<TemplateInfo>::const_iterator it = templates.begin(); it != templates.end(); ++it) {
299 row = *(_template_model->append ());
301 row[_template_columns.name] = it->name;
302 row[_template_columns.path] = it->path;
303 row[_template_columns.description] = it->description;
306 _export_all_templates_button.set_sensitive (!templates.empty ());
310 TemplateManager::handle_dirty_description ()
312 if (_desc_dirty && _current_selection) {
313 ArdourDialog dlg (_("Description not saved"), true);
314 const string name = _current_selection->get_value (_template_columns.name);
315 Label msg (string_compose (_("The discription of template \"%1\" has been modfied but has not been saved yet.\n"
316 "Do you want to save it?"), name));
317 dlg.get_vbox()->pack_start (msg);
319 dlg.add_button (_("Save"), RESPONSE_ACCEPT);
320 dlg.add_button (_("Discard"), RESPONSE_REJECT);
321 dlg.set_default_response (RESPONSE_REJECT);
323 int response = dlg.run ();
325 if (response == RESPONSE_ACCEPT) {
326 save_template_desc ();
328 _description_editor.get_buffer()->set_text (_current_selection->get_value (_template_columns.description));
334 TemplateManager::row_selection_changed ()
336 if (_current_selection) {
337 handle_dirty_description ();
339 _description_editor.get_buffer()->set_text ("");
342 _current_selection = _template_treeview.get_selection()->get_selected ();
343 if (_current_selection) {
344 const string desc = _current_selection->get_value (_template_columns.description);
345 _description_editor.get_buffer()->set_text (desc);
349 _save_desc.set_sensitive (false);
351 _description_editor.set_sensitive (_current_selection);
352 _rename_button.set_sensitive (_current_selection);
353 _remove_button.set_sensitive (_current_selection);
357 TemplateManager::render_template_names (Gtk::CellRenderer*, const Gtk::TreeModel::iterator& it)
360 _validating_cellrenderer.property_text () = it->get_value (_template_columns.name);
365 TemplateManager::validate_edit (const Glib::ustring& path_string, const Glib::ustring& new_name)
367 const TreePath path (path_string);
368 TreeModel::iterator current = _template_model->get_iter (path);
370 if (current->get_value (_template_columns.name) == new_name) {
374 TreeModel::Children rows = _template_model->children ();
377 for (TreeModel::Children::const_iterator it = rows.begin(); it != rows.end(); ++it) {
378 if (it->get_value (_template_columns.name) == new_name) {
385 error << string_compose (_("Template of name \"%1\" already exists"), new_name) << endmsg;
390 rename_template (current, new_name);
394 TemplateManager::start_edit ()
396 TreeModel::Path path;
398 _template_treeview.get_cursor (path, col);
399 _cursor_changed_connection.block ();
400 _template_treeview.set_cursor (path, *col, /*set_editing =*/ true);
401 _cursor_changed_connection.unblock ();
405 TemplateManager::set_desc_dirty ()
408 _save_desc.set_sensitive (true);
412 TemplateManager::save_template_desc ()
414 const string file_path = template_file (_current_selection);
416 string desc_txt = _description_editor.get_buffer()->get_text ();
417 string::reverse_iterator wss = desc_txt.rbegin();
418 while (wss != desc_txt.rend() && isspace (*wss)) {
419 desc_txt.erase (--(wss++).base());
422 _current_selection->set_value (_template_columns.description, desc_txt);
426 if (!tree.read(file_path)) {
427 error << string_compose (_("Could not parse template file \"%1\"."), file_path) << endmsg;
431 tree.root()->remove_nodes_and_delete (X_("description"));
433 if (!desc_txt.empty ()) {
434 XMLNode* desc = new XMLNode (X_("description"));
435 XMLNode* dn = new XMLNode (X_("content"), desc_txt);
436 desc->add_child_nocopy (*dn);
439 tree.root()->add_child_nocopy (*desc);
441 if (!tree.write ()) {
442 error << string_compose(X_("Could not write to template file \"%1\"."), file_path) << endmsg;
446 _save_desc.set_sensitive (false);
451 TemplateManager::key_event (GdkEventKey* ev)
453 if (ev->keyval == GDK_KEY_F2) {
457 if (ev->keyval == GDK_KEY_Delete) {
458 delete_selected_template ();
466 accept_all_files (string const &, void *)
472 _set_progress (Progress* p, size_t n, size_t t)
474 p->set_progress (float (n) / float(t));
479 TemplateManager::export_all_templates ()
482 char* td = g_dir_make_tmp ("ardour-templates-XXXXXX", &err);
485 error << string_compose(_("Could not make tmpdir: %1"), err->message) << endmsg;
488 const string tmpdir (td);
490 g_clear_error (&err);
492 FileChooserDialog dialog(_("Save Exported Template Archive"), FILE_CHOOSER_ACTION_SAVE);
493 dialog.set_filename (X_("templates.tar.xz"));
495 dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
496 dialog.add_button(Gtk::Stock::OK, Gtk::RESPONSE_OK);
498 FileFilter archive_filter;
499 archive_filter.add_pattern (X_("*.tar.xz"));
500 archive_filter.set_name (_("Template archives"));
501 dialog.add_filter (archive_filter);
503 int result = dialog.run ();
505 if (result != RESPONSE_OK || !dialog.get_filename().length()) {
506 PBD::remove_directory (tmpdir);
510 string filename = dialog.get_filename ();
511 if (filename.compare (filename.size () - 7, 7, ".tar.xz")) {
512 filename += ".tar.xz";
515 if (g_file_test (filename.c_str(), G_FILE_TEST_EXISTS)) {
516 ArdourDialog dlg (_("File exists"), true);
517 Label msg (string_compose (_("The file %1 already exists."), filename));
518 dlg.get_vbox()->pack_start (msg);
520 dlg.add_button (_("Overwrite"), RESPONSE_ACCEPT);
521 dlg.add_button (_("Cancel"), RESPONSE_REJECT);
522 dlg.set_default_response (RESPONSE_REJECT);
526 if (result == RESPONSE_REJECT) {
527 PBD::remove_directory (tmpdir);
532 PBD::copy_recurse (templates_dir (), Glib::build_filename (tmpdir, Glib::path_get_basename (templates_dir ())));
534 vector<string> files;
535 PBD::find_files_matching_regex (files, tmpdir, string ("\\.template$"), /* recurse = */ true);
537 vector<string>::const_iterator it;
538 for (it = files.begin(); it != files.end(); ++it) {
539 const string bn = PBD::basename_nosuffix (*it);
540 const string old_path = Glib::build_filename (templates_dir (), bn);
541 const string new_path = Glib::build_filename ("$TEMPLATEDIR", bn);
544 if (!tree.read (*it)) {
547 if (adjust_xml_tree (tree, old_path, new_path)) {
552 find_files_matching_filter (files, tmpdir, accept_all_files, 0, false, true, true);
554 std::map<std::string, std::string> filemap;
555 for (it = files.begin(); it != files.end(); ++it) {
556 filemap[*it] = it->substr (tmpdir.size()+1, it->size() - tmpdir.size() - 1);
559 _current_action = _("Exporting templates");
561 PBD::FileArchive ar (filename);
562 PBD::ScopedConnectionList progress_connection;
563 ar.progress.connect_same_thread (progress_connection, boost::bind (&_set_progress, this, _1, _2));
566 PBD::remove_directory (tmpdir);
570 TemplateManager::import_template_set ()
572 FileChooserDialog dialog (_("Import template archives"));
573 dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
574 dialog.add_button(Gtk::Stock::OK, Gtk::RESPONSE_OK);
576 FileFilter archive_filter;
577 archive_filter.add_pattern (X_("*.tar.xz"));
578 archive_filter.set_name (_("Template archives"));
579 dialog.add_filter (archive_filter);
581 int result = dialog.run ();
583 if (result != RESPONSE_OK || !dialog.get_filename().length()) {
587 _current_action = _("Importing templates");
589 FileArchive ar (dialog.get_filename ());
590 PBD::ScopedConnectionList progress_connection;
591 ar.progress.connect_same_thread (progress_connection, boost::bind (&_set_progress, this, _1, _2));
592 ar.inflate (user_config_directory ());
594 vector<string> files;
595 PBD::find_files_matching_regex (files, templates_dir (), string ("\\.template$"), /* recurse = */ true);
597 vector<string>::const_iterator it;
598 for (it = files.begin(); it != files.end(); ++it) {
599 const string bn = PBD::basename_nosuffix (*it);
600 const string old_path = Glib::build_filename ("$TEMPLATEDIR", bn);
601 const string new_path = Glib::build_filename (templates_dir (), bn);
604 if (!tree.read (*it)) {
607 if (adjust_xml_tree (tree, old_path, new_path)) {
613 TemplatesImported (); /* emit signal */
617 TemplateManager::adjust_plugin_paths (XMLNode* node, const string& name, const string& new_name) const
619 bool adjusted = false;
621 const XMLNodeList& procs = node->children (X_("Processor"));
622 XMLNodeConstIterator pit;
623 for (pit = procs.begin(); pit != procs.end(); ++pit) {
624 XMLNode* lv2_node = (*pit)->child (X_("lv2"));
630 if (!lv2_node->get_property (X_("template-dir"), template_dir)) {
634 const int suffix_pos = template_dir.size() - name.size();
635 if (suffix_pos < 0) {
636 cerr << "Template name\"" << name << "\" longer than template-dir \"" << template_dir << "\", WTH?" << endl;
640 if (template_dir.compare (suffix_pos, template_dir.size(), name)) {
641 cerr << "Template name \"" << name << "\" no suffix of template-dir \"" << template_dir << "\"" << endl;
645 const string new_template_dir = template_dir.substr (0, suffix_pos) + new_name;
646 lv2_node->set_property (X_("template-dir"), new_template_dir);
655 TemplateManager::update_progress_gui (float p)
658 _progress_bar.hide ();
662 _progress_bar.show ();
663 _progress_bar.set_text (_current_action);
664 _progress_bar.set_fraction (p);
668 SessionTemplateManager::init ()
670 vector<TemplateInfo> templates;
671 get_templates (templates);
672 setup_model (templates);
674 _progress_bar.hide ();
675 _description_editor.set_sensitive (false);
676 _save_desc.set_sensitive (false);
680 RouteTemplateManager::init ()
682 vector<TemplateInfo> templates;
683 get_templates (templates);
684 setup_model (templates);
686 _progress_bar.hide ();
687 _description_editor.set_sensitive (false);
688 _save_desc.set_sensitive (false);
692 SessionTemplateManager::get_templates (vector<TemplateInfo>& templates) const
694 find_session_templates (templates, /* read_xml = */ true);
698 RouteTemplateManager::get_templates (vector<TemplateInfo>& templates) const
700 find_route_templates (templates);
706 SessionTemplateManager::rename_template (TreeModel::iterator& item, const Glib::ustring& new_name_)
708 const string old_path = item->get_value (_template_columns.path);
709 const string old_name = item->get_value (_template_columns.name);
710 const string new_name = string (new_name_);
712 const string old_file_old_path = Glib::build_filename (old_path, old_name+".template");
716 if (!tree.read(old_file_old_path)) {
717 error << string_compose (_("Could not parse template file \"%1\"."), old_file_old_path) << endmsg;
720 XMLNode* root = tree.root();
722 const XMLNode* const routes_node = root->child (X_("Routes"));
724 const XMLNodeList& routes = routes_node->children (X_("Route"));
725 XMLNodeConstIterator rit;
726 for (rit = routes.begin(); rit != routes.end(); ++rit) {
727 adjust_plugin_paths (*rit, old_name, new_name);
731 const string new_file_old_path = Glib::build_filename (old_path, new_name+".template");
733 tree.set_filename (new_file_old_path);
735 if (!tree.write ()) {
736 error << string_compose(_("Could not write to new template file \"%1\"."), new_file_old_path);
740 const string new_path = Glib::build_filename (user_template_directory (), new_name);
742 if (g_rename (old_path.c_str(), new_path.c_str()) != 0) {
743 error << string_compose (_("Could not rename template directory from \"%1\" to \"%2\": %3"),
744 old_path, new_path, strerror (errno)) << endmsg;
745 g_unlink (new_file_old_path.c_str());
749 const string old_file_new_path = Glib::build_filename (new_path, old_name+".template");
750 if (g_unlink (old_file_new_path.c_str())) {
751 error << string_compose (X_("Could not delete old template file \"%1\": %2"),
752 old_file_new_path, strerror (errno)) << endmsg;
755 item->set_value (_template_columns.name, new_name);
756 item->set_value (_template_columns.path, new_path);
760 SessionTemplateManager::delete_selected_template ()
762 if (!_current_selection) {
766 PBD::remove_directory (_current_selection->get_value (_template_columns.path));
768 _template_model->erase (_current_selection);
769 _current_selection = TreeIter ();
770 row_selection_changed ();
774 SessionTemplateManager::templates_dir () const
776 return user_template_directory ();
781 SessionTemplateManager::template_file (const TreeModel::const_iterator& item) const
783 const string path = item->get_value (_template_columns.path);
784 const string name = item->get_value (_template_columns.name);
785 return Glib::build_filename (path, name+".template");
789 SessionTemplateManager::adjust_xml_tree (XMLTree& tree, const std::string& old_name, const std::string& new_name) const
791 bool adjusted = false;
792 XMLNode* root = tree.root();
794 const XMLNode* const routes_node = root->child (X_("Routes"));
796 const XMLNodeList& routes = routes_node->children (X_("Route"));
797 XMLNodeConstIterator rit;
798 for (rit = routes.begin(); rit != routes.end(); ++rit) {
799 if (adjust_plugin_paths (*rit, old_name, new_name)) {
810 RouteTemplateManager::rename_template (TreeModel::iterator& item, const Glib::ustring& new_name)
812 const string old_name = item->get_value (_template_columns.name);
813 const string old_filepath = item->get_value (_template_columns.path);
814 const string new_filepath = Glib::build_filename (user_route_template_directory(), new_name+".template");
817 if (!tree.read (old_filepath)) {
818 error << string_compose (_("Could not parse template file \"%1\"."), old_filepath) << endmsg;
821 tree.root()->set_property (X_("name"), new_name);
822 tree.root()->children().front()->set_property (X_("name"), new_name);
824 const bool adjusted = adjust_plugin_paths (tree.root(), old_name, string (new_name));
826 const string old_state_dir = Glib::build_filename (user_route_template_directory(), old_name);
827 const string new_state_dir = Glib::build_filename (user_route_template_directory(), new_name);
830 if (g_file_test (old_state_dir.c_str(), G_FILE_TEST_EXISTS)) {
831 if (g_rename (old_state_dir.c_str(), new_state_dir.c_str()) != 0) {
832 error << string_compose (_("Could not rename state dir \"%1\" to \"%22\": %3"), old_state_dir, new_state_dir, strerror (errno)) << endmsg;
838 tree.set_filename (new_filepath);
840 if (!tree.write ()) {
841 error << string_compose(_("Could not write new template file \"%1\"."), new_filepath) << endmsg;
843 g_rename (new_state_dir.c_str(), old_state_dir.c_str());
848 if (g_unlink (old_filepath.c_str()) != 0) {
849 error << string_compose (_("Could not remove old template file \"%1\": %2"), old_filepath, strerror (errno)) << endmsg;
852 item->set_value (_template_columns.name, string (new_name));
853 item->set_value (_template_columns.path, new_filepath);
857 RouteTemplateManager::delete_selected_template ()
859 if (!_current_selection) {
863 const string file_path = _current_selection->get_value (_template_columns.path);
865 if (g_unlink (file_path.c_str()) != 0) {
866 error << string_compose(_("Could not delete template file \"%1\": %2"), file_path, strerror (errno)) << endmsg;
869 PBD::remove_directory (Glib::build_filename (user_route_template_directory (),
870 _current_selection->get_value (_template_columns.name)));
872 _template_model->erase (_current_selection);
873 row_selection_changed ();
877 RouteTemplateManager::templates_dir () const
879 return user_route_template_directory ();
884 RouteTemplateManager::template_file (const TreeModel::const_iterator& item) const
886 return item->get_value (_template_columns.path);
890 RouteTemplateManager::adjust_xml_tree (XMLTree& tree, const std::string& old_name, const std::string& new_name) const
892 return adjust_plugin_paths (tree.root(), old_name, string (new_name));