X-Git-Url: https://git.carlh.net/gitweb/?a=blobdiff_plain;f=gtk2_ardour%2Ftemplate_dialog.cc;h=e250791b62b6550e9c0861e632d740bcdfafd832;hb=65bda27d4218d9d4ebf809d91e716c892e1f1d8b;hp=756c4b6a3f58ed79b740bea57a51d91c457e60f3;hpb=c6ecd2a6e16fddc87d244075ed3fb6b964f28041;p=ardour.git diff --git a/gtk2_ardour/template_dialog.cc b/gtk2_ardour/template_dialog.cc index 756c4b6a3f..e250791b62 100644 --- a/gtk2_ardour/template_dialog.cc +++ b/gtk2_ardour/template_dialog.cc @@ -45,6 +45,7 @@ #include "gtkmm2ext/gui_thread.h" +#include "ardour/filename_extensions.h" #include "ardour/filesystem_paths.h" #include "ardour/template_utils.h" @@ -63,7 +64,7 @@ class TemplateManager : public Gtk::HBox, public: virtual ~TemplateManager () {} - void init (); + virtual void init () = 0; void handle_dirty_description (); PBD::Signal0 TemplatesImported; @@ -71,6 +72,9 @@ public: protected: TemplateManager (); + Gtk::TextView _description_editor; + Gtk::Button _save_desc; + void setup_model (const std::vector& templates); void row_selection_changed (); @@ -125,8 +129,6 @@ private: Gtk::CellRendererText _validating_cellrenderer; Gtk::TreeView::Column _validated_column; - Gtk::TextView _description_editor; - Gtk::Button _save_desc; bool _desc_dirty; Gtk::Button _remove_button; @@ -146,6 +148,8 @@ public: SessionTemplateManager () : TemplateManager () {} ~SessionTemplateManager () {} + void init (); + void get_templates (vector& templates) const; private: @@ -165,6 +169,8 @@ public: RouteTemplateManager () : TemplateManager () {} ~RouteTemplateManager () {} + void init (); + void get_templates (vector& templates) const; private: @@ -191,7 +197,7 @@ TemplateDialog::TemplateDialog () nb->append_page (*route_tm, _("Track Templates")); get_vbox()->pack_start (*nb); - add_button (_("Ok"), Gtk::RESPONSE_OK); + add_button (_("Done"), Gtk::RESPONSE_OK); get_vbox()->show_all(); @@ -203,8 +209,8 @@ TemplateDialog::TemplateDialog () signal_hide().connect (sigc::mem_fun (session_tm, &TemplateManager::handle_dirty_description)); signal_hide().connect (sigc::mem_fun (route_tm, &TemplateManager::handle_dirty_description)); - nb->signal_switch_page().connect (boost::bind (&TemplateManager::handle_dirty_description, session_tm)); - nb->signal_switch_page().connect (boost::bind (&TemplateManager::handle_dirty_description, route_tm)); + nb->signal_switch_page().connect (sigc::hide (sigc::hide (sigc::mem_fun (session_tm, &TemplateManager::handle_dirty_description)))); + nb->signal_switch_page().connect (sigc::hide (sigc::hide (sigc::mem_fun (route_tm, &TemplateManager::handle_dirty_description)))); } TemplateManager::TemplateManager () @@ -284,18 +290,6 @@ TemplateManager::TemplateManager () _progress_bar.hide (); } -void -TemplateManager::init () -{ - vector templates; - get_templates (templates); - setup_model (templates); - - _progress_bar.hide (); - _description_editor.set_sensitive (false); - _save_desc.set_sensitive (false); -} - void TemplateManager::setup_model (const vector& templates) { @@ -319,7 +313,7 @@ TemplateManager::handle_dirty_description () if (_desc_dirty && _current_selection) { ArdourDialog dlg (_("Description not saved"), true); const string name = _current_selection->get_value (_template_columns.name); - Label msg (string_compose (_("The discription of template \"%1\" has been modfied but has not been saved yet.\n" + Label msg (string_compose (_("The description of template \"%1\" has been modified but has not been saved yet.\n" "Do you want to save it?"), name)); dlg.get_vbox()->pack_start (msg); msg.show (); @@ -420,7 +414,12 @@ TemplateManager::save_template_desc () { const string file_path = template_file (_current_selection); - const string desc_txt = _description_editor.get_buffer()->get_text (); + string desc_txt = _description_editor.get_buffer()->get_text (); + string::reverse_iterator wss = desc_txt.rbegin(); + while (wss != desc_txt.rend() && isspace (*wss)) { + desc_txt.erase (--(wss++).base()); + } + _current_selection->set_value (_template_columns.description, desc_txt); XMLTree tree; @@ -430,13 +429,14 @@ TemplateManager::save_template_desc () return; } - tree.root()->remove_nodes (X_("description")); - XMLNode* desc = new XMLNode (X_("description")); + tree.root()->remove_nodes_and_delete (X_("description")); - XMLNode* dn = new XMLNode (X_("content"), desc_txt); - desc->add_child_nocopy (*dn); - - tree.root()->add_child_nocopy (*desc); + if (!desc_txt.empty ()) { + XMLNode* desc = new XMLNode (X_("description")); + XMLNode* dn = new XMLNode (X_("content"), desc_txt); + desc->add_child_nocopy (*dn); + tree.root()->add_child_nocopy (*desc); + } if (!tree.write ()) { error << string_compose(X_("Could not write to template file \"%1\"."), file_path) << endmsg; @@ -462,13 +462,14 @@ TemplateManager::key_event (GdkEventKey* ev) return false; } -static -bool accept_all_files (string const &, void *) +static bool +accept_all_files (string const &, void *) { return true; } -static void _set_progress (Progress* p, size_t n, size_t t) +static void +_set_progress (Progress* p, size_t n, size_t t) { p->set_progress (float (n) / float(t)); } @@ -489,13 +490,13 @@ TemplateManager::export_all_templates () g_clear_error (&err); FileChooserDialog dialog(_("Save Exported Template Archive"), FILE_CHOOSER_ACTION_SAVE); - dialog.set_filename (X_("templates.tar.xz")); + dialog.set_filename (X_("templates")); dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL); dialog.add_button(Gtk::Stock::OK, Gtk::RESPONSE_OK); FileFilter archive_filter; - archive_filter.add_pattern (X_("*.tar.xz")); + archive_filter.add_pattern (string_compose(X_("*%1"), ARDOUR::template_archive_suffix)); archive_filter.set_name (_("Template archives")); dialog.add_filter (archive_filter); @@ -507,9 +508,7 @@ TemplateManager::export_all_templates () } string filename = dialog.get_filename (); - if (filename.compare (filename.size () - 7, 7, ".tar.xz")) { - filename += ".tar.xz"; - } + filename += ARDOUR::template_archive_suffix; if (g_file_test (filename.c_str(), G_FILE_TEST_EXISTS)) { ArdourDialog dlg (_("File exists"), true); @@ -573,7 +572,7 @@ TemplateManager::import_template_set () dialog.add_button(Gtk::Stock::OK, Gtk::RESPONSE_OK); FileFilter archive_filter; - archive_filter.add_pattern (X_("*.tar.xz")); + archive_filter.add_pattern (string_compose(X_("*%1"), ARDOUR::template_archive_suffix)); archive_filter.set_name (_("Template archives")); dialog.add_filter (archive_filter); @@ -663,13 +662,38 @@ TemplateManager::update_progress_gui (float p) _progress_bar.set_fraction (p); } +void +SessionTemplateManager::init () +{ + vector templates; + get_templates (templates); + setup_model (templates); + + _progress_bar.hide (); + _description_editor.set_sensitive (false); + _save_desc.set_sensitive (false); +} + +void +RouteTemplateManager::init () +{ + vector templates; + get_templates (templates); + setup_model (templates); + + _progress_bar.hide (); + _description_editor.set_sensitive (false); + _save_desc.set_sensitive (false); +} + void SessionTemplateManager::get_templates (vector& templates) const { find_session_templates (templates, /* read_xml = */ true); } -void RouteTemplateManager::get_templates (vector& templates) const +void +RouteTemplateManager::get_templates (vector& templates) const { find_route_templates (templates); } @@ -683,6 +707,10 @@ SessionTemplateManager::rename_template (TreeModel::iterator& item, const Glib:: const string old_name = item->get_value (_template_columns.name); const string new_name = string (new_name_); + if (old_name == new_name) { + return; + } + const string old_file_old_path = Glib::build_filename (old_path, old_name+".template"); XMLTree tree; @@ -787,6 +815,10 @@ RouteTemplateManager::rename_template (TreeModel::iterator& item, const Glib::us const string old_filepath = item->get_value (_template_columns.path); const string new_filepath = Glib::build_filename (user_route_template_directory(), new_name+".template"); + if (old_name == new_name) { + return; + } + XMLTree tree; if (!tree.read (old_filepath)) { error << string_compose (_("Could not parse template file \"%1\"."), old_filepath) << endmsg;