summaryrefslogtreecommitdiff
path: root/Userland/Services
diff options
context:
space:
mode:
authorAlec Murphy <alec@checksum.fail>2022-11-01 18:00:19 -0400
committerAndrew Kaster <andrewdkaster@gmail.com>2022-11-13 18:13:17 -0700
commitc2f3dead9190665763aa1c41e5d5a221cefa03cc (patch)
tree1a940a2f06daea74a97ee165eb0e0a8d28facf0c /Userland/Services
parentf5a2603714492095409d1ced441d9bd09c5050e0 (diff)
downloadserenity-c2f3dead9190665763aa1c41e5d5a221cefa03cc.zip
WindowServer: Update alt shortcuts for menu items when text changes
WindowServer: Make CI happy :^)
Diffstat (limited to 'Userland/Services')
-rw-r--r--Userland/Services/WindowServer/Menu.cpp16
-rw-r--r--Userland/Services/WindowServer/Menu.h1
-rw-r--r--Userland/Services/WindowServer/Window.cpp2
3 files changed, 16 insertions, 3 deletions
diff --git a/Userland/Services/WindowServer/Menu.cpp b/Userland/Services/WindowServer/Menu.cpp
index fc413598f9..86d1ea2d04 100644
--- a/Userland/Services/WindowServer/Menu.cpp
+++ b/Userland/Services/WindowServer/Menu.cpp
@@ -692,12 +692,22 @@ void Menu::set_visible(bool visible)
m_client->async_menu_visibility_did_change(m_menu_id, visible);
}
-void Menu::add_item(NonnullOwnPtr<MenuItem> item)
+void Menu::update_alt_shortcuts_for_items()
{
- if (auto alt_shortcut = find_ampersand_shortcut_character(item->text())) {
- m_alt_shortcut_character_to_item_indices.ensure(to_ascii_lowercase(alt_shortcut)).append(m_items.size());
+ m_alt_shortcut_character_to_item_indices.clear();
+ int i = 0;
+ for (auto& item : m_items) {
+ if (auto alt_shortcut = find_ampersand_shortcut_character(item.text())) {
+ m_alt_shortcut_character_to_item_indices.ensure(to_ascii_lowercase(alt_shortcut)).append(i);
+ }
+ ++i;
}
+}
+
+void Menu::add_item(NonnullOwnPtr<MenuItem> item)
+{
m_items.append(move(item));
+ update_alt_shortcuts_for_items();
}
Vector<size_t> const* Menu::items_with_alt_shortcut(u32 alt_shortcut) const
diff --git a/Userland/Services/WindowServer/Menu.h b/Userland/Services/WindowServer/Menu.h
index 3225bf4c30..dfa28908dd 100644
--- a/Userland/Services/WindowServer/Menu.h
+++ b/Userland/Services/WindowServer/Menu.h
@@ -56,6 +56,7 @@ public:
return found_item;
}
+ void update_alt_shortcuts_for_items();
void add_item(NonnullOwnPtr<MenuItem>);
String const& name() const { return m_name; }
diff --git a/Userland/Services/WindowServer/Window.cpp b/Userland/Services/WindowServer/Window.cpp
index 0c2f026049..c1938f609a 100644
--- a/Userland/Services/WindowServer/Window.cpp
+++ b/Userland/Services/WindowServer/Window.cpp
@@ -233,6 +233,8 @@ void Window::update_window_menu_items()
m_window_menu_close_item->set_enabled(m_closeable);
m_window_menu_move_item->set_enabled(m_minimized_state == WindowMinimizedState::None && !is_maximized() && !m_fullscreen);
+
+ m_window_menu->update_alt_shortcuts_for_items();
}
void Window::set_minimized(bool minimized)