diff --git a/autotests/input/syntax/testlang.xml b/autotests/input/syntax/testlang.xml
new file mode 100644
--- /dev/null
+++ b/autotests/input/syntax/testlang.xml
@@ -0,0 +1,27 @@
+
+
+
+
+
+ - one
+ - two
+ - three
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/autotests/input/themes/customtheme.theme b/autotests/input/themes/customtheme.theme
new file mode 100644
--- /dev/null
+++ b/autotests/input/themes/customtheme.theme
@@ -0,0 +1,46 @@
+{
+ "metadata" : {
+ "revision" : 1,
+ "name" : "Test Theme"
+ },
+ "text-styles": {
+ "Normal" : {
+ "text-color" : "#1f1c1b",
+ "selected-text-color" : "#ffffff",
+ "bold" : false,
+ "italic" : false,
+ "underline" : false,
+ "strike-through" : false
+ }
+ },
+ "editor-colors": {
+ "background-color" : "#ffffff",
+ "code-folding" : "#94caef",
+ "bracket-matching" : "#ffff00",
+ "current-line" : "#f8f7f6",
+ "icon-border" : "#f0f0f0",
+ "indentation-line" : "#d2d2d2",
+ "line-numbers" : "#a0a0a0",
+ "current-line-number" : "#1e1e1e",
+ "mark-bookmark" : "#0000ff",
+ "mark-breakpoint-active" : "#ff0000",
+ "mark-breakpoint-reached" : "#ffff00",
+ "mark-breakpoint-disabled" : "#ff00ff",
+ "mark-execution" : "#a0a0a4",
+ "mark-warning" : "#00ff00",
+ "mark-error" : "#ff0000",
+ "modified-lines" : "#fdbc4b",
+ "replace-highlight" : "#00ff00",
+ "saved-lines" : "#2ecc71",
+ "search-highlight" : "#ffff00",
+ "selection" : "#94caef",
+ "separator" : "#898887",
+ "spell-checking" : "#bf0303",
+ "tab-marker" : "#d2d2d2",
+ "template-background" : "#d6d2d0",
+ "template-placeholder" : "#baf8ce",
+ "template-focused-placeholder" : "#76da98",
+ "template-read-only-placeholder" : "#f6e6e6",
+ "word-wrap-marker" : "#ededed"
+ }
+}
diff --git a/autotests/syntaxrepository_test.cpp b/autotests/syntaxrepository_test.cpp
--- a/autotests/syntaxrepository_test.cpp
+++ b/autotests/syntaxrepository_test.cpp
@@ -15,6 +15,8 @@
along with this program. If not, see .
*/
+#include "test-config.h"
+
#include
#include
#include
@@ -177,6 +179,22 @@
}
hl.highlightLine(QLatin1String("/**! @todo this should not crash .*/"), State());
}
+
+ void testCustomPath()
+ {
+ QString testInputPath = QStringLiteral(TESTSRCDIR "/input");
+
+ Repository repo;
+ QVERIFY(repo.customSearchPaths().empty());
+ repo.addCustomSearchPath(testInputPath);
+ QCOMPARE(repo.customSearchPaths().size(), 1);
+ QCOMPARE(repo.customSearchPaths()[0], testInputPath);
+
+ auto customDefinition = repo.definitionForName(QLatin1String("Test Syntax"));
+ QVERIFY(customDefinition.isValid());
+ auto customTheme = repo.theme(QLatin1String("Test Theme"));
+ QVERIFY(customTheme.isValid());
+ }
};
}
diff --git a/src/lib/repository.h b/src/lib/repository.h
--- a/src/lib/repository.h
+++ b/src/lib/repository.h
@@ -153,6 +153,20 @@
*/
void reload();
+ /**
+ * Add a custom search path to the repository.
+ * This path will be searched in addition to the usual locations for
+ * syntax and theme definition files.
+ */
+ void addCustomSearchPath(const QString &path);
+
+ /**
+ * Returns the list of custom search paths added to the repository.
+ * By default, this list is empty.
+ * @see addCustomSearchPath()
+ */
+ QVector customSearchPaths() const;
+
private:
Q_DISABLE_COPY(Repository)
friend class RepositoryPrivate;
diff --git a/src/lib/repository.cpp b/src/lib/repository.cpp
--- a/src/lib/repository.cpp
+++ b/src/lib/repository.cpp
@@ -138,6 +138,9 @@
loadSyntaxFolder(repo, QStringLiteral(":/org.kde.syntax-highlighting/syntax"));
+ foreach (const auto &path, m_customSearchPaths)
+ loadSyntaxFolder(repo, path + QStringLiteral("/syntax"));
+
m_sortedDefs.reserve(m_defs.size());
for (auto it = m_defs.constBegin(); it != m_defs.constEnd(); ++it)
m_sortedDefs.push_back(it.value());
@@ -153,6 +156,9 @@
foreach (const auto &dir, dirs)
loadThemeFolder(dir);
loadThemeFolder(QStringLiteral(":/org.kde.syntax-highlighting/themes"));
+
+ foreach (const auto &path, m_customSearchPaths)
+ loadThemeFolder(path + QStringLiteral("/themes"));
}
void RepositoryPrivate::loadSyntaxFolder(Repository *repo, const QString &path)
@@ -266,3 +272,14 @@
d->load(this);
}
+
+void Repository::addCustomSearchPath(const QString &path)
+{
+ d->m_customSearchPaths.append(path);
+ reload();
+}
+
+QVector Repository::customSearchPaths() const
+{
+ return d->m_customSearchPaths;
+}
diff --git a/src/lib/repository_p.h b/src/lib/repository_p.h
--- a/src/lib/repository_p.h
+++ b/src/lib/repository_p.h
@@ -47,6 +47,8 @@
quint16 foldingRegionId(const QString &defName, const QString &foldName);
quint16 nextFormatId();
+ QVector m_customSearchPaths;
+
QHash m_defs;
QVector m_sortedDefs;