Changeset View
Changeset View
Standalone View
Standalone View
src/lib/repository.cpp
Show All 30 Lines | |||||
31 | #include "wildcardmatcher_p.h" | 31 | #include "wildcardmatcher_p.h" | ||
32 | 32 | | |||
33 | #include <QDebug> | 33 | #include <QDebug> | ||
34 | #include <QDirIterator> | 34 | #include <QDirIterator> | ||
35 | #include <QFile> | 35 | #include <QFile> | ||
36 | #include <QFileInfo> | 36 | #include <QFileInfo> | ||
37 | #include <QJsonDocument> | 37 | #include <QJsonDocument> | ||
38 | #include <QJsonObject> | 38 | #include <QJsonObject> | ||
39 | | ||||
40 | #ifndef NO_STANDARD_PATHS | ||||
39 | #include <QStandardPaths> | 41 | #include <QStandardPaths> | ||
42 | #endif | ||||
40 | 43 | | |||
41 | #include <limits> | 44 | #include <limits> | ||
42 | 45 | | |||
43 | using namespace KSyntaxHighlighting; | 46 | using namespace KSyntaxHighlighting; | ||
44 | 47 | | |||
45 | static void initResource() | 48 | static void initResource() | ||
46 | { | 49 | { | ||
47 | #ifdef HAS_SYNTAX_RESOURCE | 50 | #ifdef HAS_SYNTAX_RESOURCE | ||
▲ Show 20 Lines • Show All 81 Lines • ▼ Show 20 Line(s) | 129 | { | |||
129 | return theme(QLatin1String("Default")); | 132 | return theme(QLatin1String("Default")); | ||
130 | } | 133 | } | ||
131 | 134 | | |||
132 | void RepositoryPrivate::load(Repository *repo) | 135 | void RepositoryPrivate::load(Repository *repo) | ||
133 | { | 136 | { | ||
134 | // always add invalid default "None" highlighting | 137 | // always add invalid default "None" highlighting | ||
135 | addDefinition(Definition()); | 138 | addDefinition(Definition()); | ||
136 | 139 | | |||
137 | auto dirs = QStandardPaths::locateAll(QStandardPaths::GenericDataLocation, QStringLiteral("org.kde.syntax-highlighting/syntax"), QStandardPaths::LocateDirectory); | 140 | // do lookup in standard paths, if not disabled | ||
138 | foreach (const auto &dir, dirs) | 141 | #ifndef NO_STANDARD_PATHS | ||
142 | foreach (const auto &dir, QStandardPaths::locateAll(QStandardPaths::GenericDataLocation, QStringLiteral("org.kde.syntax-highlighting/syntax"), QStandardPaths::LocateDirectory)) | ||||
139 | loadSyntaxFolder(repo, dir); | 143 | loadSyntaxFolder(repo, dir); | ||
144 | | ||||
140 | // backward compatibility with Kate | 145 | // backward compatibility with Kate | ||
141 | dirs = QStandardPaths::locateAll(QStandardPaths::GenericDataLocation, QStringLiteral("katepart5/syntax"), QStandardPaths::LocateDirectory); | 146 | foreach (const auto &dir, QStandardPaths::locateAll(QStandardPaths::GenericDataLocation, QStringLiteral("katepart5/syntax"), QStandardPaths::LocateDirectory)) | ||
142 | foreach (const auto &dir, dirs) | | |||
143 | loadSyntaxFolder(repo, dir); | 147 | loadSyntaxFolder(repo, dir); | ||
148 | #endif | ||||
144 | 149 | | |||
150 | // default resources are always used | ||||
145 | loadSyntaxFolder(repo, QStringLiteral(":/org.kde.syntax-highlighting/syntax")); | 151 | loadSyntaxFolder(repo, QStringLiteral(":/org.kde.syntax-highlighting/syntax")); | ||
146 | 152 | | |||
153 | // user given extra paths | ||||
147 | foreach (const auto &path, m_customSearchPaths) | 154 | foreach (const auto &path, m_customSearchPaths) | ||
148 | loadSyntaxFolder(repo, path + QStringLiteral("/syntax")); | 155 | loadSyntaxFolder(repo, path + QStringLiteral("/syntax")); | ||
149 | 156 | | |||
150 | m_sortedDefs.reserve(m_defs.size()); | 157 | m_sortedDefs.reserve(m_defs.size()); | ||
151 | for (auto it = m_defs.constBegin(); it != m_defs.constEnd(); ++it) | 158 | for (auto it = m_defs.constBegin(); it != m_defs.constEnd(); ++it) | ||
152 | m_sortedDefs.push_back(it.value()); | 159 | m_sortedDefs.push_back(it.value()); | ||
153 | std::sort(m_sortedDefs.begin(), m_sortedDefs.end(), [](const Definition &left, const Definition &right) { | 160 | std::sort(m_sortedDefs.begin(), m_sortedDefs.end(), [](const Definition &left, const Definition &right) { | ||
154 | auto comparison = left.translatedSection().compare(right.translatedSection(), Qt::CaseInsensitive); | 161 | auto comparison = left.translatedSection().compare(right.translatedSection(), Qt::CaseInsensitive); | ||
155 | if (comparison == 0) | 162 | if (comparison == 0) | ||
156 | comparison = left.translatedName().compare(right.translatedName(), Qt::CaseInsensitive); | 163 | comparison = left.translatedName().compare(right.translatedName(), Qt::CaseInsensitive); | ||
157 | return comparison < 0; | 164 | return comparison < 0; | ||
158 | }); | 165 | }); | ||
159 | 166 | | |||
160 | // load themes | 167 | // load themes | ||
161 | dirs = QStandardPaths::locateAll(QStandardPaths::GenericDataLocation, QStringLiteral("org.kde.syntax-highlighting/themes"), QStandardPaths::LocateDirectory); | 168 | | ||
162 | foreach (const auto &dir, dirs) | 169 | // do lookup in standard paths, if not disabled | ||
170 | #ifndef NO_STANDARD_PATHS | ||||
171 | foreach (const auto &dir, QStandardPaths::locateAll(QStandardPaths::GenericDataLocation, QStringLiteral("org.kde.syntax-highlighting/themes"), QStandardPaths::LocateDirectory)) | ||||
163 | loadThemeFolder(dir); | 172 | loadThemeFolder(dir); | ||
173 | #endif | ||||
174 | | ||||
175 | // default resources are always used | ||||
164 | loadThemeFolder(QStringLiteral(":/org.kde.syntax-highlighting/themes")); | 176 | loadThemeFolder(QStringLiteral(":/org.kde.syntax-highlighting/themes")); | ||
165 | 177 | | |||
178 | // user given extra paths | ||||
166 | foreach (const auto &path, m_customSearchPaths) | 179 | foreach (const auto &path, m_customSearchPaths) | ||
167 | loadThemeFolder(path + QStringLiteral("/themes")); | 180 | loadThemeFolder(path + QStringLiteral("/themes")); | ||
168 | } | 181 | } | ||
169 | 182 | | |||
170 | void RepositoryPrivate::loadSyntaxFolder(Repository *repo, const QString &path) | 183 | void RepositoryPrivate::loadSyntaxFolder(Repository *repo, const QString &path) | ||
171 | { | 184 | { | ||
172 | if (loadSyntaxFolderFromIndex(repo, path)) | 185 | if (loadSyntaxFolderFromIndex(repo, path)) | ||
173 | return; | 186 | return; | ||
▲ Show 20 Lines • Show All 118 Lines • Show Last 20 Lines |