Add dialog to allow removal of plugin presets. Should fix #2662.
[ardour.git] / gtk2_ardour / edit_plugin_presets_dialog.cc
1 /*
2     Copyright (C) 2010 Paul Davis
3     Author: Carl Hetherington <cth@carlh.net>
4
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.
9
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.
14
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.
18
19 */
20
21 #include <gtkmm/stock.h>
22 #include <gtkmm/listviewtext.h>
23 #include "gtkmm2ext/gui_thread.h"
24 #include "ardour/plugin.h"
25 #include "edit_plugin_presets_dialog.h"
26
27 using namespace std;
28 using namespace Gtk;
29
30 EditPluginPresetsDialog::EditPluginPresetsDialog (boost::shared_ptr<ARDOUR::Plugin> plugin)
31         : ArdourDialog (_("Edit Presets"))
32         , _plugin (plugin)
33         , _list (1, false, SELECTION_MULTIPLE)
34         , _delete (_("Delete"))
35 {
36         _list.set_headers_visible (false);
37
38         setup_list ();
39
40         HBox* hbox = manage (new HBox);
41         hbox->set_spacing (6);
42         hbox->pack_start (_list);
43
44         VBox* vbox = manage (new VBox);
45         vbox->pack_start (_delete, false, false);
46
47         hbox->pack_start (*vbox, false, false);
48
49         get_vbox()->pack_start (*hbox);
50
51         add_button (Stock::CLOSE, RESPONSE_ACCEPT);
52
53         set_size_request (250, 300);
54         update_sensitivity ();
55         
56         show_all ();
57
58         _list.get_selection()->signal_changed().connect (sigc::mem_fun (*this, &EditPluginPresetsDialog::update_sensitivity));
59         _delete.signal_clicked().connect (sigc::mem_fun (*this, &EditPluginPresetsDialog::delete_presets));
60
61         _plugin->PresetAdded.connect (_preset_added_connection, invalidator (*this), boost::bind (&EditPluginPresetsDialog::setup_list, this), gui_context ());
62         _plugin->PresetRemoved.connect (_preset_removed_connection, invalidator (*this), boost::bind (&EditPluginPresetsDialog::setup_list, this), gui_context ());
63 }
64
65 void
66 EditPluginPresetsDialog::update_sensitivity ()
67 {
68         _delete.set_sensitive (!_list.get_selected().empty());
69 }
70
71 void
72 EditPluginPresetsDialog::delete_presets ()
73 {
74         ListViewText::SelectionList const s = _list.get_selected ();
75         for (ListViewText::SelectionList::const_iterator i = s.begin(); i != s.end(); ++i) {
76                 _plugin->remove_preset (_list.get_text (*i));
77         }
78
79         setup_list ();
80 }
81
82 void
83 EditPluginPresetsDialog::setup_list ()
84 {
85         _list.clear_items ();
86         
87         vector<ARDOUR::Plugin::PresetRecord> presets = _plugin->get_presets ();
88         for (vector<ARDOUR::Plugin::PresetRecord>::const_iterator i = presets.begin(); i != presets.end(); ++i) {
89                 _list.append_text (i->label);
90         }
91 }