1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-20 12:05:07 +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

@ -136,20 +136,20 @@ void GWindowServerConnection::handle(const WindowClient::KeyDown& message)
key_event->m_text = String(&ch, 1);
}
if (auto* focused_widget = window->focused_widget()) {
if (auto* action = focused_widget->action_for_key_event(*key_event)) {
if (action->is_enabled()) {
action->activate();
return;
}
}
}
GAction* action = nullptr;
if (auto* action = GApplication::the().action_for_key_event(*key_event)) {
if (action->is_enabled()) {
action->activate();
return;
}
if (auto* focused_widget = window->focused_widget())
action = focused_widget->action_for_key_event(*key_event);
if (!action)
action = window->action_for_key_event(*key_event);
if (!action)
action = GApplication::the().action_for_key_event(*key_event);
if (action && action->is_enabled()) {
action->activate();
return;
}
CEventLoop::current().post_event(*window, move(key_event));
}