mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 11:18:11 +00:00
LibGUI+WindowServer: Add "visible" state to GUI actions
This patch adds a visibility state to GUI::Action. All actions default to being visible. When invisible, they do not show up in toolbars on menus (and importantly, they don't occupy any space). This can be used to hide/show context-sensitive actions dynamically without rebuilding menus and toolbars. Thanks to Tim Slater for assuming that action visibility was a thing, which gave me a reason to implement it! :^)
This commit is contained in:
parent
df7c0eacd4
commit
49f5767789
13 changed files with 88 additions and 14 deletions
|
@ -50,6 +50,14 @@ void MenuItem::set_enabled(bool enabled)
|
|||
update_window_server();
|
||||
}
|
||||
|
||||
void MenuItem::set_visible(bool visible)
|
||||
{
|
||||
if (m_visible == visible)
|
||||
return;
|
||||
m_visible = visible;
|
||||
update_window_server();
|
||||
}
|
||||
|
||||
void MenuItem::set_checked(bool checked)
|
||||
{
|
||||
VERIFY(is_checkable());
|
||||
|
@ -75,7 +83,7 @@ void MenuItem::update_window_server()
|
|||
auto& action = *m_action;
|
||||
auto shortcut_text = action.shortcut().is_valid() ? action.shortcut().to_deprecated_string() : DeprecatedString();
|
||||
auto icon = action.icon() ? action.icon()->to_shareable_bitmap() : Gfx::ShareableBitmap();
|
||||
ConnectionToWindowServer::the().async_update_menu_item(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, icon);
|
||||
ConnectionToWindowServer::the().async_update_menu_item(m_menu_id, m_identifier, -1, action.text(), action.is_enabled(), action.is_visible(), action.is_checkable(), action.is_checkable() ? action.is_checked() : false, m_default, shortcut_text, icon);
|
||||
}
|
||||
|
||||
void MenuItem::set_menu_id(Badge<Menu>, unsigned int menu_id)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue