1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 22:17:45 +00:00

WindowServer: Add IPC call to remove a menu's item

This commit is contained in:
Marco Cutecchia 2022-02-14 14:05:42 +01:00 committed by Andreas Kling
parent b6eaefa87d
commit 8ede1a6a6f
5 changed files with 20 additions and 0 deletions

View file

@ -192,6 +192,18 @@ void ClientConnection::update_menu_item(i32 menu_id, i32 identifier, [[maybe_unu
menu_item->set_checked(checked);
}
void ClientConnection::remove_menu_item(i32 menu_id, i32 identifier)
{
auto it = m_menus.find(menu_id);
if (it == m_menus.end()) {
did_misbehave("RemoveMenuItem: Bad menu ID");
return;
}
auto& menu = *(*it).value;
if (!menu.remove_item_with_identifier(identifier))
did_misbehave("RemoveMenuItem: Bad menu item identifier");
}
void ClientConnection::flash_menubar_menu(i32 window_id, i32 menu_id)
{
auto itw = m_windows.find(window_id);

View file

@ -97,6 +97,7 @@ private:
virtual void add_menu_item(i32, i32, i32, String const&, bool, bool, bool, bool, String const&, Gfx::ShareableBitmap const&, bool) override;
virtual void add_menu_separator(i32) override;
virtual void update_menu_item(i32, i32, i32, String const&, bool, bool, bool, bool, String const&) override;
virtual void remove_menu_item(i32 menu_id, i32 identifier) override;
virtual void flash_menubar_menu(i32, i32) override;
virtual void create_window(i32, Gfx::IntRect const&, bool, bool, bool, bool, bool,
bool, bool, bool, bool, bool, float, float, Gfx::IntSize const&, Gfx::IntSize const&, Gfx::IntSize const&,

View file

@ -562,6 +562,11 @@ MenuItem* Menu::item_with_identifier(unsigned identifier)
return nullptr;
}
bool Menu::remove_item_with_identifier(unsigned identifier)
{
return m_items.remove_first_matching([&](auto& item) { return item->identifier() == identifier; });
}
int Menu::item_index_at(const Gfx::IntPoint& position)
{
int i = 0;

View file

@ -97,6 +97,7 @@ public:
const Gfx::Font& font() const;
MenuItem* item_with_identifier(unsigned);
bool remove_item_with_identifier(unsigned);
void redraw();
void redraw(MenuItem const&);

View file

@ -24,6 +24,7 @@ endpoint WindowServer
add_menu_separator(i32 menu_id) =|
update_menu_item(i32 menu_id, i32 identifier, i32 submenu_id, [UTF8] String text, bool enabled, bool checkable, bool checked, bool is_default, [UTF8] String shortcut) =|
remove_menu_item(i32 menu_id, i32 identifier) =|
flash_menubar_menu(i32 window_id, i32 menu_id) =|
create_window(