From b0b38182676d089e406d6b9b4e21ddb4f1609abf Mon Sep 17 00:00:00 2001 From: David Capello Date: Wed, 6 Dec 2017 10:22:32 -0300 Subject: [PATCH] Possibility to assign same key to several tools (fix #1460) --- src/app/ui/keyboard_shortcuts.cpp | 14 +++++++++++--- src/app/ui/keyboard_shortcuts.h | 4 +++- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/src/app/ui/keyboard_shortcuts.cpp b/src/app/ui/keyboard_shortcuts.cpp index 0f6731964..1731f321d 100644 --- a/src/app/ui/keyboard_shortcuts.cpp +++ b/src/app/ui/keyboard_shortcuts.cpp @@ -190,7 +190,7 @@ void Key::add(const ui::Accelerator& accel, KeySource source) // Remove the accelerator from other commands if (source == KeySource::UserDefined) { - KeyboardShortcuts::instance()->disableAccel(accel, m_keycontext); + KeyboardShortcuts::instance()->disableAccel(accel, m_keycontext, this); m_userRemoved.remove(accel); } @@ -619,11 +619,19 @@ Key* KeyboardShortcuts::action(KeyAction action) return key; } -void KeyboardShortcuts::disableAccel(const ui::Accelerator& accel, KeyContext keyContext) +void KeyboardShortcuts::disableAccel(const ui::Accelerator& accel, + const KeyContext keyContext, + const Key* newKey) { for (Key* key : m_keys) { - if (key->keycontext() == keyContext && key->hasAccel(accel)) + if (key->keycontext() == keyContext && + key->hasAccel(accel) && + // Tools can contain the same keyboard shortcut + (key->type() != KeyType::Tool || + newKey == nullptr || + newKey->type() != KeyType::Tool)) { key->disableAccel(accel); + } } } diff --git a/src/app/ui/keyboard_shortcuts.h b/src/app/ui/keyboard_shortcuts.h index d26e27598..e73027f89 100644 --- a/src/app/ui/keyboard_shortcuts.h +++ b/src/app/ui/keyboard_shortcuts.h @@ -148,7 +148,9 @@ namespace app { Key* quicktool(tools::Tool* tool); Key* action(KeyAction action); - void disableAccel(const ui::Accelerator& accel, KeyContext keyContext); + void disableAccel(const ui::Accelerator& accel, + const KeyContext keyContext, + const Key* newKey); KeyContext getCurrentKeyContext(); bool getCommandFromKeyMessage(ui::Message* msg, Command** command, Params* params);