summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibGUI/Action.cpp
diff options
context:
space:
mode:
authorAndreas Kling <kling@serenityos.org>2022-12-07 21:18:02 +0100
committerAndreas Kling <kling@serenityos.org>2022-12-10 14:28:38 +0100
commit49f57677893cd61b3555e5fa663b66ae53e42046 (patch)
treed1faad97ae57303781d0c396f5e3bc3de1e93e1d /Userland/Libraries/LibGUI/Action.cpp
parentdf7c0eacd44df1b49afd60c6caa4b1ce911b4273 (diff)
downloadserenity-49f57677893cd61b3555e5fa663b66ae53e42046.zip
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! :^)
Diffstat (limited to 'Userland/Libraries/LibGUI/Action.cpp')
-rw-r--r--Userland/Libraries/LibGUI/Action.cpp13
1 files changed, 13 insertions, 0 deletions
diff --git a/Userland/Libraries/LibGUI/Action.cpp b/Userland/Libraries/LibGUI/Action.cpp
index 678ee44915..8b50211017 100644
--- a/Userland/Libraries/LibGUI/Action.cpp
+++ b/Userland/Libraries/LibGUI/Action.cpp
@@ -228,6 +228,19 @@ void Action::set_enabled(bool enabled)
});
}
+void Action::set_visible(bool visible)
+{
+ if (m_visible == visible)
+ return;
+ m_visible = visible;
+ for_each_toolbar_button([visible](auto& button) {
+ button.set_visible(visible);
+ });
+ for_each_menu_item([visible](auto& item) {
+ item.set_visible(visible);
+ });
+}
+
void Action::set_checked(bool checked)
{
if (m_checked == checked)