mirror of
https://github.com/RGBCube/serenity
synced 2025-05-20 07:05:08 +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
|
@ -5,6 +5,7 @@
|
|||
#include <LibGUI/GLayout.h>
|
||||
#include <AK/Assertions.h>
|
||||
#include <SharedGraphics/GraphicsBitmap.h>
|
||||
#include <LibGUI/GAction.h>
|
||||
#include <LibGUI/GPainter.h>
|
||||
#include <LibGUI/GApplication.h>
|
||||
#include <LibGUI/GMenu.h>
|
||||
|
@ -487,3 +488,21 @@ bool GWidget::is_backmost() const
|
|||
return true;
|
||||
return parent->children().first() == this;
|
||||
}
|
||||
|
||||
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());
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue