2
Copyright (C) 2002 Paul Davis
4
This program is free software; you can redistribute it and/or modify
5
it under the terms of the GNU General Public License as published by
6
the Free Software Foundation; either version 2 of the License, or
7
(at your option) any later version.
9
This program is distributed in the hope that it will be useful,
10
but WITHOUT ANY WARRANTY; without even the implied warranty of
11
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
GNU General Public License for more details.
14
You should have received a copy of the GNU General Public License
15
along with this program; if not, write to the Free Software
16
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21
#include "gtk2ardour-config.h"
26
#include <gtkmm/stock.h>
27
#include <gtkmm/label.h>
28
#include <gtkmm/accelkey.h>
29
#include <gtkmm/accelmap.h>
30
#include <gtkmm/uimanager.h>
32
#include "gtkmm2ext/utils.h"
34
#include "pbd/strsplit.h"
36
#include "ardour/profile.h"
40
#include "keyeditor.h"
50
using Gtkmm2ext::Keyboard;
52
KeyEditor::KeyEditor ()
53
: ArdourWindow (_("Key Bindings"))
54
, unbind_button (_("Remove shortcut"))
55
, unbind_box (BUTTONBOX_END)
61
model = TreeStore::create(columns);
63
view.set_model (model);
64
view.append_column (_("Action"), columns.action);
65
view.append_column (_("Shortcut"), columns.binding);
66
view.set_headers_visible (true);
67
view.get_selection()->set_mode (SELECTION_SINGLE);
68
view.set_reorderable (false);
69
view.set_size_request (500,300);
70
view.set_enable_search (false);
71
view.set_rules_hint (true);
72
view.set_name (X_("KeyEditorTree"));
74
view.get_selection()->signal_changed().connect (sigc::mem_fun (*this, &KeyEditor::action_selected));
77
scroller.set_policy (Gtk::POLICY_NEVER, Gtk::POLICY_AUTOMATIC);
81
vpacker.set_spacing (6);
82
vpacker.pack_start (scroller);
84
if (!ARDOUR::Profile->get_sae()) {
86
Label* hint = manage (new Label (_("Select an action, then press the key(s) to (re)set its shortcut")));
88
unbind_box.set_spacing (6);
89
unbind_box.pack_start (*hint, false, true);
90
unbind_box.pack_start (unbind_button, false, false);
91
unbind_button.signal_clicked().connect (sigc::mem_fun (*this, &KeyEditor::unbind));
93
vpacker.pack_start (unbind_box, false, false);
95
unbind_button.show ();
99
vpacker.set_border_width (12);
105
unbind_button.set_sensitive (false);
111
TreeModel::iterator i = view.get_selection()->get_selected();
113
unbind_button.set_sensitive (false);
115
if (i != model->children().end()) {
116
string path = (*i)[columns.path];
118
if (!(*i)[columns.bindable]) {
122
bool result = AccelMap::change_entry (path,
127
(*i)[columns.binding] = string ();
133
KeyEditor::on_show ()
136
view.get_selection()->unselect_all ();
137
ArdourWindow::on_show ();
141
KeyEditor::on_unmap ()
143
ArdourWindow::on_unmap ();
147
KeyEditor::action_selected ()
149
if (view.get_selection()->count_selected_rows() == 0) {
153
TreeModel::iterator i = view.get_selection()->get_selected();
155
unbind_button.set_sensitive (false);
157
if (i != model->children().end()) {
159
string path = (*i)[columns.path];
161
if (!(*i)[columns.bindable]) {
165
string binding = (*i)[columns.binding];
167
if (!binding.empty()) {
168
unbind_button.set_sensitive (true);
174
KeyEditor::on_key_press_event (GdkEventKey* ev)
177
last_state = ev->state;
182
KeyEditor::on_key_release_event (GdkEventKey* ev)
184
if (ARDOUR::Profile->get_sae() || !can_bind || ev->state != last_state) {
188
TreeModel::iterator i = view.get_selection()->get_selected();
190
if (i != model->children().end()) {
191
string path = (*i)[columns.path];
193
if (!(*i)[columns.bindable]) {
197
Gtkmm2ext::possibly_translate_keyval_to_make_legal_accelerator (ev->keyval);
200
bool result = AccelMap::change_entry (path,
202
ModifierType (Keyboard::RelevantModifierKeyMask & ev->state),
207
(*i)[columns.binding] = ActionManager::get_key_representation (path, key);
217
KeyEditor::populate ()
219
vector<string> paths;
220
vector<string> labels;
221
vector<string> tooltips;
223
vector<AccelKey> bindings;
224
typedef std::map<string,TreeIter> NodeMap;
228
ActionManager::get_all_actions (labels, paths, tooltips, keys, bindings);
230
vector<string>::iterator k;
231
vector<string>::iterator p;
232
vector<string>::iterator t;
233
vector<string>::iterator l;
237
for (l = labels.begin(), k = keys.begin(), p = paths.begin(), t = tooltips.begin(); l != labels.end(); ++k, ++p, ++t, ++l) {
240
vector<string> parts;
244
split (*p, parts, '/');
250
//kinda kludgy way to avoid displaying menu items as mappable
251
if ( parts[1] == _("Main_menu") )
253
if ( parts[1] == _("JACK") )
255
if ( parts[1] == _("redirectmenu") )
257
if ( parts[1] == _("Editor_menus") )
259
if ( parts[1] == _("RegionList") )
261
if ( parts[1] == _("ProcessorMenu") )
264
if ((r = nodes.find (parts[1])) == nodes.end()) {
266
/* top level is missing */
269
TreeModel::Row parent;
270
rowp = model->append();
271
nodes[parts[1]] = rowp;
273
parent[columns.action] = parts[1];
274
parent[columns.bindable] = false;
276
row = *(model->append (parent.children()));
280
row = *(model->append ((*r->second)->children()));
284
/* add this action */
287
row[columns.action] = *t;
289
row[columns.action] = *l;
291
row[columns.path] = (*p);
292
row[columns.bindable] = true;
294
if (*k == ActionManager::unbound_string) {
295
row[columns.binding] = string();
297
row[columns.binding] = (*k);