From c2f3dead9190665763aa1c41e5d5a221cefa03cc Mon Sep 17 00:00:00 2001 From: Alec Murphy Date: Tue, 1 Nov 2022 18:00:19 -0400 Subject: WindowServer: Update alt shortcuts for menu items when text changes WindowServer: Make CI happy :^) --- Userland/Services/WindowServer/Menu.cpp | 16 +++++++++++++--- Userland/Services/WindowServer/Menu.h | 1 + Userland/Services/WindowServer/Window.cpp | 2 ++ 3 files changed, 16 insertions(+), 3 deletions(-) (limited to 'Userland/Services') 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 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 item) +{ m_items.append(move(item)); + update_alt_shortcuts_for_items(); } Vector 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); 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) -- cgit v1.2.3