WindowServer: Allow updating the name of a menu

This commit is contained in:
MacDue 2023-03-27 00:04:00 +01:00 committed by Linus Groh
parent 952f6bbb2a
commit cf730403ea
Notes: sideshowbarker 2024-07-16 22:17:36 +09:00
5 changed files with 29 additions and 0 deletions

View File

@ -96,6 +96,27 @@ void ConnectionFromClient::create_menu(i32 menu_id, DeprecatedString const& name
m_menus.set(menu_id, move(menu));
}
void ConnectionFromClient::set_menu_name(i32 menu_id, DeprecatedString const& name)
{
auto it = m_menus.find(menu_id);
if (it == m_menus.end()) {
did_misbehave("DestroyMenu: Bad menu ID");
return;
}
auto& menu = *it->value;
menu.set_name(name);
for (auto& it : m_windows) {
auto& window = *it.value;
window.menubar().for_each_menu([&](Menu& other_menu) {
if (&menu == &other_menu) {
window.invalidate_menubar();
return IterationDecision::Break;
}
return IterationDecision::Continue;
});
}
}
void ConnectionFromClient::destroy_menu(i32 menu_id)
{
auto it = m_menus.find(menu_id);

View File

@ -94,6 +94,7 @@ private:
void destroy_window(Window&, Vector<i32>& destroyed_window_ids);
virtual void create_menu(i32, DeprecatedString const&) override;
virtual void set_menu_name(i32, DeprecatedString const&) override;
virtual void destroy_menu(i32) override;
virtual void add_menu(i32, i32) override;
virtual void add_menu_item(i32, i32, i32, DeprecatedString const&, bool, bool, bool, bool, bool, DeprecatedString const&, Gfx::ShareableBitmap const&, bool) override;

View File

@ -752,6 +752,11 @@ void Menu::set_hovered_index(int index, bool make_input)
redraw(*old_hovered_item);
}
void Menu::set_name(DeprecatedString name)
{
m_name = move(name);
}
bool Menu::is_open() const
{
return MenuManager::the().is_open(*this);

View File

@ -59,6 +59,7 @@ public:
void add_item(NonnullOwnPtr<MenuItem>);
DeprecatedString const& name() const { return m_name; }
void set_name(DeprecatedString);
template<typename Callback>
IterationDecision for_each_item(Callback callback)

View File

@ -5,6 +5,7 @@
endpoint WindowServer
{
create_menu(i32 menu_id, [UTF8] DeprecatedString name) =|
set_menu_name(i32 menu_id, DeprecatedString name) =|
destroy_menu(i32 menu_id) =|
add_menu(i32 window_id, i32 menu_id) =|