Skip to content

Commit

Permalink
Possibility to assign same key to several tools (fix #1460)
Browse files Browse the repository at this point in the history
  • Loading branch information
dacap committed Dec 6, 2017
1 parent 150b278 commit b0b3818
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
14 changes: 11 additions & 3 deletions src/app/ui/keyboard_shortcuts.cpp
Expand Up @@ -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);
}

Expand Down Expand Up @@ -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);
}
}
}

Expand Down
4 changes: 3 additions & 1 deletion src/app/ui/keyboard_shortcuts.h
Expand Up @@ -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);
Expand Down

0 comments on commit b0b3818

Please sign in to comment.