mirror of
https://github.com/fergalmoran/ladybird.git
synced 2025-12-29 12:49: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:
@@ -32,6 +32,7 @@
|
||||
#include <LibC/stdlib.h>
|
||||
#include <LibC/unistd.h>
|
||||
#include <LibDraw/GraphicsBitmap.h>
|
||||
#include <LibGUI/GAction.h>
|
||||
#include <LibGUI/GApplication.h>
|
||||
#include <LibGUI/GEvent.h>
|
||||
#include <LibGUI/GPainter.h>
|
||||
@@ -633,3 +634,17 @@ void GWindow::notify_state_changed(Badge<GWindowServerConnection>, bool minimize
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
GAction* GWindow::action_for_key_event(const GKeyEvent& event)
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user