From c02ceb180eb99afd47db8c45a525f40d95d2a627 Mon Sep 17 00:00:00 2001 From: David Schulz Date: Wed, 6 Feb 2019 09:40:40 +0100 Subject: Syntax Highlighter: return all definitions for a file name/mimetype Can be used to create user controls to switch between multiple definitions for a file or mime type. Change-Id: I5fd3744db1e819d0d6f8448a53adaf9d2c7c168d Reviewed-by: Christian Stenger --- .../3rdparty/syntax-highlighting/src/lib/repository.cpp | 17 +++++++++++++---- .../3rdparty/syntax-highlighting/src/lib/repository.h | 12 ++++++++++++ 2 files changed, 25 insertions(+), 4 deletions(-) (limited to 'src/libs/3rdparty/syntax-highlighting') diff --git a/src/libs/3rdparty/syntax-highlighting/src/lib/repository.cpp b/src/libs/3rdparty/syntax-highlighting/src/lib/repository.cpp index 6b2fabd07a..922225a7e1 100644 --- a/src/libs/3rdparty/syntax-highlighting/src/lib/repository.cpp +++ b/src/libs/3rdparty/syntax-highlighting/src/lib/repository.cpp @@ -78,7 +78,7 @@ Definition Repository::definitionForName(const QString& defName) const return d->m_defs.value(defName); } -static Definition bestCandidate(QVector& candidates) +static Definition bestCandidate(QVector &&candidates) { if (candidates.isEmpty()) return Definition(); @@ -91,6 +91,11 @@ static Definition bestCandidate(QVector& candidates) } Definition Repository::definitionForFileName(const QString& fileName) const +{ + return bestCandidate(definitionsForFileName(fileName)); +} + +QVector Repository::definitionsForFileName(const QString &fileName) const { QFileInfo fi(fileName); const auto name = fi.fileName(); @@ -106,10 +111,15 @@ Definition Repository::definitionForFileName(const QString& fileName) const } } - return bestCandidate(candidates); + return candidates; } Definition Repository::definitionForMimeType(const QString& mimeType) const +{ + return bestCandidate(definitionsForMimeType(mimeType)); +} + +QVector Repository::definitionsForMimeType(const QString &mimeType) const { QVector candidates; for (auto it = d->m_defs.constBegin(); it != d->m_defs.constEnd(); ++it) { @@ -121,8 +131,7 @@ Definition Repository::definitionForMimeType(const QString& mimeType) const } } } - - return bestCandidate(candidates); + return candidates; } QVector Repository::definitions() const diff --git a/src/libs/3rdparty/syntax-highlighting/src/lib/repository.h b/src/libs/3rdparty/syntax-highlighting/src/lib/repository.h index c35da5ec37..e4e9bed69f 100644 --- a/src/libs/3rdparty/syntax-highlighting/src/lib/repository.h +++ b/src/libs/3rdparty/syntax-highlighting/src/lib/repository.h @@ -166,6 +166,13 @@ public: */ Definition definitionForFileName(const QString &fileName) const; + /** + * Returns all Definition%s for the file named @p fileName. + * The match is performed based on the \e extensions and @e mimetype of + * the definition files. + */ + QVector definitionsForFileName(const QString &fileName) const; + /** * Returns the best matching Definition to the type named @p mimeType * @@ -176,6 +183,11 @@ public: */ Definition definitionForMimeType(const QString &mimeType) const; + /** + * Returns all Definition%s to the type named @p mimeType + */ + QVector definitionsForMimeType(const QString &mimeType) const; + /** * Returns all available Definition%s. * Definition%ss are ordered by translated section and translated names, -- cgit v1.2.3