Remove duplicated code checking if mnemonic+modifiers are pressed

This commit is contained in:
David Capello 2024-12-10 10:16:20 -03:00
parent cfc92e7cdb
commit 70f2cd9559
3 changed files with 18 additions and 12 deletions

View File

@ -86,11 +86,7 @@ bool ButtonBase::onProcessMessage(Message* msg)
if (isEnabled() && isVisible()) {
const bool mnemonicPressed =
(mnemonic() &&
(!mnemonicRequiresModifiers() ||
msg->altPressed() ||
msg->cmdPressed()) &&
isMnemonicPressed(keymsg));
isMnemonicPressedWithModifiers(keymsg);
// For kButtonWidget
if (m_behaviorType == kButtonWidget) {
@ -157,11 +153,8 @@ bool ButtonBase::onProcessMessage(Message* msg)
KeyMessage* keymsg = static_cast<KeyMessage*>(msg);
KeyScancode scancode = keymsg->scancode();
const bool mnemonicPressed =
(mnemonic() &&
(!mnemonicRequiresModifiers() ||
msg->altPressed() ||
msg->cmdPressed()) &&
isMnemonicPressed(keymsg));
isMnemonicPressedWithModifiers(keymsg);
// Fire the onClick() event only if the user pressed space or
// Alt+the underscored letter of the checkbox label.
if (scancode == kKeySpace || mnemonicPressed) {

View File

@ -1556,6 +1556,15 @@ bool Widget::isMnemonicPressed(const KeyMessage* keyMsg) const
(chr >= '0' && chr <= '9' && keyMsg->scancode() == (kKey0 + chr - '0'))));
}
bool Widget::isMnemonicPressedWithModifiers(const KeyMessage* msg) const
{
return (mnemonic() &&
(!mnemonicRequiresModifiers() ||
msg->altPressed() ||
msg->cmdPressed()) &&
isMnemonicPressed(msg));
}
bool Widget::onProcessMessage(Message* msg)
{
ASSERT(msg != nullptr);

View File

@ -384,7 +384,7 @@ namespace ui {
// Offer the capture to widgets of the given type. Returns true if
// the capture was passed to other widget.
bool offerCapture(ui::MouseMessage* mouseMsg, int widget_type);
bool offerCapture(MouseMessage* mouseMsg, int widget_type);
// Returns lower-case letter that represet the mnemonic of the widget
// (the underscored character, i.e. the letter after & symbol).
@ -405,7 +405,11 @@ namespace ui {
// Returns true if the mnemonic character is pressed (without modifiers).
// TODO maybe we can add check for modifiers now that this
// information is included in the Widget
bool isMnemonicPressed(const ui::KeyMessage* keyMsg) const;
bool isMnemonicPressed(const KeyMessage* keyMsg) const;
// Returns true if the mnemonic character is pressed with
// modifiers (Alt or Command key).
bool isMnemonicPressedWithModifiers(const KeyMessage* msg) const;
// Signals
obs::signal<void()> InitTheme;