diff options
author | David Schulz <david.schulz@qt.io> | 2018-11-08 11:39:48 +0100 |
---|---|---|
committer | David Schulz <david.schulz@qt.io> | 2019-01-28 11:37:08 +0000 |
commit | 14834e6b0a4e7c1272ec3a1838b0634dd66e72ea (patch) | |
tree | 23caed8a748c0d38c59e1f92b448551122d11df2 /src/plugins/texteditor/generichighlighter/highlightersettings.cpp | |
parent | 1c77d7e1a79f59485eb90c066d17ec7436f46a93 (diff) |
TextEditor: replace generic highlighter with ksyntaxhighlighting
Fixes: QTCREATORBUG-21029
Change-Id: I9894c4384e0e47da6bf030b7b8e07c3ad4737ff3
Reviewed-by: Orgad Shaneh <orgads@gmail.com>
Diffstat (limited to 'src/plugins/texteditor/generichighlighter/highlightersettings.cpp')
-rw-r--r-- | src/plugins/texteditor/generichighlighter/highlightersettings.cpp | 223 |
1 files changed, 0 insertions, 223 deletions
diff --git a/src/plugins/texteditor/generichighlighter/highlightersettings.cpp b/src/plugins/texteditor/generichighlighter/highlightersettings.cpp deleted file mode 100644 index f0a00d3bc8..0000000000 --- a/src/plugins/texteditor/generichighlighter/highlightersettings.cpp +++ /dev/null @@ -1,223 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of Qt Creator. -** -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3 as published by the Free Software -** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-3.0.html. -** -****************************************************************************/ - -#include "highlightersettings.h" - -#include <coreplugin/icore.h> -#include <utils/hostosinfo.h> -#include <utils/synchronousprocess.h> - -#include <QSettings> -#include <QLatin1String> -#include <QLatin1Char> -#include <QDir> -#include <QFile> -#include <QStringList> - -namespace TextEditor { -namespace Internal { - -QString findFallbackDefinitionsLocation() -{ - QDir dir; - dir.setNameFilters(QStringList(QLatin1String("*.xml"))); - - if (Utils::HostOsInfo::isAnyUnixHost() && !Utils::HostOsInfo::isMacHost()) { - static const QLatin1String kateSyntaxPaths[] = { - QLatin1String("/share/apps/katepart/syntax"), - QLatin1String("/share/kde4/apps/katepart/syntax") - }; - - // Some wild guesses. - for (const auto &kateSyntaxPath : kateSyntaxPaths) { - const QStringList paths = { - QLatin1String("/usr") + kateSyntaxPath, - QLatin1String("/usr/local") + kateSyntaxPath, - QLatin1String("/opt") + kateSyntaxPath - }; - for (const auto &path : paths) { - dir.setPath(path); - if (dir.exists() && !dir.entryInfoList().isEmpty()) - return dir.path(); - } - } - - // Try kde-config. - const QStringList programs = {QLatin1String("kde-config"), QLatin1String("kde4-config")}; - for (auto &program : programs) { - Utils::SynchronousProcess process; - process.setTimeoutS(5); - Utils::SynchronousProcessResponse response - = process.runBlocking(program, QStringList(QLatin1String("--prefix"))); - if (response.result == Utils::SynchronousProcessResponse::Finished) { - QString output = response.stdOut(); - output.remove(QLatin1Char('\n')); - for (auto &kateSyntaxPath : kateSyntaxPaths) { - dir.setPath(output + kateSyntaxPath); - if (dir.exists() && !dir.entryInfoList().isEmpty()) - return dir.path(); - } - } - } - } - - dir.setPath(Core::ICore::resourcePath() + QLatin1String("/generic-highlighter")); - if (dir.exists() && !dir.entryInfoList().isEmpty()) - return dir.path(); - - return QString(); -} - -} // namespace Internal -} // namespace TextEditor - -namespace { - -static const QLatin1String kDefinitionFilesPath("UserDefinitionFilesPath"); -static const QLatin1String kFallbackDefinitionFilesPath("FallbackDefinitionFilesPath"); -static const QLatin1String kUseFallbackLocation("UseFallbackLocation"); -static const QLatin1String kIgnoredFilesPatterns("IgnoredFilesPatterns"); -static const QLatin1String kGroupPostfix("HighlighterSettings"); - -QString groupSpecifier(const QString &postFix, const QString &category) -{ - if (category.isEmpty()) - return postFix; - return QString(category + postFix); -} - -} // namespace anonymous - -using namespace TextEditor; -using namespace Internal; - -HighlighterSettings::HighlighterSettings() : - m_useFallbackLocation(true) -{} - -void HighlighterSettings::toSettings(const QString &category, QSettings *s) const -{ - const QString &group = groupSpecifier(kGroupPostfix, category); - s->beginGroup(group); - s->setValue(kDefinitionFilesPath, m_definitionFilesPath); - s->setValue(kFallbackDefinitionFilesPath, m_fallbackDefinitionFilesPath); - s->setValue(kUseFallbackLocation, m_useFallbackLocation); - s->setValue(kIgnoredFilesPatterns, ignoredFilesPatterns()); - s->endGroup(); -} - -void HighlighterSettings::fromSettings(const QString &category, QSettings *s) -{ - const QString &group = groupSpecifier(kGroupPostfix, category); - s->beginGroup(group); - m_definitionFilesPath = s->value(kDefinitionFilesPath, QString()).toString(); - if (!s->contains(kDefinitionFilesPath)) - assignDefaultDefinitionsPath(); - else - m_definitionFilesPath = s->value(kDefinitionFilesPath).toString(); - if (!s->contains(kFallbackDefinitionFilesPath)) { - m_fallbackDefinitionFilesPath = findFallbackDefinitionsLocation(); - if (m_fallbackDefinitionFilesPath.isEmpty()) - m_useFallbackLocation = false; - else - m_useFallbackLocation = true; - } else { - m_fallbackDefinitionFilesPath = s->value(kFallbackDefinitionFilesPath).toString(); - m_useFallbackLocation = s->value(kUseFallbackLocation, true).toBool(); - } - if (!s->contains(kIgnoredFilesPatterns)) - assignDefaultIgnoredPatterns(); - else - setIgnoredFilesPatterns(s->value(kIgnoredFilesPatterns, QString()).toString()); - s->endGroup(); -} - -void HighlighterSettings::setIgnoredFilesPatterns(const QString &patterns) -{ - setExpressionsFromList(patterns.split(QLatin1Char(','), QString::SkipEmptyParts)); -} - -QString HighlighterSettings::ignoredFilesPatterns() const -{ - return listFromExpressions().join(QLatin1Char(',')); -} - -void HighlighterSettings::assignDefaultIgnoredPatterns() -{ - QStringList patterns; - patterns << QLatin1String("*.txt") - << QLatin1String("LICENSE*") - << QLatin1String("README") - << QLatin1String("INSTALL") - << QLatin1String("COPYING") - << QLatin1String("NEWS") - << QLatin1String("qmldir"); - setExpressionsFromList(patterns); -} - -void HighlighterSettings::assignDefaultDefinitionsPath() -{ - const QString &path = - Core::ICore::userResourcePath() + QLatin1String("/generic-highlighter"); - if (QFile::exists(path) || QDir().mkpath(path)) - m_definitionFilesPath = path; -} - -bool HighlighterSettings::isIgnoredFilePattern(const QString &fileName) const -{ - for (auto ®Exp : m_ignoredFiles) - if (regExp.indexIn(fileName) != -1) - return true; - - return false; -} - -bool HighlighterSettings::equals(const HighlighterSettings &highlighterSettings) const -{ - return m_definitionFilesPath == highlighterSettings.m_definitionFilesPath && - m_fallbackDefinitionFilesPath == highlighterSettings.m_fallbackDefinitionFilesPath && - m_useFallbackLocation == highlighterSettings.m_useFallbackLocation && - m_ignoredFiles == highlighterSettings.m_ignoredFiles; -} - -void HighlighterSettings::setExpressionsFromList(const QStringList &patterns) -{ - m_ignoredFiles.clear(); - QRegExp regExp; - regExp.setCaseSensitivity(Qt::CaseInsensitive); - regExp.setPatternSyntax(QRegExp::Wildcard); - for (auto &pattern : patterns) { - regExp.setPattern(pattern); - m_ignoredFiles.append(regExp); - } -} - -QStringList HighlighterSettings::listFromExpressions() const -{ - QStringList patterns; - foreach (const QRegExp ®Exp, m_ignoredFiles) - patterns.append(regExp.pattern()); - return patterns; -} |