1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 14:48:14 +00:00

LibGUI: Add support for an alternate keyboard shortcut in Action

This patch adds the alternate_shortcut member to LibGUI::Action, which
enables one Action to have two keyboard shortcuts.

Note that the string used in menus and tooltips only shows the main
shortcut, which is the same behaviour as in Firefox and Chrome.
This commit is contained in:
Aatos Majava 2021-06-24 11:53:47 +03:00 committed by Andreas Kling
parent 5b79d53c89
commit 21a193ed5a
2 changed files with 28 additions and 7 deletions

View file

@ -186,9 +186,19 @@ NonnullRefPtr<Action> Action::create(String text, const Shortcut& shortcut, Func
return adopt_ref(*new Action(move(text), shortcut, move(callback), parent));
}
NonnullRefPtr<Action> Action::create(String text, const Shortcut& shortcut, const Shortcut& alternate_shortcut, Function<void(Action&)> callback, Core::Object* parent)
{
return adopt_ref(*new Action(move(text), shortcut, alternate_shortcut, move(callback), parent));
}
NonnullRefPtr<Action> Action::create(String text, const Shortcut& shortcut, RefPtr<Gfx::Bitmap> icon, Function<void(Action&)> callback, Core::Object* parent)
{
return adopt_ref(*new Action(move(text), shortcut, move(icon), move(callback), parent));
return adopt_ref(*new Action(move(text), shortcut, Shortcut {}, move(icon), move(callback), parent));
}
NonnullRefPtr<Action> Action::create(String text, const Shortcut& shortcut, const Shortcut& alternate_shortcut, RefPtr<Gfx::Bitmap> icon, Function<void(Action&)> callback, Core::Object* parent)
{
return adopt_ref(*new Action(move(text), shortcut, alternate_shortcut, move(icon), move(callback), parent));
}
NonnullRefPtr<Action> Action::create_checkable(String text, Function<void(Action&)> callback, Core::Object* parent)
@ -208,30 +218,36 @@ NonnullRefPtr<Action> Action::create_checkable(String text, const Shortcut& shor
NonnullRefPtr<Action> Action::create_checkable(String text, const Shortcut& shortcut, RefPtr<Gfx::Bitmap> icon, Function<void(Action&)> callback, Core::Object* parent)
{
return adopt_ref(*new Action(move(text), shortcut, move(icon), move(callback), parent, true));
return adopt_ref(*new Action(move(text), shortcut, Shortcut {}, move(icon), move(callback), parent, true));
}
Action::Action(String text, Function<void(Action&)> on_activation_callback, Core::Object* parent, bool checkable)
: Action(move(text), Shortcut {}, nullptr, move(on_activation_callback), parent, checkable)
: Action(move(text), Shortcut {}, Shortcut {}, nullptr, move(on_activation_callback), parent, checkable)
{
}
Action::Action(String text, RefPtr<Gfx::Bitmap> icon, Function<void(Action&)> on_activation_callback, Core::Object* parent, bool checkable)
: Action(move(text), Shortcut {}, move(icon), move(on_activation_callback), parent, checkable)
: Action(move(text), Shortcut {}, Shortcut {}, move(icon), move(on_activation_callback), parent, checkable)
{
}
Action::Action(String text, const Shortcut& shortcut, Function<void(Action&)> on_activation_callback, Core::Object* parent, bool checkable)
: Action(move(text), shortcut, nullptr, move(on_activation_callback), parent, checkable)
: Action(move(text), shortcut, Shortcut {}, nullptr, move(on_activation_callback), parent, checkable)
{
}
Action::Action(String text, const Shortcut& shortcut, RefPtr<Gfx::Bitmap> icon, Function<void(Action&)> on_activation_callback, Core::Object* parent, bool checkable)
Action::Action(String text, const Shortcut& shortcut, const Shortcut& alternate_shortcut, Function<void(Action&)> on_activation_callback, Core::Object* parent, bool checkable)
: Action(move(text), shortcut, alternate_shortcut, nullptr, move(on_activation_callback), parent, checkable)
{
}
Action::Action(String text, const Shortcut& shortcut, const Shortcut& alternate_shortcut, RefPtr<Gfx::Bitmap> icon, Function<void(Action&)> on_activation_callback, Core::Object* parent, bool checkable)
: Core::Object(parent)
, on_activation(move(on_activation_callback))
, m_text(move(text))
, m_icon(move(icon))
, m_shortcut(shortcut)
, m_alternate_shortcut(alternate_shortcut)
, m_checkable(checkable)
{
if (parent && is<Widget>(*parent)) {