update drobilla's fascistic dir-locals.el to force emacs users into whitespace submis...
[ardour.git] / gtk2_ardour / new_plugin_preset_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 "new_plugin_preset_dialog.h"
23
24 using namespace std;
25 using namespace Gtk;
26
27 NewPluginPresetDialog::NewPluginPresetDialog (boost::shared_ptr<ARDOUR::Plugin> p)
28         : ArdourDialog (_("New Preset"))
29         , _replace (_("Replace existing preset with this name"))
30 {
31         HBox* h = manage (new HBox);
32         h->set_spacing (6);
33         h->pack_start (*manage (new Label (_("Name of new preset"))));
34         h->pack_start (_name);
35
36         get_vbox()->set_spacing (6);
37         get_vbox()->pack_start (*h);
38
39         get_vbox()->pack_start (_replace);
40
41         add_button (Stock::CANCEL, RESPONSE_CANCEL);
42         _add = add_button (Stock::ADD, RESPONSE_ACCEPT);
43
44         show_all ();
45
46         _presets = p->get_presets ();
47
48         _name.signal_changed().connect (sigc::mem_fun (*this, &NewPluginPresetDialog::setup_sensitivity));
49         _replace.signal_toggled().connect (sigc::mem_fun (*this, &NewPluginPresetDialog::setup_sensitivity));
50
51         setup_sensitivity ();
52 }
53
54 void
55 NewPluginPresetDialog::setup_sensitivity ()
56 {
57         if (_name.get_text().empty()) {
58                 _replace.set_sensitive (false);
59                 _add->set_sensitive (false);
60                 return;
61         }
62                 
63         vector<ARDOUR::Plugin::PresetRecord>::const_iterator i = _presets.begin ();
64         while (i != _presets.end() && i->label != _name.get_text()) {
65                 ++i;
66         }
67
68         if (i != _presets.end ()) {
69                 _replace.set_sensitive (true);
70                 _add->set_sensitive (_replace.get_active ());
71         } else {
72                 _replace.set_sensitive (false);
73                 _add->set_sensitive (true);
74         }
75 }
76
77 string
78 NewPluginPresetDialog::name () const
79 {
80         return _name.get_text ();
81 }
82
83 bool
84 NewPluginPresetDialog::replace () const
85 {
86         return _replace.get_active ();
87 }
88