3 #include <gtkmm/stock.h>
4 #include <gtkmm/accelkey.h>
5 #include <gtkmm/accelmap.h>
6 #include <gtkmm/uimanager.h>
8 #include <pbd/strsplit.h>
12 #include "keyeditor.h"
20 KeyEditor::KeyEditor ()
21 : ArdourDialog (_("Keybinding Editor"), false)
26 model = TreeStore::create(columns);
28 view.set_model (model);
29 view.append_column (_("Action"), columns.action);
30 view.append_column (_("Binding"), columns.binding);
31 view.set_headers_visible (true);
32 view.get_selection()->set_mode (SELECTION_SINGLE);
33 view.set_reorderable (false);
34 view.set_size_request (300,200);
35 view.set_enable_search (false);
36 view.set_rules_hint (true);
37 view.set_name (X_("KeyEditorTree"));
39 view.get_selection()->signal_changed().connect (mem_fun (*this, &KeyEditor::action_selected));
42 scroller.set_policy (Gtk::POLICY_NEVER, Gtk::POLICY_AUTOMATIC);
44 get_vbox()->pack_start (scroller);
45 get_vbox()->set_border_width (12);
55 view.get_selection()->unselect_all ();
56 ArdourDialog::on_show ();
60 KeyEditor::on_unmap ()
62 ArdourDialog::on_unmap ();
66 KeyEditor::action_selected ()
71 KeyEditor::on_key_press_event (GdkEventKey* ev)
74 last_state = ev->state;
79 KeyEditor::on_key_release_event (GdkEventKey* ev)
81 if (!can_bind || ev->state != last_state) {
85 TreeModel::iterator i = view.get_selection()->get_selected();
87 if (i != model->children().end()) {
88 string path = (*i)[columns.path];
90 if (!(*i)[columns.bindable]) {
94 bool result = AccelMap::change_entry (path,
96 (ModifierType) ev->state,
103 known = ActionManager::lookup_entry (path, key);
106 (*i)[columns.binding] = ActionManager::ui_manager->get_accel_group()->name (key.get_key(), Gdk::ModifierType (key.get_mod()));
108 (*i)[columns.binding] = string();
121 KeyEditor::populate ()
123 vector<string> paths;
124 vector<string> labels;
126 vector<AccelKey> bindings;
127 typedef std::map<string,TreeIter> NodeMap;
131 ActionManager::get_all_actions (labels, paths, keys, bindings);
133 vector<string>::iterator k;
134 vector<string>::iterator p;
135 vector<string>::iterator l;
139 for (l = labels.begin(), k = keys.begin(), p = paths.begin(); l != labels.end(); ++k, ++p, ++l) {
142 vector<string> parts;
146 split (*p, parts, '/');
152 if ((r = nodes.find (parts[1])) == nodes.end()) {
154 /* top level is missing */
157 TreeModel::Row parent;
158 rowp = model->append();
159 nodes[parts[1]] = rowp;
161 parent[columns.action] = parts[1];
162 parent[columns.bindable] = false;
164 row = *(model->append (parent.children()));
168 row = *(model->append ((*r->second)->children()));
172 /* add this action */
174 row[columns.action] = (*l);
175 row[columns.path] = (*p);
176 row[columns.bindable] = true;
178 if (*k == ActionManager::unbound_string) {
179 row[columns.binding] = string();
181 row[columns.binding] = (*k);