mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 07:08:10 +00:00
LibGUI: Allow GActions to be scoped either globally or widget-locally.
This makes it possible for e.g GTextEditor to create a bunch of actions with popular shortcuts like Ctrl+C, etc, without polluting the global shortcut namespace. Widget-local actions will only activate while their corresponding widget has focus. :^)
This commit is contained in:
parent
a56e1afb64
commit
5c5ce4f885
8 changed files with 102 additions and 41 deletions
|
@ -7,6 +7,7 @@
|
|||
#include <LibCore/CNotifier.h>
|
||||
#include <LibGUI/GMenu.h>
|
||||
#include <LibGUI/GDesktop.h>
|
||||
#include <LibGUI/GWidget.h>
|
||||
#include <LibC/unistd.h>
|
||||
#include <LibC/stdio.h>
|
||||
#include <LibC/fcntl.h>
|
||||
|
@ -124,6 +125,15 @@ void GEventLoop::handle_key_event(const WSAPI_ServerMessage& event, GWindow& win
|
|||
key_event->m_text = String(&event.key.character, 1);
|
||||
|
||||
if (event.type == WSAPI_ServerMessage::Type::KeyDown) {
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (auto* action = GApplication::the().action_for_key_event(*key_event)) {
|
||||
if (action->is_enabled()) {
|
||||
action->activate();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue