mirror of
https://github.com/fergalmoran/ladybird.git
synced 2025-12-27 03:37:53 +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:
@@ -52,20 +52,20 @@ void GApplication::set_menubar(OwnPtr<GMenuBar>&& menubar)
|
||||
m_menubar->notify_added_to_application(Badge<GApplication>());
|
||||
}
|
||||
|
||||
void GApplication::register_shortcut_action(Badge<GAction>, GAction& action)
|
||||
void GApplication::register_global_shortcut_action(Badge<GAction>, GAction& action)
|
||||
{
|
||||
m_shortcut_actions.set(action.shortcut(), &action);
|
||||
m_global_shortcut_actions.set(action.shortcut(), &action);
|
||||
}
|
||||
|
||||
void GApplication::unregister_shortcut_action(Badge<GAction>, GAction& action)
|
||||
void GApplication::unregister_global_shortcut_action(Badge<GAction>, GAction& action)
|
||||
{
|
||||
m_shortcut_actions.remove(action.shortcut());
|
||||
m_global_shortcut_actions.remove(action.shortcut());
|
||||
}
|
||||
|
||||
GAction* GApplication::action_for_key_event(const GKeyEvent& event)
|
||||
{
|
||||
auto it = m_shortcut_actions.find(GShortcut(event.modifiers(), (KeyCode)event.key()));
|
||||
if (it == m_shortcut_actions.end())
|
||||
auto it = m_global_shortcut_actions.find(GShortcut(event.modifiers(), (KeyCode)event.key()));
|
||||
if (it == m_global_shortcut_actions.end())
|
||||
return nullptr;
|
||||
return (*it).value;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user