mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 09:38:11 +00:00
LibGUI+WindowServer: Add support for enabled/disabled actions.
The enabled state of a GAction now propagates both to any toolbar buttons and any menu items linked to the action. Toolbar buttons are painted in a grayed out style when disabled. Menu items are gray when disabled. :^)
This commit is contained in:
parent
32e5c8c689
commit
054c982181
20 changed files with 308 additions and 53 deletions
|
@ -1,5 +1,7 @@
|
|||
#include <LibGUI/GAction.h>
|
||||
#include <LibGUI/GApplication.h>
|
||||
#include <LibGUI/GButton.h>
|
||||
#include <LibGUI/GMenuItem.h>
|
||||
|
||||
GAction::GAction(const String& text, const String& custom_data, Function<void(const GAction&)> on_activation_callback)
|
||||
: on_activation(move(on_activation_callback))
|
||||
|
@ -46,3 +48,50 @@ void GAction::activate()
|
|||
if (on_activation)
|
||||
on_activation(*this);
|
||||
}
|
||||
|
||||
void GAction::register_button(Badge<GButton>, GButton& button)
|
||||
{
|
||||
m_buttons.set(&button);
|
||||
}
|
||||
|
||||
void GAction::unregister_button(Badge<GButton>, GButton& button)
|
||||
{
|
||||
m_buttons.remove(&button);
|
||||
}
|
||||
|
||||
void GAction::register_menu_item(Badge<GMenuItem>, GMenuItem& menu_item)
|
||||
{
|
||||
m_menu_items.set(&menu_item);
|
||||
}
|
||||
|
||||
void GAction::unregister_menu_item(Badge<GMenuItem>, GMenuItem& menu_item)
|
||||
{
|
||||
m_menu_items.remove(&menu_item);
|
||||
}
|
||||
|
||||
template<typename Callback>
|
||||
void GAction::for_each_toolbar_button(Callback callback)
|
||||
{
|
||||
for (auto& it : m_buttons)
|
||||
callback(*it);
|
||||
}
|
||||
|
||||
template<typename Callback>
|
||||
void GAction::for_each_menu_item(Callback callback)
|
||||
{
|
||||
for (auto& it : m_menu_items)
|
||||
callback(*it);
|
||||
}
|
||||
|
||||
void GAction::set_enabled(bool enabled)
|
||||
{
|
||||
if (m_enabled == enabled)
|
||||
return;
|
||||
m_enabled = enabled;
|
||||
for_each_toolbar_button([enabled] (GButton& button) {
|
||||
button.set_enabled(enabled);
|
||||
});
|
||||
for_each_menu_item([enabled] (GMenuItem& item) {
|
||||
item.set_enabled(enabled);
|
||||
});
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue