3 #include <ardour/profile.h>
5 #include <gtkmm/stock.h>
6 #include <gtkmm/label.h>
7 #include <gtkmm/accelkey.h>
8 #include <gtkmm/accelmap.h>
9 #include <gtkmm/uimanager.h>
11 #include <pbd/strsplit.h>
12 #include <pbd/replace_all.h>
14 #include <ardour/profile.h>
18 #include "keyeditor.h"
27 KeyEditor::KeyEditor ()
28 : ArdourDialog (_("Shortcut Editor"), false)
29 , unbind_button (_("Remove shortcut"))
30 , unbind_box (BUTTONBOX_END)
36 model = TreeStore::create(columns);
38 view.set_model (model);
39 view.append_column (_("Action"), columns.action);
40 view.append_column (_("Shortcut"), columns.binding);
41 view.set_headers_visible (true);
42 view.get_selection()->set_mode (SELECTION_SINGLE);
43 view.set_reorderable (false);
44 view.set_size_request (500,300);
45 view.set_enable_search (false);
46 view.set_rules_hint (true);
47 view.set_name (X_("KeyEditorTree"));
49 view.get_selection()->signal_changed().connect (mem_fun (*this, &KeyEditor::action_selected));
52 scroller.set_policy (Gtk::POLICY_NEVER, Gtk::POLICY_AUTOMATIC);
55 get_vbox()->set_spacing (6);
56 get_vbox()->pack_start (scroller);
58 if (!ARDOUR::Profile->get_sae()) {
60 Label* hint = manage (new Label (_("Select an action, then press the key(s) to (re)set its shortcut")));
62 unbind_box.set_spacing (6);
63 unbind_box.pack_start (*hint, false, true);
64 unbind_box.pack_start (unbind_button, false, false);
65 unbind_button.signal_clicked().connect (mem_fun (*this, &KeyEditor::unbind));
67 get_vbox()->pack_start (unbind_box, false, false);
69 unbind_button.show ();
73 get_vbox()->set_border_width (12);
78 unbind_button.set_sensitive (false);
84 TreeModel::iterator i = view.get_selection()->get_selected();
86 unbind_button.set_sensitive (false);
88 if (i != model->children().end()) {
89 string path = (*i)[columns.path];
91 if (!(*i)[columns.bindable]) {
95 bool result = AccelMap::change_entry (path,
100 (*i)[columns.binding] = string ();
106 KeyEditor::on_show ()
109 view.get_selection()->unselect_all ();
110 ArdourDialog::on_show ();
114 KeyEditor::on_unmap ()
116 ArdourDialog::on_unmap ();
120 KeyEditor::action_selected ()
122 if (view.get_selection()->count_selected_rows() == 0) {
126 TreeModel::iterator i = view.get_selection()->get_selected();
128 unbind_button.set_sensitive (false);
130 if (i != model->children().end()) {
132 string path = (*i)[columns.path];
134 if (!(*i)[columns.bindable]) {
138 string binding = (*i)[columns.binding];
140 if (!binding.empty()) {
141 unbind_button.set_sensitive (true);
147 KeyEditor::on_key_press_event (GdkEventKey* ev)
150 last_state = ev->state;
155 KeyEditor::on_key_release_event (GdkEventKey* ev)
157 if (ARDOUR::Profile->get_sae() || !can_bind || ev->state != last_state) {
161 TreeModel::iterator i = view.get_selection()->get_selected();
163 if (i != model->children().end()) {
164 string path = (*i)[columns.path];
166 if (!(*i)[columns.bindable]) {
170 bool result = AccelMap::change_entry (path,
172 (ModifierType) ev->state,
179 known = ActionManager::lookup_entry (path, key);
182 (*i)[columns.binding] = ActionManager::ui_manager->get_accel_group()->name (key.get_key(), Gdk::ModifierType (key.get_mod()));
184 (*i)[columns.binding] = string();
195 KeyEditor::populate ()
197 vector<string> paths;
198 vector<string> labels;
200 vector<AccelKey> bindings;
201 typedef std::map<string,TreeIter> NodeMap;
205 ActionManager::get_all_actions (labels, paths, keys, bindings);
207 vector<string>::iterator k;
208 vector<string>::iterator p;
209 vector<string>::iterator l;
213 for (l = labels.begin(), k = keys.begin(), p = paths.begin(); l != labels.end(); ++k, ++p, ++l) {
216 vector<string> parts;
220 split (*p, parts, '/');
226 if ((r = nodes.find (parts[1])) == nodes.end()) {
228 /* top level is missing */
231 TreeModel::Row parent;
232 rowp = model->append();
233 nodes[parts[1]] = rowp;
235 parent[columns.action] = parts[1];
236 parent[columns.bindable] = false;
238 row = *(model->append (parent.children()));
242 row = *(model->append ((*r->second)->children()));
246 /* add this action */
248 row[columns.action] = (*l);
249 row[columns.path] = (*p);
250 row[columns.bindable] = true;
252 if (*k == ActionManager::unbound_string) {
253 row[columns.binding] = string();
260 NSAlternate/NSOption key to Mod1
261 NSCommand key to Meta
264 replace_all (label, "<Meta>", _("Command-"));
265 replace_all (label, "<Alt>", _("Option-"));
266 replace_all (label, "<Shift>", _("Shift-"));
267 replace_all (label, "<Control>", _("Control-"));
268 row[columns.binding] = label;
270 row[columns.binding] = (*k);