mirror of
https://github.com/Ardour/ardour.git
synced 2025-12-06 23:05:04 +01:00
Ask user whether to save or discard unsaved template descriptions
This commit is contained in:
parent
bd4db1e151
commit
c834e88e9e
2 changed files with 55 additions and 34 deletions
|
|
@ -72,6 +72,11 @@ TemplateDialog::TemplateDialog ()
|
||||||
|
|
||||||
session_tm->TemplatesImported.connect (*this, invalidator (*this), boost::bind (&RouteTemplateManager::init, route_tm), gui_context ());
|
session_tm->TemplatesImported.connect (*this, invalidator (*this), boost::bind (&RouteTemplateManager::init, route_tm), gui_context ());
|
||||||
route_tm->TemplatesImported.connect (*this, invalidator (*this), boost::bind (&SessionTemplateManager::init, session_tm), gui_context ());
|
route_tm->TemplatesImported.connect (*this, invalidator (*this), boost::bind (&SessionTemplateManager::init, session_tm), gui_context ());
|
||||||
|
|
||||||
|
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));
|
||||||
}
|
}
|
||||||
|
|
||||||
TemplateManager::TemplateManager ()
|
TemplateManager::TemplateManager ()
|
||||||
|
|
@ -168,23 +173,47 @@ TemplateManager::setup_model (const vector<TemplateInfo>& templates)
|
||||||
_export_all_templates_button.set_sensitive (!templates.empty ());
|
_export_all_templates_button.set_sensitive (!templates.empty ());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
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"
|
||||||
|
"Do you want to save it?"), name));
|
||||||
|
dlg.get_vbox()->pack_start (msg);
|
||||||
|
msg.show ();
|
||||||
|
dlg.add_button (_("Save"), RESPONSE_ACCEPT);
|
||||||
|
dlg.add_button (_("Discard"), RESPONSE_REJECT);
|
||||||
|
dlg.set_default_response (RESPONSE_REJECT);
|
||||||
|
|
||||||
|
int response = dlg.run ();
|
||||||
|
|
||||||
|
if (response == RESPONSE_ACCEPT) {
|
||||||
|
save_template_desc ();
|
||||||
|
} else {
|
||||||
|
_description_editor.get_buffer()->set_text (_current_selection->get_value (_template_columns.description));
|
||||||
|
}
|
||||||
|
|
||||||
|
_desc_dirty = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
TemplateManager::row_selection_changed ()
|
TemplateManager::row_selection_changed ()
|
||||||
{
|
{
|
||||||
bool has_selection = false;
|
handle_dirty_description ();
|
||||||
if (_template_treeview.get_selection()->count_selected_rows () != 0) {
|
|
||||||
Gtk::TreeModel::const_iterator it = _template_treeview.get_selection()->get_selected ();
|
_current_selection = _template_treeview.get_selection()->get_selected ();
|
||||||
if (it) {
|
if (_current_selection) {
|
||||||
has_selection = true;
|
const string desc = _current_selection->get_value (_template_columns.description);
|
||||||
const string desc = it->get_value (_template_columns.description);
|
_description_editor.get_buffer()->set_text (desc);
|
||||||
_description_editor.get_buffer()->set_text (desc);
|
_desc_dirty = false;
|
||||||
_desc_dirty = false;
|
_save_desc.set_sensitive (false);
|
||||||
_save_desc.set_sensitive (false);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
_rename_button.set_sensitive (has_selection);
|
_rename_button.set_sensitive (_current_selection);
|
||||||
_remove_button.set_sensitive (has_selection);
|
_remove_button.set_sensitive (_current_selection);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
|
@ -243,11 +272,10 @@ TemplateManager::set_desc_dirty ()
|
||||||
void
|
void
|
||||||
TemplateManager::save_template_desc ()
|
TemplateManager::save_template_desc ()
|
||||||
{
|
{
|
||||||
const Gtk::TreeModel::const_iterator it = _template_treeview.get_selection()->get_selected ();
|
const string file_path = template_file (_current_selection);
|
||||||
const string file_path = template_file (it);
|
|
||||||
|
|
||||||
const string desc_txt = _description_editor.get_buffer()->get_text ();
|
const string desc_txt = _description_editor.get_buffer()->get_text ();
|
||||||
it->set_value (_template_columns.description, desc_txt);
|
_current_selection->set_value (_template_columns.description, desc_txt);
|
||||||
|
|
||||||
XMLTree tree;
|
XMLTree tree;
|
||||||
|
|
||||||
|
|
@ -567,19 +595,13 @@ SessionTemplateManager::rename_template (TreeModel::iterator& item, const Glib::
|
||||||
void
|
void
|
||||||
SessionTemplateManager::delete_selected_template ()
|
SessionTemplateManager::delete_selected_template ()
|
||||||
{
|
{
|
||||||
if (_template_treeview.get_selection()->count_selected_rows() == 0) {
|
if (!_current_selection) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Gtk::TreeModel::const_iterator it = _template_treeview.get_selection()->get_selected();
|
PBD::remove_directory (_current_selection->get_value (_template_columns.path));
|
||||||
|
|
||||||
if (!it) {
|
_template_model->erase (_current_selection);
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
PBD::remove_directory (it->get_value (_template_columns.path));
|
|
||||||
|
|
||||||
_template_model->erase (it);
|
|
||||||
row_selection_changed ();
|
row_selection_changed ();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -669,25 +691,20 @@ RouteTemplateManager::rename_template (TreeModel::iterator& item, const Glib::us
|
||||||
void
|
void
|
||||||
RouteTemplateManager::delete_selected_template ()
|
RouteTemplateManager::delete_selected_template ()
|
||||||
{
|
{
|
||||||
if (_template_treeview.get_selection()->count_selected_rows() == 0) {
|
if (!_current_selection) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Gtk::TreeModel::const_iterator it = _template_treeview.get_selection()->get_selected();
|
const string file_path = _current_selection->get_value (_template_columns.path);
|
||||||
|
|
||||||
if (!it) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const string file_path = it->get_value (_template_columns.path);
|
|
||||||
|
|
||||||
if (g_unlink (file_path.c_str()) != 0) {
|
if (g_unlink (file_path.c_str()) != 0) {
|
||||||
error << string_compose(_("Could not delete template file \"%1\": %2"), file_path, strerror (errno)) << endmsg;
|
error << string_compose(_("Could not delete template file \"%1\": %2"), file_path, strerror (errno)) << endmsg;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
PBD::remove_directory (Glib::build_filename (user_route_template_directory (), it->get_value (_template_columns.name)));
|
PBD::remove_directory (Glib::build_filename (user_route_template_directory (),
|
||||||
|
_current_selection->get_value (_template_columns.name)));
|
||||||
|
|
||||||
_template_model->erase (it);
|
_template_model->erase (_current_selection);
|
||||||
row_selection_changed ();
|
row_selection_changed ();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -49,6 +49,7 @@ public:
|
||||||
class TemplateManager : public Gtk::HBox,
|
class TemplateManager : public Gtk::HBox,
|
||||||
public ProgressReporter
|
public ProgressReporter
|
||||||
{
|
{
|
||||||
|
friend class TemplateDialog;
|
||||||
public:
|
public:
|
||||||
virtual ~TemplateManager () {}
|
virtual ~TemplateManager () {}
|
||||||
virtual void init () = 0;
|
virtual void init () = 0;
|
||||||
|
|
@ -72,6 +73,7 @@ protected:
|
||||||
virtual void rename_template (Gtk::TreeModel::iterator& item, const Glib::ustring& new_name) = 0;
|
virtual void rename_template (Gtk::TreeModel::iterator& item, const Glib::ustring& new_name) = 0;
|
||||||
virtual void delete_selected_template () = 0;
|
virtual void delete_selected_template () = 0;
|
||||||
|
|
||||||
|
void handle_dirty_description ();
|
||||||
virtual void save_template_desc ();
|
virtual void save_template_desc ();
|
||||||
|
|
||||||
void export_all_templates ();
|
void export_all_templates ();
|
||||||
|
|
@ -99,6 +101,8 @@ protected:
|
||||||
SessionTemplateColumns _template_columns;
|
SessionTemplateColumns _template_columns;
|
||||||
Glib::RefPtr<Gtk::ListStore> _template_model;
|
Glib::RefPtr<Gtk::ListStore> _template_model;
|
||||||
|
|
||||||
|
Gtk::TreeModel::const_iterator _current_selection;
|
||||||
|
|
||||||
Gtk::TreeView _template_treeview;
|
Gtk::TreeView _template_treeview;
|
||||||
Gtk::CellRendererText _validating_cellrenderer;
|
Gtk::CellRendererText _validating_cellrenderer;
|
||||||
Gtk::TreeView::Column _validated_column;
|
Gtk::TreeView::Column _validated_column;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue