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>
14 #include "keyeditor.h"
22 KeyEditor::KeyEditor ()
23 : ArdourDialog (_("Keybinding Editor"), false)
28 model = TreeStore::create(columns);
30 view.set_model (model);
31 view.append_column (_("Action"), columns.action);
32 view.append_column (_("Binding"), columns.binding);
33 view.set_headers_visible (true);
34 view.get_selection()->set_mode (SELECTION_SINGLE);
35 view.set_reorderable (false);
36 view.set_size_request (300,200);
37 view.set_enable_search (false);
38 view.set_rules_hint (true);
39 view.set_name (X_("KeyEditorTree"));
41 view.get_selection()->signal_changed().connect (mem_fun (*this, &KeyEditor::action_selected));
44 scroller.set_policy (Gtk::POLICY_NEVER, Gtk::POLICY_AUTOMATIC);
46 get_vbox()->pack_start (scroller);
47 get_vbox()->set_border_width (12);
57 view.get_selection()->unselect_all ();
58 ArdourDialog::on_show ();
62 KeyEditor::on_unmap ()
64 ArdourDialog::on_unmap ();
68 KeyEditor::action_selected ()
73 KeyEditor::on_key_press_event (GdkEventKey* ev)
76 last_state = ev->state;
81 KeyEditor::on_key_release_event (GdkEventKey* ev)
83 if (ARDOUR::Profile->get_sae() || !can_bind || ev->state != last_state) {
87 TreeModel::iterator i = view.get_selection()->get_selected();
89 if (i != model->children().end()) {
90 string path = (*i)[columns.path];
92 if (!(*i)[columns.bindable]) {
96 bool result = AccelMap::change_entry (path,
98 (ModifierType) ev->state,
105 known = ActionManager::lookup_entry (path, key);
108 (*i)[columns.binding] = ActionManager::ui_manager->get_accel_group()->name (key.get_key(), Gdk::ModifierType (key.get_mod()));
110 (*i)[columns.binding] = string();
123 KeyEditor::populate ()
125 vector<string> paths;
126 vector<string> labels;
128 vector<AccelKey> bindings;
129 typedef std::map<string,TreeIter> NodeMap;
133 ActionManager::get_all_actions (labels, paths, keys, bindings);
135 vector<string>::iterator k;
136 vector<string>::iterator p;
137 vector<string>::iterator l;
141 for (l = labels.begin(), k = keys.begin(), p = paths.begin(); l != labels.end(); ++k, ++p, ++l) {
144 vector<string> parts;
148 split (*p, parts, '/');
154 if ((r = nodes.find (parts[1])) == nodes.end()) {
156 /* top level is missing */
159 TreeModel::Row parent;
160 rowp = model->append();
161 nodes[parts[1]] = rowp;
163 parent[columns.action] = parts[1];
164 parent[columns.bindable] = false;
166 row = *(model->append (parent.children()));
170 row = *(model->append ((*r->second)->children()));
174 /* add this action */
176 row[columns.action] = (*l);
177 row[columns.path] = (*p);
178 row[columns.bindable] = true;
180 if (*k == ActionManager::unbound_string) {
181 row[columns.binding] = string();
183 row[columns.binding] = (*k);