-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathHomeWindowInterface.cpp
More file actions
81 lines (72 loc) · 2.84 KB
/
HomeWindowInterface.cpp
File metadata and controls
81 lines (72 loc) · 2.84 KB
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#include "HomeWindowInterface.h"
#include <QQmlComponent>
#include <CoreApi/runtimeinterface.h>
#include <QAKQuick/quickactioncontext.h>
#include <coreplugin/CoreInterface.h>
#include <coreplugin/internal/ActionHelper.h>
namespace Core {
static HomeWindowInterface *m_instance = nullptr;
class HomeWindowInterfacePrivate {
Q_DECLARE_PUBLIC(HomeWindowInterface)
public:
HomeWindowInterface *q_ptr;
void init() {
Q_Q(HomeWindowInterface);
initActionContext();
}
void initActionContext() {
Q_Q(HomeWindowInterface);
auto actionContext = q->actionContext();
{
QQmlComponent component(RuntimeInterface::qmlEngine(), "DiffScope.Core", "GlobalActions");
if (component.isError()) {
qFatal() << component.errorString();
}
auto o = component.createWithInitialProperties({
{"windowHandle", QVariant::fromValue(q)},
});
o->setParent(q);
QMetaObject::invokeMethod(o, "registerToContext", actionContext);
}
{
QQmlComponent component(RuntimeInterface::qmlEngine(), "DiffScope.Core", "HomeActions");
if (component.isError()) {
qFatal() << component.errorString();
}
auto o = component.createWithInitialProperties({
{"windowHandle", QVariant::fromValue(q)},
});
o->setParent(q);
QMetaObject::invokeMethod(o, "registerToContext", actionContext);
}
}
};
HomeWindowInterface *HomeWindowInterface::instance() {
return m_instance;
}
QWindow *HomeWindowInterface::createWindow(QObject *parent) const {
Q_D(const HomeWindowInterface);
QQmlComponent component(RuntimeInterface::qmlEngine(), "DiffScope.Core", "HomeWindow");
if (component.isError()) {
qFatal() << component.errorString();
}
auto win = qobject_cast<QWindow *>(component.createWithInitialProperties({{"windowHandle", QVariant::fromValue(this)}}));
Q_ASSERT(win);
return win;
}
HomeWindowInterface::HomeWindowInterface(QObject *parent) : HomeWindowInterface(*new HomeWindowInterfacePrivate, parent) {
m_instance = this;
}
HomeWindowInterface::HomeWindowInterface(HomeWindowInterfacePrivate &d, QObject *parent) : ActionWindowInterfaceBase(parent), d_ptr(&d) {
d.q_ptr = this;
d.init();
}
HomeWindowInterface::~HomeWindowInterface() {
m_instance = nullptr;
}
HomeWindowInterfaceRegistry *HomeWindowInterfaceRegistry::instance() {
static HomeWindowInterfaceRegistry reg;
return ®
}
}
#include "moc_HomeWindowInterface.cpp"