mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 01:07:35 +00:00
LibGUI: Don't crash when updating menu item that's not in the window server (#83)
Don't crash when updating menu item that's not in the window server. Menu Items begin with an invalid ID of -1, and only get a valid ID if the menu they are attached to is added to the window server. They don't send updates to the server unless they have a valid ID. Fixes #82
This commit is contained in:
parent
ebf645d72a
commit
9823354754
4 changed files with 7 additions and 2 deletions
|
@ -32,6 +32,7 @@ GMenu::~GMenu()
|
||||||
void GMenu::add_action(Retained<GAction> action)
|
void GMenu::add_action(Retained<GAction> action)
|
||||||
{
|
{
|
||||||
m_items.append(make<GMenuItem>(m_menu_id, move(action)));
|
m_items.append(make<GMenuItem>(m_menu_id, move(action)));
|
||||||
|
dbgprintf("MenuItem Menu ID: %d\n", m_menu_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
void GMenu::add_separator()
|
void GMenu::add_separator()
|
||||||
|
@ -70,6 +71,7 @@ int GMenu::realize_menu()
|
||||||
auto response = GEventLoop::current().sync_request(request, WSAPI_ServerMessage::Type::DidCreateMenu);
|
auto response = GEventLoop::current().sync_request(request, WSAPI_ServerMessage::Type::DidCreateMenu);
|
||||||
m_menu_id = response.menu.menu_id;
|
m_menu_id = response.menu.menu_id;
|
||||||
|
|
||||||
|
dbgprintf("GMenu: Realizing menu! New menu ID: %d", m_menu_id);
|
||||||
ASSERT(m_menu_id > 0);
|
ASSERT(m_menu_id > 0);
|
||||||
for (int i = 0; i < m_items.size(); ++i) {
|
for (int i = 0; i < m_items.size(); ++i) {
|
||||||
auto& item = *m_items[i];
|
auto& item = *m_items[i];
|
||||||
|
@ -79,6 +81,7 @@ int GMenu::realize_menu()
|
||||||
WSAPI_ClientMessage request;
|
WSAPI_ClientMessage request;
|
||||||
request.type = WSAPI_ClientMessage::Type::AddMenuSeparator;
|
request.type = WSAPI_ClientMessage::Type::AddMenuSeparator;
|
||||||
request.menu.menu_id = m_menu_id;
|
request.menu.menu_id = m_menu_id;
|
||||||
|
dbgprintf("MenuItem [New] Menu ID: %d\n", m_menu_id);
|
||||||
GEventLoop::current().sync_request(request, WSAPI_ServerMessage::Type::DidAddMenuSeparator);
|
GEventLoop::current().sync_request(request, WSAPI_ServerMessage::Type::DidAddMenuSeparator);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
|
@ -33,7 +33,7 @@ private:
|
||||||
int realize_menu();
|
int realize_menu();
|
||||||
void unrealize_menu();
|
void unrealize_menu();
|
||||||
|
|
||||||
int m_menu_id { 0 };
|
int m_menu_id { -1 };
|
||||||
String m_name;
|
String m_name;
|
||||||
Vector<OwnPtr<GMenuItem>> m_items;
|
Vector<OwnPtr<GMenuItem>> m_items;
|
||||||
};
|
};
|
||||||
|
|
|
@ -46,6 +46,8 @@ void GMenuItem::set_checked(bool checked)
|
||||||
|
|
||||||
void GMenuItem::update_window_server()
|
void GMenuItem::update_window_server()
|
||||||
{
|
{
|
||||||
|
if (m_menu_id < 0)
|
||||||
|
return;
|
||||||
auto& action = *m_action;
|
auto& action = *m_action;
|
||||||
WSAPI_ClientMessage request;
|
WSAPI_ClientMessage request;
|
||||||
request.type = WSAPI_ClientMessage::Type::UpdateMenuItem;
|
request.type = WSAPI_ClientMessage::Type::UpdateMenuItem;
|
||||||
|
|
|
@ -36,7 +36,7 @@ private:
|
||||||
void update_window_server();
|
void update_window_server();
|
||||||
|
|
||||||
Type m_type { Invalid };
|
Type m_type { Invalid };
|
||||||
unsigned m_menu_id { 0 };
|
int m_menu_id { -1 };
|
||||||
unsigned m_identifier { 0 };
|
unsigned m_identifier { 0 };
|
||||||
bool m_enabled { true };
|
bool m_enabled { true };
|
||||||
bool m_checkable { false };
|
bool m_checkable { false };
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue