fixes for keystate handling in the key binding editor (from trunk)
authorPaul Davis <paul@linuxaudiosystems.com>
Sat, 27 Oct 2007 20:38:23 +0000 (20:38 +0000)
committerPaul Davis <paul@linuxaudiosystems.com>
Sat, 27 Oct 2007 20:38:23 +0000 (20:38 +0000)
git-svn-id: svn://localhost/ardour2/branches/2.0-ongoing@2578 d708f5d6-7413-0410-9779-e7cbd77b26cf

gtk2_ardour/keyeditor.cc
gtk2_ardour/keyeditor.h

index 07aad652afef65209ae104e64c9240154ddaecbc..f3ae77865d1db9b653b72bb4aca9adeb0307fa2a 100644 (file)
@@ -20,6 +20,9 @@ using namespace Gdk;
 KeyEditor::KeyEditor ()
        : ArdourDialog (_("Keybinding Editor"), false)
 {
+       can_bind = false;
+       last_state = 0;
+
        model = TreeStore::create(columns);
 
        view.set_model (model);
@@ -37,7 +40,9 @@ KeyEditor::KeyEditor ()
        
        scroller.add (view);
        scroller.set_policy (Gtk::POLICY_NEVER, Gtk::POLICY_AUTOMATIC);
+
        get_vbox()->pack_start (scroller);
+       get_vbox()->set_border_width (12);
 
        scroller.show ();
        view.show ();
@@ -62,14 +67,30 @@ KeyEditor::action_selected ()
 {
 }
 
+bool
+KeyEditor::on_key_press_event (GdkEventKey* ev)
+{
+       can_bind = true;
+       last_state = ev->state;
+       return false;
+}
+
 bool
 KeyEditor::on_key_release_event (GdkEventKey* ev)
 {
+       if (!can_bind || ev->state != last_state) {
+               return false;
+       }
+
        TreeModel::iterator i = view.get_selection()->get_selected();
 
        if (i != model->children().end()) {
                string path = (*i)[columns.path];
                
+               if (!(*i)[columns.bindable]) {
+                       goto out;
+               } 
+
                bool result = AccelMap::change_entry (path,
                                                      ev->keyval,
                                                      (ModifierType) ev->state,
@@ -91,6 +112,8 @@ KeyEditor::on_key_release_event (GdkEventKey* ev)
                
        }
 
+  out:
+       can_bind = false;
        return true;
 }
 
@@ -136,6 +159,7 @@ KeyEditor::populate ()
                        nodes[parts[1]] = rowp;
                        parent = *(rowp);
                        parent[columns.action] = parts[1];
+                       parent[columns.bindable] = false;
 
                        row = *(model->append (parent.children()));
 
@@ -149,6 +173,7 @@ KeyEditor::populate ()
 
                row[columns.action] = (*l);
                row[columns.path] = (*p);
+               row[columns.bindable] = true;
                
                if (*k == ActionManager::unbound_string) {
                        row[columns.binding] = string();
index b200adabf4a59e14997637337a009cf96e6cbc42..9fd129ca312c6757d3c6fd5a76afb4cd6f637bfe 100644 (file)
@@ -18,6 +18,7 @@ class KeyEditor : public ArdourDialog
   protected:
        void on_show ();
        void on_unmap ();
+       bool on_key_press_event (GdkEventKey*);
        bool on_key_release_event (GdkEventKey*);
 
   private:
@@ -26,10 +27,12 @@ class KeyEditor : public ArdourDialog
                    add (action);
                    add (binding);
                    add (path);
+                   add (bindable);
            }
            Gtk::TreeModelColumn<Glib::ustring> action;
            Gtk::TreeModelColumn<std::string> binding;
            Gtk::TreeModelColumn<std::string> path;
+           Gtk::TreeModelColumn<bool> bindable;
        };
 
        Gtk::ScrolledWindow scroller;
@@ -37,6 +40,9 @@ class KeyEditor : public ArdourDialog
        Glib::RefPtr<Gtk::TreeStore> model;
        KeyEditorColumns columns;
 
+       bool can_bind;
+       guint last_state;
+
        void action_selected ();
        void populate ();
 };