summaryrefslogtreecommitdiff
path: root/gtk2_ardour/keyeditor.cc
diff options
context:
space:
mode:
authorMathias Buhr <napcode@apparatus.de>2016-02-28 21:54:08 +0100
committerRobin Gareus <robin@gareus.org>2016-03-05 16:27:48 +0100
commit290d9e5e660ba1e8ae73fc6ff2a5e437174542a8 (patch)
treee7f813b317542cfa8a2556631e62d7ec5135ce91 /gtk2_ardour/keyeditor.cc
parent914027ecf8a572a3db3f869fe3ae50f134cac99d (diff)
Small refactoring of keyboard bindings (first part)
- Adds collision detection for keybindings - Fixes a bug that prevented newly created bindings to be deleted properly (reproduction: add a binding, remove it, restart ardour, binding is still there but can now be deleted).
Diffstat (limited to 'gtk2_ardour/keyeditor.cc')
-rw-r--r--gtk2_ardour/keyeditor.cc49
1 files changed, 34 insertions, 15 deletions
diff --git a/gtk2_ardour/keyeditor.cc b/gtk2_ardour/keyeditor.cc
index ba360e9de7..60e8bf58f5 100644
--- a/gtk2_ardour/keyeditor.cc
+++ b/gtk2_ardour/keyeditor.cc
@@ -51,6 +51,19 @@ using namespace PBD;
using Gtkmm2ext::Keyboard;
using Gtkmm2ext::Bindings;
+/*========================================== HELPER =========================================*/
+void bindings_collision_dialog (Gtk::Window& parent)
+{
+ ArdourDialog dialog (parent, _("Colliding keybindings"), true);
+ Label label (_("The key sequence is already bound. Please remove the other binding first."));
+
+ dialog.get_vbox()->pack_start (label, true, true);
+ dialog.add_button (_("Ok"), Gtk::RESPONSE_ACCEPT);
+ dialog.show_all ();
+ dialog.run();
+}
+
+/*======================================== KEYEDITOR =========================================*/
KeyEditor::KeyEditor ()
: ArdourWindow (_("Key Bindings"))
, unbind_button (_("Remove shortcut"))
@@ -211,13 +224,13 @@ KeyEditor::Tab::unbind ()
owner.unbind_button.set_sensitive (false);
if (i != model->children().end()) {
- Glib::RefPtr<Action> action = (*i)[columns.action];
-
if (!(*i)[columns.bindable]) {
return;
}
- bindings->remove (action, Gtkmm2ext::Bindings::Press, true);
+ const std::string& action_path = (*i)[columns.path];
+
+ bindings->remove (Gtkmm2ext::Bindings::Press, action_path , true);
(*i)[columns.binding] = string ();
}
}
@@ -227,23 +240,29 @@ KeyEditor::Tab::bind (GdkEventKey* release_event, guint pressed_key)
{
TreeModel::iterator i = view.get_selection()->get_selected();
- if (i != model->children().end()) {
+ if (i == model->children().end()) {
+ return;
+ }
- string action_name = (*i)[columns.path];
+ string action_path = (*i)[columns.path];
- if (!(*i)[columns.bindable]) {
- return;
- }
+ if (!(*i)[columns.bindable]) {
+ return;
+ }
- GdkModifierType mod = (GdkModifierType)(Keyboard::RelevantModifierKeyMask & release_event->state);
- Gtkmm2ext::KeyboardKey new_binding (mod, pressed_key);
+ GdkModifierType mod = (GdkModifierType)(Keyboard::RelevantModifierKeyMask & release_event->state);
+ Gtkmm2ext::KeyboardKey new_binding (mod, pressed_key);
- bool result = bindings->replace (new_binding, Gtkmm2ext::Bindings::Press, action_name);
+ if (bindings->is_bound (new_binding, Gtkmm2ext::Bindings::Press)) {
+ bindings_collision_dialog (owner);
+ return;
+ }
- if (result) {
- (*i)[columns.binding] = gtk_accelerator_get_label (new_binding.key(), (GdkModifierType) new_binding.state());
- owner.unbind_button.set_sensitive (true);
- }
+ bool result = bindings->replace (new_binding, Gtkmm2ext::Bindings::Press, action_path);
+
+ if (result) {
+ (*i)[columns.binding] = gtk_accelerator_get_label (new_binding.key(), (GdkModifierType) new_binding.state());
+ owner.unbind_button.set_sensitive (true);
}
}