diff --git a/CMakeLists.txt b/CMakeLists.txt --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -53,6 +53,12 @@ option(QRC_SYNTAX "Bundle the syntax definition files inside the library as resources" ON) add_feature_info(SYNTAX_RESOURCE ${QRC_SYNTAX} "Bundle the syntax definition files inside the library as resources") +# +# allow to turn of lookup for syntax files and themes via QStandardPaths +# +option(NO_STANDARD_PATHS "Skip lookup of syntax and theme definitions in QStandardPaths locations" OFF) +add_feature_info(FEATURE_NO_STANDARD_PATHS ${NO_STANDARD_PATHS} "Skip lookup of syntax and theme definitions in QStandardPaths locations") + # # API documentation # @@ -71,6 +77,11 @@ add_definitions(-DHAS_SYNTAX_RESOURCE) endif() +# skip standard paths? +if (NO_STANDARD_PATHS) + add_definitions(-DNO_STANDARD_PATHS) +endif() + # # Actually build the stuff # diff --git a/autotests/test-config.h.in b/autotests/test-config.h.in --- a/autotests/test-config.h.in +++ b/autotests/test-config.h.in @@ -41,6 +41,5 @@ #else repository.addCustomSearchPath(QStringLiteral("@CMAKE_SOURCE_DIR@/data")); repository.addCustomSearchPath(QStringLiteral("@CMAKE_BINARY_DIR@/data")); - repository.reload(); #endif } diff --git a/src/lib/repository.h b/src/lib/repository.h --- a/src/lib/repository.h +++ b/src/lib/repository.h @@ -82,39 +82,48 @@ * additional files from disk is supported as well. * * Loading syntax Definition files works as follows: + * * -# First, all syntax highlighting files are loaded that are located in * QStandardPaths::locateAll(QStandardPaths::GenericDataLocation, QStringLiteral("org.kde.syntax-highlighting/syntax"), QStandardPaths::LocateDirectory); * Under Unix, this uses $XDG_DATA_HOME and $XDG_DATA_DIRS, which could * map to $HOME/.local5/share/org.kde.syntax-highlighting/syntax and * /usr/share/org.kde.syntax-highlighting/syntax. + * * -# Next, for backwards compatibility with Kate, all syntax highlighting * files are loaded that are located in * QStandardPaths::locateAll(QStandardPaths::GenericDataLocation, QStringLiteral("katepart5/syntax"), QStandardPaths::LocateDirectory); * Again, under Unix, this uses $XDG_DATA_HOME and $XDG_DATA_DIRS, which * could map to $HOME/.local5/share/katepart5/syntax and * /usr/share/katepart5/syntax. + * * -# Then, all files compiled into the library through resources are loaded. * The internal resource path is ":/org.kde.syntax-highlighting/syntax". * This path should never be touched by other applications. + * * -# Finally, the search path can be extended by calling addCustomSearchPath(). * A custom search path can either be a path on disk or again a path to - * a Qt resoruce. + * a Qt resource. * * Similarly, loading Theme files works as follows: + * * -# First, all Theme files are loaded that are located in * QStandardPaths::locateAll(QStandardPaths::GenericDataLocation, QStringLiteral("org.kde.syntax-highlighting/themes"), QStandardPaths::LocateDirectory); * Under Unix, this uses $XDG_DATA_HOME and $XDG_DATA_DIRS, which could * map to $HOME/.local5/share/org.kde.syntax-highlighting/themes and * /usr/share/org.kde.syntax-highlighting/themes. + * * -# Then, all files compiled into the library through resources are loaded. * The internal resource path is ":/org.kde.syntax-highlighting/themes". * This path should never be touched by other applications. + * * -# Finally, all Theme%s located in the paths added addCustomSearchPath() * are loaded. * * @note Whenever a Definition or a Theme exists twice, the variant with * higher version is used. * + * @note The QStandardPaths lookup can be disabled by compiling the framework with the -DNO_STANDARD_PATHS define. + * * @see Definition, Theme, AbstractHighlighter * @since 5.28 */ @@ -210,6 +219,8 @@ * Theme%s. Do not append @e syntax or @e themes to @p path * yourself. * + * @note Calling this triggers a reload() of the repository. + * * @since 5.39 */ void addCustomSearchPath(const QString &path); diff --git a/src/lib/repository.cpp b/src/lib/repository.cpp --- a/src/lib/repository.cpp +++ b/src/lib/repository.cpp @@ -36,7 +36,10 @@ #include #include #include + +#ifndef NO_STANDARD_PATHS #include +#endif #include @@ -134,16 +137,20 @@ // always add invalid default "None" highlighting addDefinition(Definition()); - auto dirs = QStandardPaths::locateAll(QStandardPaths::GenericDataLocation, QStringLiteral("org.kde.syntax-highlighting/syntax"), QStandardPaths::LocateDirectory); - foreach (const auto &dir, dirs) + // do lookup in standard paths, if not disabled +#ifndef NO_STANDARD_PATHS + foreach (const auto &dir, QStandardPaths::locateAll(QStandardPaths::GenericDataLocation, QStringLiteral("org.kde.syntax-highlighting/syntax"), QStandardPaths::LocateDirectory)) loadSyntaxFolder(repo, dir); + // backward compatibility with Kate - dirs = QStandardPaths::locateAll(QStandardPaths::GenericDataLocation, QStringLiteral("katepart5/syntax"), QStandardPaths::LocateDirectory); - foreach (const auto &dir, dirs) + foreach (const auto &dir, QStandardPaths::locateAll(QStandardPaths::GenericDataLocation, QStringLiteral("katepart5/syntax"), QStandardPaths::LocateDirectory)) loadSyntaxFolder(repo, dir); +#endif + // default resources are always used loadSyntaxFolder(repo, QStringLiteral(":/org.kde.syntax-highlighting/syntax")); + // user given extra paths foreach (const auto &path, m_customSearchPaths) loadSyntaxFolder(repo, path + QStringLiteral("/syntax")); @@ -158,11 +165,17 @@ }); // load themes - dirs = QStandardPaths::locateAll(QStandardPaths::GenericDataLocation, QStringLiteral("org.kde.syntax-highlighting/themes"), QStandardPaths::LocateDirectory); - foreach (const auto &dir, dirs) + + // do lookup in standard paths, if not disabled +#ifndef NO_STANDARD_PATHS + foreach (const auto &dir, QStandardPaths::locateAll(QStandardPaths::GenericDataLocation, QStringLiteral("org.kde.syntax-highlighting/themes"), QStandardPaths::LocateDirectory)) loadThemeFolder(dir); +#endif + + // default resources are always used loadThemeFolder(QStringLiteral(":/org.kde.syntax-highlighting/themes")); + // user given extra paths foreach (const auto &path, m_customSearchPaths) loadThemeFolder(path + QStringLiteral("/themes")); }