1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
|
/*
Copyright (C) 2010 Paul Davis
Author: Carl Hetherington <cth@carlh.net>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include <gtkmm/stock.h>
#include <gtkmm/listviewtext.h>
#include <gtkmm/scrolledwindow.h>
#include "gtkmm2ext/gui_thread.h"
#include "ardour/plugin.h"
#include "edit_plugin_presets_dialog.h"
using namespace std;
using namespace Gtk;
EditPluginPresetsDialog::EditPluginPresetsDialog (boost::shared_ptr<ARDOUR::Plugin> plugin)
: ArdourDialog (_("Edit Presets"))
, _plugin (plugin)
, _list (1, false, SELECTION_MULTIPLE)
, _delete (_("Delete"))
{
_list.set_headers_visible (false);
setup_list ();
HBox* hbox = manage (new HBox);
hbox->set_spacing (6);
ScrolledWindow* scr = manage (new ScrolledWindow);
scr->add (_list);
hbox->pack_start (*scr);
VBox* vbox = manage (new VBox);
vbox->pack_start (_delete, false, false);
hbox->pack_start (*vbox, false, false);
get_vbox()->pack_start (*hbox);
add_button (Stock::CLOSE, RESPONSE_ACCEPT);
set_size_request (250, 300);
update_sensitivity ();
show_all ();
_list.get_selection()->signal_changed().connect (sigc::mem_fun (*this, &EditPluginPresetsDialog::update_sensitivity));
_delete.signal_clicked().connect (sigc::mem_fun (*this, &EditPluginPresetsDialog::delete_presets));
_plugin->PresetAdded.connect (_preset_added_connection, invalidator (*this), boost::bind (&EditPluginPresetsDialog::setup_list, this), gui_context ());
_plugin->PresetRemoved.connect (_preset_removed_connection, invalidator (*this), boost::bind (&EditPluginPresetsDialog::setup_list, this), gui_context ());
}
void
EditPluginPresetsDialog::update_sensitivity ()
{
ListViewText::SelectionList s = _list.get_selected ();
ListViewText::SelectionList::const_iterator i = s.begin();
while (i != s.end()) {
if (*i >= _plugin->first_user_preset_index()) {
break;
}
++i;
}
_delete.set_sensitive (i != s.end ());
}
void
EditPluginPresetsDialog::delete_presets ()
{
ListViewText::SelectionList const s = _list.get_selected ();
for (ListViewText::SelectionList::const_iterator i = s.begin(); i != s.end(); ++i) {
_plugin->remove_preset (_list.get_text (*i));
}
}
void
EditPluginPresetsDialog::setup_list ()
{
_list.clear_items ();
vector<ARDOUR::Plugin::PresetRecord> presets = _plugin->get_presets ();
for (vector<ARDOUR::Plugin::PresetRecord>::const_iterator i = presets.begin(); i != presets.end(); ++i) {
_list.append_text (i->label);
}
update_sensitivity ();
}
|