Fix problems assigning different but similar modifiers to mouse wheel actions

For example, before this change we were depending on the order of the
wheel actions. If an action were associated to <Ctrl> and other one to
<Ctrl+Shift>, when we pressed <Ctrl+Shift> we weren't returning the
action with most modifiers pressed (in this case <Ctrl+Shift>), but
instead the one that was checked first in the for loop (which could
be the one with <Ctrl>).
This commit is contained in:
David Capello 2018-07-24 13:45:12 -03:00
parent 65bc54904d
commit 95c6af355c
2 changed files with 19 additions and 11 deletions

View File

@ -114,8 +114,8 @@ namespace app {
void add(const ui::Accelerator& accel,
const KeySource source,
KeyboardShortcuts& globalKeys);
bool isPressed(const ui::Message* msg,
KeyboardShortcuts& globalKeys) const;
const ui::Accelerator* isPressed(const ui::Message* msg,
KeyboardShortcuts& globalKeys) const;
bool isPressed() const;
bool isLooselyPressed() const;

View File

@ -266,8 +266,8 @@ void Key::add(const ui::Accelerator& accel,
accels->add(accel);
}
bool Key::isPressed(const Message* msg,
KeyboardShortcuts& globalKeys) const
const ui::Accelerator* Key::isPressed(const Message* msg,
KeyboardShortcuts& globalKeys) const
{
if (auto keyMsg = dynamic_cast<const KeyMessage*>(msg)) {
for (const Accelerator& accel : accels()) {
@ -276,7 +276,7 @@ bool Key::isPressed(const Message* msg,
keyMsg->unicodeChar()) &&
(m_keycontext == KeyContext::Any ||
m_keycontext == globalKeys.getCurrentKeyContext())) {
return true;
return &accel;
}
}
}
@ -288,11 +288,11 @@ bool Key::isPressed(const Message* msg,
// like "sprite editor" context, or "timeline" context,
// etc.
m_keycontext == KeyContext::MouseWheel)) {
return true;
return &accel;
}
}
}
return false;
return nullptr;
}
bool Key::isPressed() const
@ -852,13 +852,21 @@ KeyAction KeyboardShortcuts::getCurrentActionModifiers(KeyContext context)
WheelAction KeyboardShortcuts::getWheelActionFromMouseMessage(const KeyContext context,
const ui::Message* msg)
{
WheelAction wheelAction = WheelAction::None;
const ui::Accelerator* bestAccel = nullptr;
KeyPtr bestKey;
for (const KeyPtr& key : m_keys) {
if (key->type() == KeyType::WheelAction &&
key->keycontext() == context &&
key->isPressed(msg, *this))
return key->wheelAction();
key->keycontext() == context) {
const ui::Accelerator* accel = key->isPressed(msg, *this);
if ((accel) &&
(!bestAccel || bestAccel->modifiers() < accel->modifiers())) {
bestAccel = accel;
wheelAction = key->wheelAction();
}
}
}
return WheelAction::None;
return wheelAction;
}
bool KeyboardShortcuts::hasMouseWheelCustomization() const