1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 04:17:35 +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:
Andreas Kling 2022-12-07 21:18:02 +01:00
parent df7c0eacd4
commit 49f5767789
13 changed files with 88 additions and 14 deletions

View file

@ -12,10 +12,11 @@
namespace WindowServer {
MenuItem::MenuItem(Menu& menu, unsigned identifier, DeprecatedString const& text, DeprecatedString const& shortcut_text, bool enabled, bool checkable, bool checked, Gfx::Bitmap const* icon)
MenuItem::MenuItem(Menu& menu, unsigned identifier, DeprecatedString const& text, DeprecatedString const& shortcut_text, bool enabled, bool visible, bool checkable, bool checked, Gfx::Bitmap const* icon)
: m_menu(menu)
, m_type(Text)
, m_enabled(enabled)
, m_visible(visible)
, m_checkable(checkable)
, m_checked(checked)
, m_identifier(identifier)
@ -23,6 +24,7 @@ MenuItem::MenuItem(Menu& menu, unsigned identifier, DeprecatedString const& text
, m_shortcut_text(shortcut_text)
, m_icon(icon)
{
menu.invalidate_menu_window();
}
MenuItem::MenuItem(Menu& menu, Type type)
@ -39,6 +41,14 @@ void MenuItem::set_enabled(bool enabled)
m_menu.redraw();
}
void MenuItem::set_visible(bool visible)
{
if (m_visible == visible)
return;
m_visible = visible;
m_menu.invalidate_menu_window();
}
void MenuItem::set_checked(bool checked)
{
if (m_checked == checked)