3 #include <ardour/profile.h>
5 #include <gtkmm/stock.h>
6 #include <gtkmm/accelkey.h>
7 #include <gtkmm/accelmap.h>
8 #include <gtkmm/uimanager.h>
10 #include <pbd/strsplit.h>
11 #include <pbd/replace_all.h>
15 #include "keyeditor.h"
24 KeyEditor::KeyEditor ()
25 : ArdourDialog (_("Keybinding Editor"), false)
30 model = TreeStore::create(columns);
32 view.set_model (model);
33 view.append_column (_("Action"), columns.action);
34 view.append_column (_("Binding"), columns.binding);
35 view.set_headers_visible (true);
36 view.get_selection()->set_mode (SELECTION_SINGLE);
37 view.set_reorderable (false);
38 view.set_size_request (500,300);
39 view.set_enable_search (false);
40 view.set_rules_hint (true);
41 view.set_name (X_("KeyEditorTree"));
43 view.get_selection()->signal_changed().connect (mem_fun (*this, &KeyEditor::action_selected));
46 scroller.set_policy (Gtk::POLICY_NEVER, Gtk::POLICY_AUTOMATIC);
48 get_vbox()->pack_start (scroller);
49 get_vbox()->set_border_width (12);
59 view.get_selection()->unselect_all ();
60 ArdourDialog::on_show ();
64 KeyEditor::on_unmap ()
66 ArdourDialog::on_unmap ();
70 KeyEditor::action_selected ()
75 KeyEditor::on_key_press_event (GdkEventKey* ev)
78 last_state = ev->state;
83 KeyEditor::on_key_release_event (GdkEventKey* ev)
85 if (ARDOUR::Profile->get_sae() || !can_bind || ev->state != last_state) {
89 TreeModel::iterator i = view.get_selection()->get_selected();
91 if (i != model->children().end()) {
92 string path = (*i)[columns.path];
94 if (!(*i)[columns.bindable]) {
98 bool result = AccelMap::change_entry (path,
100 (ModifierType) ev->state,
107 known = ActionManager::lookup_entry (path, key);
110 (*i)[columns.binding] = ActionManager::ui_manager->get_accel_group()->name (key.get_key(), Gdk::ModifierType (key.get_mod()));
112 (*i)[columns.binding] = string();
125 KeyEditor::populate ()
127 vector<string> paths;
128 vector<string> labels;
130 vector<AccelKey> bindings;
131 typedef std::map<string,TreeIter> NodeMap;
135 ActionManager::get_all_actions (labels, paths, keys, bindings);
137 vector<string>::iterator k;
138 vector<string>::iterator p;
139 vector<string>::iterator l;
143 for (l = labels.begin(), k = keys.begin(), p = paths.begin(); l != labels.end(); ++k, ++p, ++l) {
146 vector<string> parts;
150 split (*p, parts, '/');
156 if ((r = nodes.find (parts[1])) == nodes.end()) {
158 /* top level is missing */
161 TreeModel::Row parent;
162 rowp = model->append();
163 nodes[parts[1]] = rowp;
165 parent[columns.action] = parts[1];
166 parent[columns.bindable] = false;
168 row = *(model->append (parent.children()));
172 row = *(model->append ((*r->second)->children()));
176 /* add this action */
178 row[columns.action] = (*l);
179 row[columns.path] = (*p);
180 row[columns.bindable] = true;
182 if (*k == ActionManager::unbound_string) {
183 row[columns.binding] = string();
188 replace_all (label, "<Mod5>", _("Command-"));
189 replace_all (label, "<Alt>", _("Option-"));
190 replace_all (label, "<Shift>", _("Shift-"));
191 row[columns.binding] = label;
193 row[columns.binding] = (*k);