NOOP, remove trailing tabs/whitespace.
[ardour.git] / gtk2_ardour / keyeditor.cc
index efcff5b9010e6bea4090fea4552b54725b3d2fc5..cbbbfafc730ee0775253884b3a0786472f452123 100644 (file)
@@ -23,8 +23,6 @@
 
 #include <map>
 
-#include "ardour/profile.h"
-
 #include <gtkmm/stock.h>
 #include <gtkmm/label.h>
 #include <gtkmm/accelkey.h>
 #include "gtkmm2ext/utils.h"
 
 #include "pbd/strsplit.h"
-#include "pbd/replace_all.h"
 
+#include "ardour/filesystem_paths.h"
 #include "ardour/profile.h"
 
 #include "actions.h"
 #include "keyboard.h"
 #include "keyeditor.h"
-#include "utils.h"
 
 #include "i18n.h"
 
@@ -58,8 +55,7 @@ KeyEditor::KeyEditor ()
        , unbind_box (BUTTONBOX_END)
 
 {
-       can_bind = false;
-       last_state = 0;
+       last_keyval = 0;
 
        model = TreeStore::create(columns);
 
@@ -79,7 +75,9 @@ KeyEditor::KeyEditor ()
        scroller.add (view);
        scroller.set_policy (Gtk::POLICY_NEVER, Gtk::POLICY_AUTOMATIC);
 
-       add (scroller);
+       vpacker.set_spacing (6);
+       vpacker.set_border_width (12);
+       vpacker.pack_start (scroller);
 
        if (!ARDOUR::Profile->get_sae()) {
 
@@ -90,14 +88,27 @@ KeyEditor::KeyEditor ()
                unbind_box.pack_start (unbind_button, false, false);
                unbind_button.signal_clicked().connect (sigc::mem_fun (*this, &KeyEditor::unbind));
 
-               add (unbind_box);
+               vpacker.pack_start (unbind_box, false, false);
                unbind_box.show ();
                unbind_button.show ();
 
        }
 
+       reset_button.add (reset_label);
+       reset_label.set_markup (string_compose ("<span size=\"large\" weight=\"bold\">%1</span>", _("Reset Bindings to Defaults")));
+
+       reset_box.pack_start (reset_button, true, false);
+       reset_box.show ();
+       reset_button.show ();
+       reset_label.show ();
+       reset_button.signal_clicked().connect (sigc::mem_fun (*this, &KeyEditor::reset));
+       vpacker.pack_start (reset_box, false, false);
+
+       add (vpacker);
+
        view.show ();
        scroller.show ();
+       vpacker.show ();
 
        unbind_button.set_sensitive (false);
 }
@@ -109,8 +120,6 @@ KeyEditor::unbind ()
 
        unbind_button.set_sensitive (false);
 
-       cerr << "trying to unbind\n";
-
        if (i != model->children().end()) {
                string path = (*i)[columns.path];
 
@@ -172,15 +181,16 @@ KeyEditor::action_selected ()
 bool
 KeyEditor::on_key_press_event (GdkEventKey* ev)
 {
-       can_bind = true;
-       last_state = ev->state;
-       return false;
+       if (!ev->is_modifier) {
+               last_keyval = ev->keyval;
+       }
+       return ArdourWindow::on_key_press_event (ev);
 }
 
 bool
 KeyEditor::on_key_release_event (GdkEventKey* ev)
 {
-       if (ARDOUR::Profile->get_sae() || !can_bind || ev->state != last_state) {
+       if (ARDOUR::Profile->get_sae() || last_keyval == 0) {
                return false;
        }
 
@@ -193,26 +203,25 @@ KeyEditor::on_key_release_event (GdkEventKey* ev)
                        goto out;
                }
 
-               cerr << "real lkeyval: " << ev->keyval << endl;
-                Gtkmm2ext::possibly_translate_keyval_to_make_legal_accelerator (ev->keyval);
-               cerr << "using keyval = " << ev->keyval << endl;
+               GdkModifierType mod = (GdkModifierType)(Keyboard::RelevantModifierKeyMask & ev->state);
 
+               Gtkmm2ext::possibly_translate_keyval_to_make_legal_accelerator (ev->keyval);
+               Gtkmm2ext::possibly_translate_mod_to_make_legal_accelerator (mod);
 
                bool result = AccelMap::change_entry (path,
-                                                     ev->keyval,
-                                                     ModifierType (Keyboard::RelevantModifierKeyMask & ev->state),
+                                                     last_keyval,
+                                                     Gdk::ModifierType(mod),
                                                      true);
 
-               cerr << "New binding to " << ev->keyval << " worked: " << result << endl;
-
                if (result) {
                        AccelKey key;
                        (*i)[columns.binding] = ActionManager::get_key_representation (path, key);
+                       unbind_button.set_sensitive (true);
                }
        }
 
   out:
-       can_bind = false;
+    last_keyval = 0;
        return true;
 }
 
@@ -253,8 +262,6 @@ KeyEditor::populate ()
                //kinda kludgy way to avoid displaying menu items as mappable
                if ( parts[1] == _("Main_menu") )
                        continue;
-               if ( parts[1] == _("JACK") )
-                       continue;
                if ( parts[1] == _("redirectmenu") )
                        continue;
                if ( parts[1] == _("Editor_menus") )
@@ -301,3 +308,12 @@ KeyEditor::populate ()
                }
        }
 }
+
+void
+KeyEditor::reset ()
+{
+       Keyboard::the_keyboard().reset_bindings ();
+       populate ();
+       view.get_selection()->unselect_all ();
+       populate ();
+}