diff options
author | Andreas Kling <awesomekling@gmail.com> | 2019-07-09 22:10:03 +0200 |
---|---|---|
committer | Andreas Kling <awesomekling@gmail.com> | 2019-07-09 22:10:03 +0200 |
commit | 7083a0104ab73b57494236ac3b7eac78a67f103f (patch) | |
tree | 2190f551297773159b01a5e1fa54fc8d78538231 /Libraries/LibGUI/GAction.cpp | |
parent | 2ae0333f5de5f83541869a9a5b45847a923709c3 (diff) | |
download | serenity-7083a0104ab73b57494236ac3b7eac78a67f103f.zip |
LibGUI: Add GActionGroup, a way to group a bunch of GActions.
This can be used to make a bunch of actions mutually exclusive.
This patch only implements the exclusivity behavior for buttons.
Diffstat (limited to 'Libraries/LibGUI/GAction.cpp')
-rw-r--r-- | Libraries/LibGUI/GAction.cpp | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/Libraries/LibGUI/GAction.cpp b/Libraries/LibGUI/GAction.cpp index 530f553a87..b655c67f58 100644 --- a/Libraries/LibGUI/GAction.cpp +++ b/Libraries/LibGUI/GAction.cpp @@ -1,4 +1,5 @@ #include <LibGUI/GAction.h> +#include <LibGUI/GActionGroup.h> #include <LibGUI/GApplication.h> #include <LibGUI/GButton.h> #include <LibGUI/GMenuItem.h> @@ -105,6 +106,17 @@ void GAction::set_checked(bool checked) if (m_checked == checked) return; m_checked = checked; + + if (m_checked && m_action_group) { + m_action_group->for_each_action([this](auto& other_action) { + if (this == &other_action) + return IterationDecision::Continue; + if (other_action.is_checkable()) + other_action.set_checked(false); + return IterationDecision::Continue; + }); + } + for_each_toolbar_button([checked](GButton& button) { button.set_checked(checked); }); @@ -112,3 +124,8 @@ void GAction::set_checked(bool checked) item.set_checked(checked); }); } + +void GAction::set_group(Badge<GActionGroup>, GActionGroup* group) +{ + m_action_group = group ? group->make_weak_ptr() : nullptr; +} |