1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-26 05:07:35 +00:00

WindowServer: Support Alt+Character menu shortcuts :^)

This patch adds support for opening menus via keyboard shortcuts.
Use an ampersand in a menu name to automatically create a keyboard
shortcut (Alt + the character following the ampersand.)

Menus with an Alt shortcut have a small underline under the shortcut
character for discoverability.
This commit is contained in:
Andreas Kling 2021-04-05 23:03:55 +02:00
parent 89bc655765
commit d80fb6d9c0
6 changed files with 56 additions and 19 deletions

View file

@ -43,12 +43,26 @@
namespace WindowServer {
Menu::Menu(ClientConnection* client, int menu_id, const String& name)
static u32 find_ampersand_shortcut_character(const String& string)
{
Utf8View utf8_view { string };
for (auto it = utf8_view.begin(); it != utf8_view.end(); ++it) {
if (*it == '&') {
++it;
if (it != utf8_view.end() && *it != '&')
return *it;
}
}
return 0;
}
Menu::Menu(ClientConnection* client, int menu_id, String name)
: Core::Object(client)
, m_client(client)
, m_menu_id(menu_id)
, m_name(move(name))
{
m_alt_shortcut_character = find_ampersand_shortcut_character(m_name);
}
Menu::~Menu()