blob: b50549d2db22007b9bcb311005e9dccb859ed78a (
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
63
64
65
66
67
|
#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()
{
s_the = nullptr;
}
int GApplication::exec()
{
int exit_code = m_event_loop->exec();
// NOTE: Maybe it would be cool to return instead of exit()?
// This would require cleaning up all the GObjects on the heap.
exit(exit_code);
return exit_code;
}
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;
}
|