blob: 9fc3eabfde024118d8e8fa3e04a9de5fab25f1b9 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
|
#include <LibGUI/GApplication.h>
#include <LibGUI/GEventLoop.h>
#include <LibGUI/GMenuBar.h>
#include <LibGUI/GAction.h>
static GApplication* s_the;
GApplication& GApplication::the()
{
ASSERT(s_the);
return *s_the;
}
GApplication::GApplication(int argc, char** argv)
{
(void)argc;
(void)argv;
ASSERT(!s_the);
s_the = this;
m_event_loop = make<GEventLoop>();
}
GApplication::~GApplication()
{
}
int GApplication::exec()
{
return m_event_loop->exec();
}
void GApplication::quit(int exit_code)
{
m_event_loop->quit(exit_code);
}
void GApplication::set_menubar(OwnPtr<GMenuBar>&& menubar)
{
if (m_menubar)
m_menubar->notify_removed_from_application(Badge<GApplication>());
m_menubar = move(menubar);
if (m_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;
}
|