1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-22 14:45:08 +00:00

LibGUI: Make GAction scoped to its CObject parent (widget or window)

Unparented GActions are still parented to the application like before,
making them globally available.

This makes it possible to have actions that work whenever a specific
window is active, no matter which widget is currently focused. :^)
This commit is contained in:
Andreas Kling 2020-02-02 01:57:57 +01:00
parent 6ab9dc4ff4
commit 5b47b0d867
8 changed files with 130 additions and 109 deletions

View file

@ -626,20 +626,16 @@ bool GWidget::is_backmost() const
GAction* GWidget::action_for_key_event(const GKeyEvent& event)
{
auto it = m_local_shortcut_actions.find(GShortcut(event.modifiers(), (KeyCode)event.key()));
if (it == m_local_shortcut_actions.end())
return nullptr;
return (*it).value;
}
void GWidget::register_local_shortcut_action(Badge<GAction>, GAction& action)
{
m_local_shortcut_actions.set(action.shortcut(), &action);
}
void GWidget::unregister_local_shortcut_action(Badge<GAction>, GAction& action)
{
m_local_shortcut_actions.remove(action.shortcut());
GShortcut shortcut(event.modifiers(), (KeyCode)event.key());
GAction* found_action = nullptr;
for_each_child_of_type<GAction>([&] (auto& action) {
if (action.shortcut() == shortcut) {
found_action = &action;
return IterationDecision::Break;
}
return IterationDecision::Continue;
});
return found_action;
}
void GWidget::set_updates_enabled(bool enabled)