mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 13:18:13 +00:00
WindowServer/LibGUI: Add default menu items and allow default action for context menu
By specifying an optional Action for Menu::popup an application can specify what item should be displayed as a default item.
This commit is contained in:
parent
fc4e01a3c9
commit
1c1ab71692
6 changed files with 44 additions and 20 deletions
|
@ -79,13 +79,22 @@ void MenuItem::set_checked(bool checked)
|
|||
update_window_server();
|
||||
}
|
||||
|
||||
void MenuItem::set_default(bool is_default)
|
||||
{
|
||||
ASSERT(is_checkable());
|
||||
if (m_default == is_default)
|
||||
return;
|
||||
m_default = is_default;
|
||||
update_window_server();
|
||||
}
|
||||
|
||||
void MenuItem::update_window_server()
|
||||
{
|
||||
if (m_menu_id < 0)
|
||||
return;
|
||||
auto& action = *m_action;
|
||||
auto shortcut_text = action.shortcut().is_valid() ? action.shortcut().to_string() : String();
|
||||
WindowServerConnection::the().send_sync<Messages::WindowServer::UpdateMenuItem>(m_menu_id, m_identifier, -1, action.text(), action.is_enabled(), action.is_checkable(), action.is_checkable() ? action.is_checked() : false, shortcut_text);
|
||||
WindowServerConnection::the().send_sync<Messages::WindowServer::UpdateMenuItem>(m_menu_id, m_identifier, -1, action.text(), action.is_enabled(), action.is_checkable(), action.is_checkable() ? action.is_checked() : false, m_default, shortcut_text);
|
||||
}
|
||||
|
||||
void MenuItem::set_menu_id(Badge<Menu>, unsigned int menu_id)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue