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 (_("Shortcut Editor"), false)
26 , unbind_button (_("Remove shortcut"))
27 , unbind_box (BUTTONBOX_END)
33 model = TreeStore::create(columns);
35 view.set_model (model);
36 view.append_column (_("Action"), columns.action);
37 view.append_column (_("Shortcut"), columns.binding);
38 view.set_headers_visible (true);
39 view.get_selection()->set_mode (SELECTION_SINGLE);
40 view.set_reorderable (false);
41 view.set_size_request (500,300);
42 view.set_enable_search (false);
43 view.set_rules_hint (true);
44 view.set_name (X_("KeyEditorTree"));
46 view.get_selection()->signal_changed().connect (mem_fun (*this, &KeyEditor::action_selected));
49 scroller.set_policy (Gtk::POLICY_NEVER, Gtk::POLICY_AUTOMATIC);
51 unbind_box.pack_start (unbind_button, false, false);
53 unbind_button.signal_clicked().connect (mem_fun (*this, &KeyEditor::unbind));
55 get_vbox()->set_spacing (6);
56 get_vbox()->pack_start (scroller);
57 get_vbox()->pack_start (unbind_box, false, false);
58 get_vbox()->set_border_width (12);
63 unbind_button.show ();
64 unbind_button.set_sensitive (false);
70 TreeModel::iterator i = view.get_selection()->get_selected();
72 unbind_button.set_sensitive (false);
74 if (i != model->children().end()) {
75 string path = (*i)[columns.path];
77 if (!(*i)[columns.bindable]) {
81 bool result = AccelMap::change_entry (path,
86 (*i)[columns.binding] = string ();
95 view.get_selection()->unselect_all ();
96 ArdourDialog::on_show ();
100 KeyEditor::on_unmap ()
102 ArdourDialog::on_unmap ();
106 KeyEditor::action_selected ()
108 if (view.get_selection()->count_selected_rows() == 0) {
112 TreeModel::iterator i = view.get_selection()->get_selected();
114 unbind_button.set_sensitive (false);
116 if (i != model->children().end()) {
118 string path = (*i)[columns.path];
120 if (!(*i)[columns.bindable]) {
124 string binding = (*i)[columns.binding];
126 if (!binding.empty()) {
127 unbind_button.set_sensitive (true);
133 KeyEditor::on_key_press_event (GdkEventKey* ev)
136 last_state = ev->state;
141 KeyEditor::on_key_release_event (GdkEventKey* ev)
143 if (ARDOUR::Profile->get_sae() || !can_bind || ev->state != last_state) {
147 TreeModel::iterator i = view.get_selection()->get_selected();
149 if (i != model->children().end()) {
150 string path = (*i)[columns.path];
152 if (!(*i)[columns.bindable]) {
156 bool result = AccelMap::change_entry (path,
158 (ModifierType) ev->state,
165 known = ActionManager::lookup_entry (path, key);
168 (*i)[columns.binding] = ActionManager::ui_manager->get_accel_group()->name (key.get_key(), Gdk::ModifierType (key.get_mod()));
170 (*i)[columns.binding] = string();
181 KeyEditor::populate ()
183 vector<string> paths;
184 vector<string> labels;
186 vector<AccelKey> bindings;
187 typedef std::map<string,TreeIter> NodeMap;
191 ActionManager::get_all_actions (labels, paths, keys, bindings);
193 vector<string>::iterator k;
194 vector<string>::iterator p;
195 vector<string>::iterator l;
199 for (l = labels.begin(), k = keys.begin(), p = paths.begin(); l != labels.end(); ++k, ++p, ++l) {
202 vector<string> parts;
206 split (*p, parts, '/');
212 if ((r = nodes.find (parts[1])) == nodes.end()) {
214 /* top level is missing */
217 TreeModel::Row parent;
218 rowp = model->append();
219 nodes[parts[1]] = rowp;
221 parent[columns.action] = parts[1];
222 parent[columns.bindable] = false;
224 row = *(model->append (parent.children()));
228 row = *(model->append ((*r->second)->children()));
232 /* add this action */
234 row[columns.action] = (*l);
235 row[columns.path] = (*p);
236 row[columns.bindable] = true;
238 if (*k == ActionManager::unbound_string) {
239 row[columns.binding] = string();
244 replace_all (label, "<Mod5>", _("Command-"));
245 replace_all (label, "<Alt>", _("Option-"));
246 replace_all (label, "<Shift>", _("Shift-"));
247 row[columns.binding] = label;
249 row[columns.binding] = (*k);