mirror of
https://github.com/aseprite/aseprite.git
synced 2025-02-22 15:39:52 +00:00
Add ability to use mnemonic without modifiers in alerts
Requested in https://community.aseprite.org/t/16845
This commit is contained in:
parent
53c851c547
commit
11abe10c20
@ -111,7 +111,12 @@ void Alert::addSeparator()
|
|||||||
void Alert::addButton(const std::string& text)
|
void Alert::addButton(const std::string& text)
|
||||||
{
|
{
|
||||||
auto button = new Button(text);
|
auto button = new Button(text);
|
||||||
button->processMnemonicFromText();
|
|
||||||
|
// Process the mnemonic next to & character and "false" means that
|
||||||
|
// the mnemonic letter can be used without Alt or Command key
|
||||||
|
// modifiers.
|
||||||
|
button->processMnemonicFromText('&', false);
|
||||||
|
|
||||||
button->setMinSize(gfx::Size(60*guiscale(), 0));
|
button->setMinSize(gfx::Size(60*guiscale(), 0));
|
||||||
m_buttons.push_back(button);
|
m_buttons.push_back(button);
|
||||||
|
|
||||||
|
@ -80,8 +80,11 @@ bool ButtonBase::onProcessMessage(Message* msg)
|
|||||||
KeyScancode scancode = keymsg->scancode();
|
KeyScancode scancode = keymsg->scancode();
|
||||||
|
|
||||||
if (isEnabled() && isVisible()) {
|
if (isEnabled() && isVisible()) {
|
||||||
bool mnemonicPressed =
|
const bool mnemonicPressed =
|
||||||
((msg->altPressed() || msg->cmdPressed()) &&
|
(mnemonic() &&
|
||||||
|
(!mnemonicRequiresModifiers() ||
|
||||||
|
msg->altPressed() ||
|
||||||
|
msg->cmdPressed()) &&
|
||||||
isMnemonicPressed(keymsg));
|
isMnemonicPressed(keymsg));
|
||||||
|
|
||||||
// For kButtonWidget
|
// For kButtonWidget
|
||||||
|
@ -1503,12 +1503,18 @@ gfx::Point Widget::mousePosInDisplay() const
|
|||||||
return display()->nativeWindow()->pointFromScreen(get_mouse_position());
|
return display()->nativeWindow()->pointFromScreen(get_mouse_position());
|
||||||
}
|
}
|
||||||
|
|
||||||
void Widget::setMnemonic(int mnemonic)
|
void Widget::setMnemonic(const int mnemonic,
|
||||||
|
const bool requireModifiers)
|
||||||
{
|
{
|
||||||
m_mnemonic = mnemonic;
|
static_assert((kMnemonicCharMask & kMnemonicModifiersMask) == 0);
|
||||||
|
ASSERT((mnemonic & kMnemonicModifiersMask) == 0);
|
||||||
|
m_mnemonic =
|
||||||
|
(mnemonic & kMnemonicCharMask) |
|
||||||
|
(requireModifiers ? kMnemonicModifiersMask: 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Widget::processMnemonicFromText(int escapeChar)
|
void Widget::processMnemonicFromText(const int escapeChar,
|
||||||
|
const bool requireModifiers)
|
||||||
{
|
{
|
||||||
// Avoid calling setText() when the widget doesn't have the HAS_TEXT flag
|
// Avoid calling setText() when the widget doesn't have the HAS_TEXT flag
|
||||||
if (!hasText())
|
if (!hasText())
|
||||||
@ -1526,7 +1532,7 @@ void Widget::processMnemonicFromText(int escapeChar)
|
|||||||
break; // Ill-formed string (it ends with escape character)
|
break; // Ill-formed string (it ends with escape character)
|
||||||
}
|
}
|
||||||
else if (chr != escapeChar) {
|
else if (chr != escapeChar) {
|
||||||
setMnemonic(chr);
|
setMnemonic(chr, requireModifiers);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
newText.push_back(chr);
|
newText.push_back(chr);
|
||||||
|
@ -372,14 +372,23 @@ namespace ui {
|
|||||||
|
|
||||||
// Returns lower-case letter that represet the mnemonic of the widget
|
// Returns lower-case letter that represet the mnemonic of the widget
|
||||||
// (the underscored character, i.e. the letter after & symbol).
|
// (the underscored character, i.e. the letter after & symbol).
|
||||||
int mnemonic() const { return m_mnemonic; }
|
int mnemonic() const {
|
||||||
void setMnemonic(int mnemonic);
|
return (m_mnemonic & kMnemonicCharMask);
|
||||||
|
}
|
||||||
|
bool mnemonicRequiresModifiers() const {
|
||||||
|
return (m_mnemonic & kMnemonicModifiersMask ? true: false);
|
||||||
|
}
|
||||||
|
void setMnemonic(const int mnemonic,
|
||||||
|
const bool requireModifiers);
|
||||||
|
|
||||||
// Assigns mnemonic from the character preceded by the given
|
// Assigns mnemonic from the character preceded by the given
|
||||||
// escapeChar ('&' by default).
|
// escapeChar ('&' by default).
|
||||||
void processMnemonicFromText(int escapeChar = '&');
|
void processMnemonicFromText(const int escapeChar = '&',
|
||||||
|
const bool requireModifiers = true);
|
||||||
|
|
||||||
// Returns true if the mnemonic character is pressed.
|
// 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 ui::KeyMessage* keyMsg) const;
|
||||||
|
|
||||||
// Signals
|
// Signals
|
||||||
@ -437,7 +446,14 @@ namespace ui {
|
|||||||
Widget* m_parent; // Who is the parent?
|
Widget* m_parent; // Who is the parent?
|
||||||
int m_parentIndex; // Location/index of this widget in the parent's Widget::m_children vector
|
int m_parentIndex; // Location/index of this widget in the parent's Widget::m_children vector
|
||||||
gfx::Size* m_sizeHint;
|
gfx::Size* m_sizeHint;
|
||||||
int m_mnemonic; // Keyboard shortcut to access this widget like Alt+mnemonic
|
|
||||||
|
// Keyboard shortcut to access this widget like Alt+mnemonic. If
|
||||||
|
// kMnemonicModifiersMask bit is zero, it means that the mnemonic
|
||||||
|
// can be used without Alt or Command key modifiers (useful for
|
||||||
|
// buttons in ui::Alert).
|
||||||
|
static constexpr int kMnemonicCharMask = 0x7f;
|
||||||
|
static constexpr int kMnemonicModifiersMask = 0x80;
|
||||||
|
int m_mnemonic;
|
||||||
|
|
||||||
// Widget size limits
|
// Widget size limits
|
||||||
gfx::Size m_minSize, m_maxSize;
|
gfx::Size m_minSize, m_maxSize;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user