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

LibGUI: Allow finding the source of a GAction activation

When a GAction is activated by a menu, or by a toolbar button, you can
now use GAction::activator() to get a pointer to whomever activated it.

This can be used to implement context-specific behaviors in situations
where the same action is exposed through multiple paths.

This addresses an issue that was brought up in #826.
This commit is contained in:
Andreas Kling 2019-12-09 21:25:48 +01:00
parent fd5eb79d19
commit 571c4d3fb8
4 changed files with 11 additions and 4 deletions

View file

@ -127,10 +127,13 @@ GAction::~GAction()
m_widget->unregister_local_shortcut_action({}, *this);
}
void GAction::activate()
void GAction::activate(CObject* activator)
{
if (activator)
m_activator = activator->make_weak_ptr();
if (on_activation)
on_activation(*this);
m_activator = nullptr;
}
void GAction::register_button(Badge<GButton>, GButton& button)