use Bindings API for binding replacement
authorPaul Davis <paul@linuxaudiosystems.com>
Wed, 5 Aug 2015 14:57:00 +0000 (10:57 -0400)
committerPaul Davis <paul@linuxaudiosystems.com>
Mon, 22 Feb 2016 20:31:23 +0000 (15:31 -0500)
gtk2_ardour/ardour_ui.cc
gtk2_ardour/keyboard.cc
gtk2_ardour/keyeditor.cc
gtk2_ardour/keyeditor.h

index 9f886ed5125e5047804768bc5fa4847f37a887e3..fec3463dbb7d0293fc807a9e5c2faa04fb9341be 100644 (file)
@@ -587,19 +587,21 @@ ARDOUR_UI::post_engine ()
        /* this is the first point at which all the keybindings are available */
 
        if (ARDOUR_COMMAND_LINE::show_key_actions) {
-               vector<string> names;
-               vector<string> paths;
-               vector<string> tooltips;
-               vector<string> keys;
-               vector<AccelKey> bindings;
-
-               ActionManager::get_all_actions (names, paths, tooltips, keys, bindings);
-
-               vector<string>::iterator n;
-               vector<string>::iterator k;
-               vector<string>::iterator p;
-               for (n = names.begin(), k = keys.begin(), p = paths.begin(); n != names.end(); ++n, ++k, ++p) {
-                       cout << "Action: '" << (*n) << "' bound to '" << (*k) << "' Path: '" << (*p) << "'" << endl;
+
+               for (map<string,Bindings*>::const_iterator mb = Bindings::bindings_for_state.begin(); mb != Bindings::bindings_for_state.end(); ++mb) {
+
+                       vector<string> names;
+                       vector<string> paths;
+                       vector<string> keys;
+                       
+                       mb->second->get_all_actions (names, paths, keys);
+                       
+                       vector<string>::iterator n;
+                       vector<string>::iterator k;
+                       vector<string>::iterator p;
+                       for (n = names.begin(), k = keys.begin(), p = paths.begin(); n != names.end(); ++n, ++k, ++p) {
+                               cout << "Action: '" << (*n) << "' bound to '" << (*k) << "' Path: '" << (*p) << "'" << endl;
+                       }
                }
 
                halt_connection.disconnect ();
index 3612e5facb826b4932a6024290df5ece69a9a946..4856cea4fa0a2429659033e5da5073bd1a165381 100644 (file)
@@ -36,18 +36,6 @@ using namespace PBD;
 using namespace ARDOUR;
 using Gtkmm2ext::Keyboard;
  
-static void
-accel_map_changed (GtkAccelMap* /*map*/,
-                  gchar* /*path*/,
-                  guint /*key*/,
-                  GdkModifierType /*mod*/,
-                  gpointer keyboard)
-{
-       ArdourKeyboard* me = (ArdourKeyboard*)keyboard;
-       Keyboard::keybindings_changed ();
-       me->ui.setup_tooltips ();
-}
-
 #ifdef GTKOSX
 guint ArdourKeyboard::constraint_mod = Keyboard::PrimaryModifier;
 #else
index f517217b0d01acdbe2310d99029843670c4f3247..e95a73af32b47b9f48e14ed8d1d897e0fb6b14b1 100644 (file)
@@ -121,7 +121,13 @@ KeyEditor::on_key_press_event (GdkEventKey* ev)
        if (!ev->is_modifier) {
                last_keyval = ev->keyval;
        }
-       return ArdourWindow::on_key_press_event (ev);
+
+       /* Don't let anything else handle the key press, because navigation
+        * keys will be used by GTK to change the selection/treeview cursor
+        * position
+        */
+       
+       return true;
 }
 
 bool
@@ -145,7 +151,7 @@ KeyEditor::Tab::Tab (KeyEditor& ke, string const & str, Bindings* b)
        model = TreeStore::create(columns);
 
        view.set_model (model);
-       view.append_column (_("Action"), columns.action);
+       view.append_column (_("Action"), columns.name);
        view.append_column (_("Shortcut"), columns.binding);
        view.set_headers_visible (true);
        view.get_selection()->set_mode (SELECTION_SINGLE);
@@ -200,19 +206,14 @@ KeyEditor::Tab::unbind ()
        owner.unbind_button.set_sensitive (false);
 
        if (i != model->children().end()) {
-               string path = (*i)[columns.path];
+               Glib::RefPtr<Action> action = (*i)[columns.action];
 
                if (!(*i)[columns.bindable]) {
                        return;
                }
-
-               bool result = AccelMap::change_entry (path,
-                                                     0,
-                                                     (ModifierType) 0,
-                                                     true);
-               if (result) {
-                       (*i)[columns.binding] = string ();
-               }
+               
+               bindings->remove (action, Gtkmm2ext::Bindings::Press, true);
+               (*i)[columns.binding] = string ();
        }
 }
 
@@ -222,25 +223,20 @@ KeyEditor::Tab::bind (GdkEventKey* release_event, guint pressed_key)
        TreeModel::iterator i = view.get_selection()->get_selected();
 
        if (i != model->children().end()) {
-               string path = (*i)[columns.path];
+
+               string action_name = (*i)[columns.path];
 
                if (!(*i)[columns.bindable]) {
                        return;
                }
 
                GdkModifierType mod = (GdkModifierType)(Keyboard::RelevantModifierKeyMask & release_event->state);
+               Gtkmm2ext::KeyboardKey new_binding (mod, pressed_key);
 
-               Gtkmm2ext::possibly_translate_keyval_to_make_legal_accelerator (release_event->keyval);
-               Gtkmm2ext::possibly_translate_mod_to_make_legal_accelerator (mod);
-
-               bool result = AccelMap::change_entry (path,
-                                                     pressed_key,
-                                                     Gdk::ModifierType(mod),
-                                                     true);
+               bool result = bindings->replace (new_binding, Gtkmm2ext::Bindings::Press, action_name);
 
                if (result) {
-                       AccelKey key;
-                       (*i)[columns.binding] = ActionManager::get_key_representation (path, key);
+                       (*i)[columns.binding] = gtk_accelerator_get_label (new_binding.key(), (GdkModifierType) new_binding.state());
                        owner.unbind_button.set_sensitive (true);
                }
        }
@@ -248,80 +244,93 @@ KeyEditor::Tab::bind (GdkEventKey* release_event, guint pressed_key)
 
 void
 KeyEditor::Tab::populate ()
-{
+{      
        vector<string> paths;
        vector<string> labels;
        vector<string> tooltips;
        vector<string> keys;
-       vector<Gtkmm2ext::KeyboardKey> binds;
+       vector<Glib::RefPtr<Action> > actions;
        typedef std::map<string,TreeIter> NodeMap;
        NodeMap nodes;
        NodeMap::iterator r;
 
-       bindings->get_all_actions (labels, paths, tooltips, keys, binds);
+       bindings->get_all_actions (paths, labels, tooltips, keys, actions);
 
        vector<string>::iterator k;
        vector<string>::iterator p;
        vector<string>::iterator t;
        vector<string>::iterator l;
-
+       vector<Glib::RefPtr<Action> >::iterator a;
+       
        model->clear ();
 
-       for (l = labels.begin(), k = keys.begin(), p = paths.begin(), t = tooltips.begin(); l != labels.end(); ++k, ++p, ++t, ++l) {
+       for (a = actions.begin(), l = labels.begin(), k = keys.begin(), p = paths.begin(), t = tooltips.begin(); l != labels.end(); ++k, ++p, ++t, ++l, ++a) {
 
                TreeModel::Row row;
                vector<string> parts;
 
-               parts.clear ();
-
                split (*p, parts, '/');
 
-               if (parts.empty()) {
+               string category = parts[1];
+               string action_name = parts[2];
+               
+               if (action_name.empty()) {
                        continue;
                }
 
                //kinda kludgy way to avoid displaying menu items as mappable
-               if ((parts[1].find ("Menu") == parts[1].length() - 4) ||
-                   (parts[1].find ("menu") == parts[1].length() - 4) ||
-                   (parts[1] == _("RegionList"))) {
+               if ((action_name.find ("Menu") == action_name.length() - 4) ||
+                   (action_name.find ("menu") == action_name.length() - 4) ||
+                   (action_name == _("RegionList"))) {
                        continue;
                }
 
-               if ((r = nodes.find (parts[1])) == nodes.end()) {
+               if ((r = nodes.find (category)) == nodes.end()) {
 
-                       /* top level is missing */
+                       /* category/group is missing, so add it first */
 
                        TreeIter rowp;
                        TreeModel::Row parent;
                        rowp = model->append();
-                       nodes[parts[1]] = rowp;
+                       nodes[category] = rowp;
                        parent = *(rowp);
-                       parent[columns.action] = parts[1];
+                       parent[columns.name] = category;
                        parent[columns.bindable] = false;
+                       parent[columns.action] = *a;
 
+                       /* now set up the child row that we're about to fill
+                        * out with information
+                        */
+                       
                        row = *(model->append (parent.children()));
 
                } else {
 
+                       /* category/group is present, so just add the child row */
+                       
                        row = *(model->append ((*r->second)->children()));
 
                }
 
                /* add this action */
 
+               /* use the "visible label" as the action name */
+               
                if (l->empty ()) {
-                       row[columns.action] = *t;
+                       /* no label, try using the tooltip instead */
+                       row[columns.name] = *t;
                } else {
-                       row[columns.action] = *l;
+                       row[columns.name] = *l;
                }
-               row[columns.path] = (*p);
+               row[columns.path] = string_compose ("%1/%2", category, action_name);
                row[columns.bindable] = true;
 
                if (*k == ActionManager::unbound_string) {
                        row[columns.binding] = string();
                } else {
-                       row[columns.binding] = (*k);
+                       row[columns.binding] = *k;
                }
+               row[columns.action] = *a;
        }
 }
 
index 472b5063f7c4a940049f9f3d9738fafef5f04336..046f8b0715ca09fa6c1ca15bdfb950cc03ab9acf 100644 (file)
@@ -58,15 +58,17 @@ class KeyEditor : public ArdourWindow
                
                struct KeyEditorColumns : public Gtk::TreeModel::ColumnRecord {
                        KeyEditorColumns () {
-                               add (action);
+                               add (name);
                                add (binding);
                                add (path);
                                add (bindable);
+                               add (action);
                        }
-                       Gtk::TreeModelColumn<std::string> action;
+                       Gtk::TreeModelColumn<std::string> name;
                        Gtk::TreeModelColumn<std::string> binding;
                        Gtk::TreeModelColumn<std::string> path;
                        Gtk::TreeModelColumn<bool> bindable;
+                       Gtk::TreeModelColumn<Glib::RefPtr<Gtk::Action> > action;
                };
                
                Gtk::VBox vpacker;