Changeset View
Changeset View
Standalone View
Standalone View
src/lib/repository.cpp
Show First 20 Lines • Show All 63 Lines • ▼ Show 20 Line(s) | 63 | { | |||
---|---|---|---|---|---|
64 | initResource(); | 64 | initResource(); | ||
65 | d->load(this); | 65 | d->load(this); | ||
66 | } | 66 | } | ||
67 | 67 | | |||
68 | Repository::~Repository() | 68 | Repository::~Repository() | ||
69 | { | 69 | { | ||
70 | // reset repo so we can detect in still alive definition instances | 70 | // reset repo so we can detect in still alive definition instances | ||
71 | // that the repo was deleted | 71 | // that the repo was deleted | ||
72 | foreach (const auto &def, d->m_sortedDefs) | 72 | for (const auto &def : qAsConst(d->m_sortedDefs)) | ||
73 | DefinitionData::get(def)->repo = nullptr; | 73 | DefinitionData::get(def)->repo = nullptr; | ||
74 | } | 74 | } | ||
75 | 75 | | |||
76 | Definition Repository::definitionForName(const QString& defName) const | 76 | Definition Repository::definitionForName(const QString& defName) const | ||
77 | { | 77 | { | ||
78 | return d->m_defs.value(defName); | 78 | return d->m_defs.value(defName); | ||
79 | } | 79 | } | ||
80 | 80 | | |||
Show All 12 Lines | |||||
93 | Definition Repository::definitionForFileName(const QString& fileName) const | 93 | Definition Repository::definitionForFileName(const QString& fileName) const | ||
94 | { | 94 | { | ||
95 | QFileInfo fi(fileName); | 95 | QFileInfo fi(fileName); | ||
96 | const auto name = fi.fileName(); | 96 | const auto name = fi.fileName(); | ||
97 | 97 | | |||
98 | QVector<Definition> candidates; | 98 | QVector<Definition> candidates; | ||
99 | for (auto it = d->m_defs.constBegin(); it != d->m_defs.constEnd(); ++it) { | 99 | for (auto it = d->m_defs.constBegin(); it != d->m_defs.constEnd(); ++it) { | ||
100 | auto def = it.value(); | 100 | auto def = it.value(); | ||
101 | foreach (const auto &pattern, def.extensions()) { | 101 | for (const auto &pattern : def.extensions()) { | ||
102 | if (WildcardMatcher::exactMatch(name, pattern)) { | 102 | if (WildcardMatcher::exactMatch(name, pattern)) { | ||
103 | candidates.push_back(def); | 103 | candidates.push_back(def); | ||
104 | break; | 104 | break; | ||
105 | } | 105 | } | ||
106 | } | 106 | } | ||
107 | } | 107 | } | ||
108 | 108 | | |||
109 | return bestCandidate(candidates); | 109 | return bestCandidate(candidates); | ||
110 | } | 110 | } | ||
111 | 111 | | |||
112 | Definition Repository::definitionForMimeType(const QString& mimeType) const | 112 | Definition Repository::definitionForMimeType(const QString& mimeType) const | ||
113 | { | 113 | { | ||
114 | QVector<Definition> candidates; | 114 | QVector<Definition> candidates; | ||
115 | for (auto it = d->m_defs.constBegin(); it != d->m_defs.constEnd(); ++it) { | 115 | for (auto it = d->m_defs.constBegin(); it != d->m_defs.constEnd(); ++it) { | ||
116 | auto def = it.value(); | 116 | auto def = it.value(); | ||
117 | foreach (const auto &matchType, def.mimeTypes()) { | 117 | for (const auto &matchType : def.mimeTypes()) { | ||
118 | if (mimeType == matchType) { | 118 | if (mimeType == matchType) { | ||
119 | candidates.push_back(def); | 119 | candidates.push_back(def); | ||
120 | break; | 120 | break; | ||
121 | } | 121 | } | ||
122 | } | 122 | } | ||
123 | } | 123 | } | ||
124 | 124 | | |||
125 | return bestCandidate(candidates); | 125 | return bestCandidate(candidates); | ||
Show All 29 Lines | |||||
155 | 155 | | |||
156 | void RepositoryPrivate::load(Repository *repo) | 156 | void RepositoryPrivate::load(Repository *repo) | ||
157 | { | 157 | { | ||
158 | // always add invalid default "None" highlighting | 158 | // always add invalid default "None" highlighting | ||
159 | addDefinition(Definition()); | 159 | addDefinition(Definition()); | ||
160 | 160 | | |||
161 | // do lookup in standard paths, if not disabled | 161 | // do lookup in standard paths, if not disabled | ||
162 | #ifndef NO_STANDARD_PATHS | 162 | #ifndef NO_STANDARD_PATHS | ||
163 | foreach (const auto &dir, QStandardPaths::locateAll(QStandardPaths::GenericDataLocation, QStringLiteral("org.kde.syntax-highlighting/syntax"), QStandardPaths::LocateDirectory)) | 163 | for (const auto &dir : QStandardPaths::locateAll(QStandardPaths::GenericDataLocation, QStringLiteral("org.kde.syntax-highlighting/syntax"), QStandardPaths::LocateDirectory)) | ||
164 | loadSyntaxFolder(repo, dir); | 164 | loadSyntaxFolder(repo, dir); | ||
165 | 165 | | |||
166 | // backward compatibility with Kate | 166 | // backward compatibility with Kate | ||
167 | foreach (const auto &dir, QStandardPaths::locateAll(QStandardPaths::GenericDataLocation, QStringLiteral("katepart5/syntax"), QStandardPaths::LocateDirectory)) | 167 | for (const auto &dir : QStandardPaths::locateAll(QStandardPaths::GenericDataLocation, QStringLiteral("katepart5/syntax"), QStandardPaths::LocateDirectory)) | ||
168 | loadSyntaxFolder(repo, dir); | 168 | loadSyntaxFolder(repo, dir); | ||
169 | #endif | 169 | #endif | ||
170 | 170 | | |||
171 | // default resources are always used | 171 | // default resources are always used | ||
172 | loadSyntaxFolder(repo, QStringLiteral(":/org.kde.syntax-highlighting/syntax")); | 172 | loadSyntaxFolder(repo, QStringLiteral(":/org.kde.syntax-highlighting/syntax")); | ||
173 | 173 | | |||
174 | // user given extra paths | 174 | // user given extra paths | ||
175 | foreach (const auto &path, m_customSearchPaths) | 175 | for (const auto &path : qAsConst(m_customSearchPaths)) | ||
176 | loadSyntaxFolder(repo, path + QStringLiteral("/syntax")); | 176 | loadSyntaxFolder(repo, path + QStringLiteral("/syntax")); | ||
177 | 177 | | |||
178 | m_sortedDefs.reserve(m_defs.size()); | 178 | m_sortedDefs.reserve(m_defs.size()); | ||
179 | for (auto it = m_defs.constBegin(); it != m_defs.constEnd(); ++it) | 179 | for (auto it = m_defs.constBegin(); it != m_defs.constEnd(); ++it) | ||
180 | m_sortedDefs.push_back(it.value()); | 180 | m_sortedDefs.push_back(it.value()); | ||
181 | std::sort(m_sortedDefs.begin(), m_sortedDefs.end(), [](const Definition &left, const Definition &right) { | 181 | std::sort(m_sortedDefs.begin(), m_sortedDefs.end(), [](const Definition &left, const Definition &right) { | ||
182 | auto comparison = left.translatedSection().compare(right.translatedSection(), Qt::CaseInsensitive); | 182 | auto comparison = left.translatedSection().compare(right.translatedSection(), Qt::CaseInsensitive); | ||
183 | if (comparison == 0) | 183 | if (comparison == 0) | ||
184 | comparison = left.translatedName().compare(right.translatedName(), Qt::CaseInsensitive); | 184 | comparison = left.translatedName().compare(right.translatedName(), Qt::CaseInsensitive); | ||
185 | return comparison < 0; | 185 | return comparison < 0; | ||
186 | }); | 186 | }); | ||
187 | 187 | | |||
188 | // load themes | 188 | // load themes | ||
189 | 189 | | |||
190 | // do lookup in standard paths, if not disabled | 190 | // do lookup in standard paths, if not disabled | ||
191 | #ifndef NO_STANDARD_PATHS | 191 | #ifndef NO_STANDARD_PATHS | ||
192 | foreach (const auto &dir, QStandardPaths::locateAll(QStandardPaths::GenericDataLocation, QStringLiteral("org.kde.syntax-highlighting/themes"), QStandardPaths::LocateDirectory)) | 192 | for (const auto &dir : QStandardPaths::locateAll(QStandardPaths::GenericDataLocation, QStringLiteral("org.kde.syntax-highlighting/themes"), QStandardPaths::LocateDirectory)) | ||
193 | loadThemeFolder(dir); | 193 | loadThemeFolder(dir); | ||
194 | #endif | 194 | #endif | ||
195 | 195 | | |||
196 | // default resources are always used | 196 | // default resources are always used | ||
197 | loadThemeFolder(QStringLiteral(":/org.kde.syntax-highlighting/themes")); | 197 | loadThemeFolder(QStringLiteral(":/org.kde.syntax-highlighting/themes")); | ||
198 | 198 | | |||
199 | // user given extra paths | 199 | // user given extra paths | ||
200 | foreach (const auto &path, m_customSearchPaths) | 200 | for (const auto &path : qAsConst(m_customSearchPaths)) | ||
201 | loadThemeFolder(path + QStringLiteral("/themes")); | 201 | loadThemeFolder(path + QStringLiteral("/themes")); | ||
202 | } | 202 | } | ||
203 | 203 | | |||
204 | void RepositoryPrivate::loadSyntaxFolder(Repository *repo, const QString &path) | 204 | void RepositoryPrivate::loadSyntaxFolder(Repository *repo, const QString &path) | ||
205 | { | 205 | { | ||
206 | if (loadSyntaxFolderFromIndex(repo, path)) | 206 | if (loadSyntaxFolderFromIndex(repo, path)) | ||
207 | return; | 207 | return; | ||
208 | 208 | | |||
▲ Show 20 Lines • Show All 84 Lines • ▼ Show 20 Line(s) | |||||
293 | { | 293 | { | ||
294 | Q_ASSERT(m_formatId < std::numeric_limits<quint16>::max()); | 294 | Q_ASSERT(m_formatId < std::numeric_limits<quint16>::max()); | ||
295 | return ++m_formatId; | 295 | return ++m_formatId; | ||
296 | } | 296 | } | ||
297 | 297 | | |||
298 | void Repository::reload() | 298 | void Repository::reload() | ||
299 | { | 299 | { | ||
300 | qCDebug(Log) << "Reloading syntax definitions!"; | 300 | qCDebug(Log) << "Reloading syntax definitions!"; | ||
301 | foreach (const auto &def, d->m_sortedDefs) | 301 | for (const auto &def : qAsConst(d->m_sortedDefs)) | ||
302 | DefinitionData::get(def)->clear(); | 302 | DefinitionData::get(def)->clear(); | ||
303 | d->m_defs.clear(); | 303 | d->m_defs.clear(); | ||
304 | d->m_sortedDefs.clear(); | 304 | d->m_sortedDefs.clear(); | ||
305 | 305 | | |||
306 | d->m_themes.clear(); | 306 | d->m_themes.clear(); | ||
307 | 307 | | |||
308 | d->m_foldingRegionId = 0; | 308 | d->m_foldingRegionId = 0; | ||
309 | d->m_foldingRegionIds.clear(); | 309 | d->m_foldingRegionIds.clear(); | ||
Show All 16 Lines |