mirror of
https://github.com/RGBCube/serenity
synced 2025-05-19 16:45:08 +00:00
LibGUI: Move shortcut actions from GEventLoop to GApplications.
I'm gonna want to have nested event loops sooner or later, so let's not pollute GEventLoop with things that are meant to work globally. This patch also changes key events to pass around their modifiers as a bitfield all the way around the system instead of breaking them up.
This commit is contained in:
parent
725b57fe1f
commit
5e40aa4f1a
11 changed files with 63 additions and 55 deletions
|
@ -1,6 +1,7 @@
|
|||
#include <LibGUI/GApplication.h>
|
||||
#include <LibGUI/GEventLoop.h>
|
||||
#include <LibGUI/GMenuBar.h>
|
||||
#include <LibGUI/GAction.h>
|
||||
|
||||
static GApplication* s_the;
|
||||
|
||||
|
@ -42,3 +43,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)
|
||||
{
|
||||
m_shortcut_actions.set(action.shortcut(), &action);
|
||||
}
|
||||
|
||||
void GApplication::unregister_shortcut_action(Badge<GAction>, GAction& action)
|
||||
{
|
||||
m_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())
|
||||
return nullptr;
|
||||
return (*it).value;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue