1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 10:18:11 +00:00

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.
This commit is contained in:
Andreas Kling 2019-07-09 22:10:03 +02:00
parent 2ae0333f5d
commit 7083a0104a
9 changed files with 97 additions and 6 deletions

View file

@ -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;
}