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;
78 KeyEditor::on_key_release_event (GdkEventKey* ev)
80 if (!can_bind || ev->state != last_state) {
84 TreeModel::iterator i = view.get_selection()->get_selected();
86 if (i != model->children().end()) {
87 string path = (*i)[columns.path];
89 if (!(*i)[columns.bindable]) {
93 bool result = AccelMap::change_entry (path,
95 (ModifierType) ev->state,
102 known = ActionManager::lookup_entry (path, key);
105 (*i)[columns.binding] = ActionManager::ui_manager->get_accel_group()->name (key.get_key(), Gdk::ModifierType (key.get_mod()));
107 (*i)[columns.binding] = string();
120 KeyEditor::populate ()
122 vector<string> paths;
123 vector<string> labels;
125 vector<AccelKey> bindings;
126 typedef std::map<string,TreeIter> NodeMap;
130 ActionManager::get_all_actions (labels, paths, keys, bindings);
132 vector<string>::iterator k;
133 vector<string>::iterator p;
134 vector<string>::iterator l;
138 for (l = labels.begin(), k = keys.begin(), p = paths.begin(); l != labels.end(); ++k, ++p, ++l) {
141 vector<string> parts;
145 split (*p, parts, '/');
151 if ((r = nodes.find (parts[1])) == nodes.end()) {
153 /* top level is missing */
156 TreeModel::Row parent;
157 rowp = model->append();
158 nodes[parts[1]] = rowp;
160 parent[columns.action] = parts[1];
161 parent[columns.bindable] = false;
163 row = *(model->append (parent.children()));
167 row = *(model->append ((*r->second)->children()));
171 /* add this action */
173 row[columns.action] = (*l);
174 row[columns.path] = (*p);
175 row[columns.bindable] = true;
177 if (*k == ActionManager::unbound_string) {
178 row[columns.binding] = string();
180 row[columns.binding] = (*k);