Possibility to assign same key to several tools (fix #1460)

This commit is contained in:
David Capello 2017-12-06 10:22:32 -03:00
parent 150b27862f
commit b0b3818267
2 changed files with 14 additions and 4 deletions

View File

@ -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,13 +619,21 @@ 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);
}
}
}
KeyContext KeyboardShortcuts::getCurrentKeyContext()
{

View File

@ -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);