1/*
2 SPDX-FileCopyrightText: 2018 Eike Hein <hein@kde.org>
3 SPDX-FileCopyrightText: 2021 Volker Krause <vkrause@kde.org>
4
5 SPDX-License-Identifier: MIT
6*/
7
8#include "kquicksyntaxhighlightingplugin.h"
9#include "kquicksyntaxhighlighter.h"
10
11#include <KSyntaxHighlighting/Definition>
12#include <KSyntaxHighlighting/Repository>
13#include <KSyntaxHighlighting/Theme>
14
15#include <memory>
16
17using namespace KSyntaxHighlighting;
18
19Repository *defaultRepository()
20{
21 static std::unique_ptr<Repository> s_instance;
22 if (!s_instance) {
23 s_instance = std::make_unique<Repository>();
24 }
25 return s_instance.get();
26}
27
28void KQuickSyntaxHighlightingPlugin::registerTypes(const char *uri)
29{
30 Q_ASSERT(QLatin1String(uri) == QLatin1String("org.kde.syntaxhighlighting"));
31 qRegisterMetaType<Definition>();
32 qRegisterMetaType<QList<Definition>>();
33 qRegisterMetaType<Theme>();
34 qRegisterMetaType<QList<Theme>>();
35 qmlRegisterType<KQuickSyntaxHighlighter>(uri, versionMajor: 1, versionMinor: 0, qmlName: "SyntaxHighlighter");
36 qmlRegisterUncreatableMetaObject(staticMetaObject: Definition::staticMetaObject, uri, versionMajor: 1, versionMinor: 0, qmlName: "Definition", reason: {});
37 qmlRegisterUncreatableMetaObject(staticMetaObject: Theme::staticMetaObject, uri, versionMajor: 1, versionMinor: 0, qmlName: "Theme", reason: {});
38 qmlRegisterSingletonType<Repository>(uri, versionMajor: 1, versionMinor: 0, typeName: "Repository", callback: [](auto engine, auto scriptEngine) {
39 (void)engine;
40 auto repo = defaultRepository();
41 scriptEngine->setObjectOwnership(repo, QJSEngine::CppOwnership);
42 return defaultRepository();
43 });
44}
45
46#include "moc_kquicksyntaxhighlightingplugin.cpp"
47

source code of syntax-highlighting/src/quick/kquicksyntaxhighlightingplugin.cpp