forked from qt-creator/qt-creator
Fix generic highlighter autotest
Change-Id: I35994a8c29374edfeb8a230af10c2a3277232f22 Reviewed-by: Christian Stenger <christian.stenger@digia.com> Reviewed-by: Christian Kandeler <christian.kandeler@digia.com>
This commit is contained in:
@@ -46,6 +46,7 @@
|
|||||||
#include <texteditor/fontsettings.h>
|
#include <texteditor/fontsettings.h>
|
||||||
#include <texteditor/displaysettings.h>
|
#include <texteditor/displaysettings.h>
|
||||||
#include <texteditor/generichighlighter/highlighter.h>
|
#include <texteditor/generichighlighter/highlighter.h>
|
||||||
|
#include <texteditor/generichighlighter/highlighterutils.h>
|
||||||
|
|
||||||
#include <coreplugin/icore.h>
|
#include <coreplugin/icore.h>
|
||||||
#include <coreplugin/minisplitter.h>
|
#include <coreplugin/minisplitter.h>
|
||||||
@@ -282,7 +283,7 @@ void MultiHighlighter::setDocuments(const QList<QPair<DiffEditorWidget::DiffFile
|
|||||||
if (!highlighter) {
|
if (!highlighter) {
|
||||||
TextEditor::Highlighter *h = new TextEditor::Highlighter();
|
TextEditor::Highlighter *h = new TextEditor::Highlighter();
|
||||||
highlighter = h;
|
highlighter = h;
|
||||||
h->setMimeType(mimeType);
|
setMimeTypeForHighlighter(h, mimeType);
|
||||||
highlighter->setDocument(document);
|
highlighter->setDocument(document);
|
||||||
}
|
}
|
||||||
m_documents.append(document);
|
m_documents.append(document);
|
||||||
|
|||||||
@@ -35,9 +35,7 @@
|
|||||||
#include "highlighterexception.h"
|
#include "highlighterexception.h"
|
||||||
#include "progressdata.h"
|
#include "progressdata.h"
|
||||||
#include "reuse.h"
|
#include "reuse.h"
|
||||||
#include "tabsettings.h"
|
#include <texteditor/tabsettings.h>
|
||||||
#include "manager.h"
|
|
||||||
#include <coreplugin/icore.h>
|
|
||||||
|
|
||||||
#include <QLatin1String>
|
#include <QLatin1String>
|
||||||
#include <QLatin1Char>
|
#include <QLatin1Char>
|
||||||
@@ -119,40 +117,6 @@ void Highlighter::setDefaultContext(const QSharedPointer<Context> &defaultContex
|
|||||||
m_indentationBasedFolding = defaultContext->definition()->isIndentationBasedFolding();
|
m_indentationBasedFolding = defaultContext->definition()->isIndentationBasedFolding();
|
||||||
}
|
}
|
||||||
|
|
||||||
QString Highlighter::findDefinitionId(const Core::MimeType &mimeType,
|
|
||||||
bool considerParents)
|
|
||||||
{
|
|
||||||
QString definitionId = Manager::instance()->definitionIdByAnyMimeType(mimeType.aliases());
|
|
||||||
if (definitionId.isEmpty() && considerParents) {
|
|
||||||
definitionId = Manager::instance()->definitionIdByAnyMimeType(mimeType.subClassesOf());
|
|
||||||
if (definitionId.isEmpty()) {
|
|
||||||
foreach (const QString &parent, mimeType.subClassesOf()) {
|
|
||||||
const Core::MimeType &parentMimeType =
|
|
||||||
Core::ICore::mimeDatabase()->findByType(parent);
|
|
||||||
definitionId = findDefinitionId(parentMimeType, considerParents);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return definitionId;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Highlighter::setMimeType(const Core::MimeType &mimeType)
|
|
||||||
{
|
|
||||||
const QString type = mimeType.type();
|
|
||||||
QString definitionId = Manager::instance()->definitionIdByMimeType(type);
|
|
||||||
if (definitionId.isEmpty())
|
|
||||||
definitionId = findDefinitionId(mimeType, true);
|
|
||||||
|
|
||||||
if (!definitionId.isEmpty()) {
|
|
||||||
const QSharedPointer<HighlightDefinition> &definition =
|
|
||||||
Manager::instance()->definition(definitionId);
|
|
||||||
if (!definition.isNull() && definition->isValid()) {
|
|
||||||
setDefaultContext(definition->initialContext());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
void Highlighter::setTabSettings(const TabSettings &ts)
|
void Highlighter::setTabSettings(const TabSettings &ts)
|
||||||
{
|
{
|
||||||
m_tabSettings = &ts;
|
m_tabSettings = &ts;
|
||||||
|
|||||||
@@ -32,6 +32,9 @@
|
|||||||
|
|
||||||
#include <texteditor/basetextdocumentlayout.h>
|
#include <texteditor/basetextdocumentlayout.h>
|
||||||
#include <texteditor/syntaxhighlighter.h>
|
#include <texteditor/syntaxhighlighter.h>
|
||||||
|
#include <texteditor/texteditor_global.h>
|
||||||
|
|
||||||
|
#include "context.h"
|
||||||
|
|
||||||
#include <QString>
|
#include <QString>
|
||||||
#include <QVector>
|
#include <QVector>
|
||||||
@@ -41,16 +44,12 @@
|
|||||||
|
|
||||||
#include <QTextCharFormat>
|
#include <QTextCharFormat>
|
||||||
|
|
||||||
namespace Core {
|
|
||||||
class MimeType;
|
|
||||||
}
|
|
||||||
namespace TextEditor {
|
namespace TextEditor {
|
||||||
|
|
||||||
class TabSettings;
|
class TabSettings;
|
||||||
namespace Internal {
|
namespace Internal {
|
||||||
|
|
||||||
class Rule;
|
class Rule;
|
||||||
class Context;
|
|
||||||
class HighlightDefinition;
|
class HighlightDefinition;
|
||||||
class ProgressData;
|
class ProgressData;
|
||||||
|
|
||||||
@@ -83,9 +82,7 @@ public:
|
|||||||
};
|
};
|
||||||
|
|
||||||
void setTabSettings(const TabSettings &ts);
|
void setTabSettings(const TabSettings &ts);
|
||||||
void setMimeType(const Core::MimeType &mimeType);
|
void setDefaultContext(const QSharedPointer<Internal::Context> &defaultContext);
|
||||||
|
|
||||||
static QString findDefinitionId(const Core::MimeType &mimeType, bool considerParents);
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual void highlightBlock(const QString &text);
|
virtual void highlightBlock(const QString &text);
|
||||||
@@ -104,7 +101,6 @@ private:
|
|||||||
const bool childRule,
|
const bool childRule,
|
||||||
const QList<QSharedPointer<Internal::Rule> > &rules);
|
const QList<QSharedPointer<Internal::Rule> > &rules);
|
||||||
|
|
||||||
void setDefaultContext(const QSharedPointer<Internal::Context> &defaultContext);
|
|
||||||
void assignCurrentContext();
|
void assignCurrentContext();
|
||||||
bool contextChangeRequired(const QString &contextName) const;
|
bool contextChangeRequired(const QString &contextName) const;
|
||||||
void handleContextChange(const QString &contextName,
|
void handleContextChange(const QString &contextName,
|
||||||
|
|||||||
@@ -0,0 +1,71 @@
|
|||||||
|
/****************************************************************************
|
||||||
|
**
|
||||||
|
** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
|
||||||
|
** Contact: http://www.qt-project.org/legal
|
||||||
|
**
|
||||||
|
** 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 Digia. For licensing terms and
|
||||||
|
** conditions see http://qt.digia.com/licensing. For further information
|
||||||
|
** use the contact form at http://qt.digia.com/contact-us.
|
||||||
|
**
|
||||||
|
** GNU Lesser General Public License Usage
|
||||||
|
** Alternatively, this file may be used under the terms of the GNU Lesser
|
||||||
|
** General Public License version 2.1 as published by the Free Software
|
||||||
|
** Foundation and appearing in the file LICENSE.LGPL included in the
|
||||||
|
** packaging of this file. Please review the following information to
|
||||||
|
** ensure the GNU Lesser General Public License version 2.1 requirements
|
||||||
|
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
||||||
|
**
|
||||||
|
** In addition, as a special exception, Digia gives you certain additional
|
||||||
|
** rights. These rights are described in the Digia Qt LGPL Exception
|
||||||
|
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
||||||
|
**
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
#include "highlighterutils.h"
|
||||||
|
#include "highlighter.h"
|
||||||
|
#include "highlightdefinition.h"
|
||||||
|
#include "manager.h"
|
||||||
|
#include <coreplugin/icore.h>
|
||||||
|
|
||||||
|
using namespace TextEditor;
|
||||||
|
using namespace Internal;
|
||||||
|
|
||||||
|
QString TextEditor::findDefinitionId(const Core::MimeType &mimeType,
|
||||||
|
bool considerParents)
|
||||||
|
{
|
||||||
|
QString definitionId = Manager::instance()->definitionIdByAnyMimeType(mimeType.aliases());
|
||||||
|
if (definitionId.isEmpty() && considerParents) {
|
||||||
|
definitionId = Manager::instance()->definitionIdByAnyMimeType(mimeType.subClassesOf());
|
||||||
|
if (definitionId.isEmpty()) {
|
||||||
|
foreach (const QString &parent, mimeType.subClassesOf()) {
|
||||||
|
const Core::MimeType &parentMimeType =
|
||||||
|
Core::ICore::mimeDatabase()->findByType(parent);
|
||||||
|
definitionId = findDefinitionId(parentMimeType, considerParents);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return definitionId;
|
||||||
|
}
|
||||||
|
|
||||||
|
void TextEditor::setMimeTypeForHighlighter(Highlighter *highlighter, const Core::MimeType &mimeType)
|
||||||
|
{
|
||||||
|
const QString type = mimeType.type();
|
||||||
|
QString definitionId = Manager::instance()->definitionIdByMimeType(type);
|
||||||
|
if (definitionId.isEmpty())
|
||||||
|
definitionId = findDefinitionId(mimeType, true);
|
||||||
|
|
||||||
|
if (!definitionId.isEmpty()) {
|
||||||
|
const QSharedPointer<HighlightDefinition> &definition =
|
||||||
|
Manager::instance()->definition(definitionId);
|
||||||
|
if (!definition.isNull() && definition->isValid()) {
|
||||||
|
highlighter->setDefaultContext(definition->initialContext());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
53
src/plugins/texteditor/generichighlighter/highlighterutils.h
Normal file
53
src/plugins/texteditor/generichighlighter/highlighterutils.h
Normal file
@@ -0,0 +1,53 @@
|
|||||||
|
/****************************************************************************
|
||||||
|
**
|
||||||
|
** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
|
||||||
|
** Contact: http://www.qt-project.org/legal
|
||||||
|
**
|
||||||
|
** 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 Digia. For licensing terms and
|
||||||
|
** conditions see http://qt.digia.com/licensing. For further information
|
||||||
|
** use the contact form at http://qt.digia.com/contact-us.
|
||||||
|
**
|
||||||
|
** GNU Lesser General Public License Usage
|
||||||
|
** Alternatively, this file may be used under the terms of the GNU Lesser
|
||||||
|
** General Public License version 2.1 as published by the Free Software
|
||||||
|
** Foundation and appearing in the file LICENSE.LGPL included in the
|
||||||
|
** packaging of this file. Please review the following information to
|
||||||
|
** ensure the GNU Lesser General Public License version 2.1 requirements
|
||||||
|
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
||||||
|
**
|
||||||
|
** In addition, as a special exception, Digia gives you certain additional
|
||||||
|
** rights. These rights are described in the Digia Qt LGPL Exception
|
||||||
|
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
||||||
|
**
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
#ifndef HIGHLIGHTERUTILS_H
|
||||||
|
#define HIGHLIGHTERUTILS_H
|
||||||
|
|
||||||
|
#include <QString>
|
||||||
|
#include <texteditor/texteditor_global.h>
|
||||||
|
|
||||||
|
/* These methods were originally a part of TextEditor::Highlighter,
|
||||||
|
* but due to a very hackish test of that generic highlighter,
|
||||||
|
* there methods must be outside. */
|
||||||
|
|
||||||
|
namespace Core {
|
||||||
|
class MimeType;
|
||||||
|
}
|
||||||
|
|
||||||
|
namespace TextEditor {
|
||||||
|
|
||||||
|
class Highlighter;
|
||||||
|
|
||||||
|
void TEXTEDITOR_EXPORT setMimeTypeForHighlighter(Highlighter *highlighter, const Core::MimeType &mimeType);
|
||||||
|
QString TEXTEDITOR_EXPORT findDefinitionId(const Core::MimeType &mimeType, bool considerParents);
|
||||||
|
|
||||||
|
} // namespace TextEditor
|
||||||
|
|
||||||
|
#endif // HIGHLIGHTERUTILS_H
|
||||||
@@ -38,6 +38,7 @@
|
|||||||
#include "manager.h"
|
#include "manager.h"
|
||||||
#include "context.h"
|
#include "context.h"
|
||||||
#include "normalindenter.h"
|
#include "normalindenter.h"
|
||||||
|
#include "generichighlighter/highlighterutils.h"
|
||||||
|
|
||||||
#include <coreplugin/coreconstants.h>
|
#include <coreplugin/coreconstants.h>
|
||||||
#include <coreplugin/icore.h>
|
#include <coreplugin/icore.h>
|
||||||
@@ -125,13 +126,13 @@ void PlainTextEditorWidget::configure(const Core::MimeType &mimeType)
|
|||||||
if (!mimeType.isNull()) {
|
if (!mimeType.isNull()) {
|
||||||
m_isMissingSyntaxDefinition = true;
|
m_isMissingSyntaxDefinition = true;
|
||||||
|
|
||||||
highlighter->setMimeType(mimeType);
|
setMimeTypeForHighlighter(highlighter, mimeType);
|
||||||
const QString &type = mimeType.type();
|
const QString &type = mimeType.type();
|
||||||
setMimeType(type);
|
setMimeType(type);
|
||||||
|
|
||||||
QString definitionId = Manager::instance()->definitionIdByMimeType(type);
|
QString definitionId = Manager::instance()->definitionIdByMimeType(type);
|
||||||
if (definitionId.isEmpty())
|
if (definitionId.isEmpty())
|
||||||
definitionId = Highlighter::findDefinitionId(mimeType, true);
|
definitionId = findDefinitionId(mimeType, true);
|
||||||
|
|
||||||
if (!definitionId.isEmpty()) {
|
if (!definitionId.isEmpty()) {
|
||||||
m_isMissingSyntaxDefinition = false;
|
m_isMissingSyntaxDefinition = false;
|
||||||
|
|||||||
@@ -57,6 +57,7 @@ SOURCES += texteditorplugin.cpp \
|
|||||||
generichighlighter/highlightersettings.cpp \
|
generichighlighter/highlightersettings.cpp \
|
||||||
generichighlighter/managedefinitionsdialog.cpp \
|
generichighlighter/managedefinitionsdialog.cpp \
|
||||||
generichighlighter/definitiondownloader.cpp \
|
generichighlighter/definitiondownloader.cpp \
|
||||||
|
generichighlighter/highlighterutils.cpp \
|
||||||
refactoringchanges.cpp \
|
refactoringchanges.cpp \
|
||||||
refactoroverlay.cpp \
|
refactoroverlay.cpp \
|
||||||
outlinefactory.cpp \
|
outlinefactory.cpp \
|
||||||
@@ -168,6 +169,7 @@ HEADERS += texteditorplugin.h \
|
|||||||
generichighlighter/managedefinitionsdialog.h \
|
generichighlighter/managedefinitionsdialog.h \
|
||||||
generichighlighter/highlightdefinitionmetadata.h \
|
generichighlighter/highlightdefinitionmetadata.h \
|
||||||
generichighlighter/definitiondownloader.h \
|
generichighlighter/definitiondownloader.h \
|
||||||
|
generichighlighter/highlighterutils.h \
|
||||||
refactoringchanges.h \
|
refactoringchanges.h \
|
||||||
refactoroverlay.h \
|
refactoroverlay.h \
|
||||||
outlinefactory.h \
|
outlinefactory.h \
|
||||||
|
|||||||
@@ -223,6 +223,8 @@ QtcPlugin {
|
|||||||
"highlightersettingspage.cpp",
|
"highlightersettingspage.cpp",
|
||||||
"highlightersettingspage.h",
|
"highlightersettingspage.h",
|
||||||
"highlightersettingspage.ui",
|
"highlightersettingspage.ui",
|
||||||
|
"highlighterutils.cpp",
|
||||||
|
"highlighterutils.h",
|
||||||
"includerulesinstruction.cpp",
|
"includerulesinstruction.cpp",
|
||||||
"includerulesinstruction.h",
|
"includerulesinstruction.h",
|
||||||
"itemdata.cpp",
|
"itemdata.cpp",
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
include(../../qttest.pri)
|
include(../../qttest.pri)
|
||||||
QT += gui
|
QT += gui
|
||||||
|
|
||||||
PLUGINSDIR = $$IDE_SOURCE_TREE/src/plugins
|
PLUGINSDIR = $$IDE_SOURCE_TREE/src/plugins
|
||||||
GENERICHIGHLIGHTERDIR = $$PLUGINSDIR/texteditor/generichighlighter
|
GENERICHIGHLIGHTERDIR = $$PLUGINSDIR/texteditor/generichighlighter
|
||||||
|
|
||||||
@@ -8,7 +7,7 @@ SOURCES += \
|
|||||||
tst_highlighterengine.cpp \
|
tst_highlighterengine.cpp \
|
||||||
highlightermock.cpp \
|
highlightermock.cpp \
|
||||||
formats.cpp \
|
formats.cpp \
|
||||||
syntaxhighlighter.cpp \
|
texteditor/syntaxhighlighter.cpp \
|
||||||
$$GENERICHIGHLIGHTERDIR/highlighter.cpp \
|
$$GENERICHIGHLIGHTERDIR/highlighter.cpp \
|
||||||
$$GENERICHIGHLIGHTERDIR/context.cpp \
|
$$GENERICHIGHLIGHTERDIR/context.cpp \
|
||||||
$$GENERICHIGHLIGHTERDIR/dynamicrule.cpp \
|
$$GENERICHIGHLIGHTERDIR/dynamicrule.cpp \
|
||||||
@@ -21,10 +20,10 @@ SOURCES += \
|
|||||||
|
|
||||||
HEADERS += \
|
HEADERS += \
|
||||||
highlightermock.h \
|
highlightermock.h \
|
||||||
basetextdocumentlayout.h \
|
|
||||||
formats.h \
|
formats.h \
|
||||||
tabsettings.h \
|
texteditor/basetextdocumentlayout.h \
|
||||||
syntaxhighlighter.h \
|
texteditor/syntaxhighlighter.h \
|
||||||
|
texteditor/tabsettings.h \
|
||||||
$$GENERICHIGHLIGHTERDIR/highlighter.h \
|
$$GENERICHIGHLIGHTERDIR/highlighter.h \
|
||||||
$$GENERICHIGHLIGHTERDIR/context.h \
|
$$GENERICHIGHLIGHTERDIR/context.h \
|
||||||
$$GENERICHIGHLIGHTERDIR/dynamicrule.h \
|
$$GENERICHIGHLIGHTERDIR/dynamicrule.h \
|
||||||
@@ -35,4 +34,4 @@ HEADERS += \
|
|||||||
$$GENERICHIGHLIGHTERDIR/keywordlist.h \
|
$$GENERICHIGHLIGHTERDIR/keywordlist.h \
|
||||||
$$GENERICHIGHLIGHTERDIR/itemdata.h
|
$$GENERICHIGHLIGHTERDIR/itemdata.h
|
||||||
|
|
||||||
INCLUDEPATH += $$GENERICHIGHLIGHTERDIR $$PWD
|
INCLUDEPATH += $$PWD $$GENERICHIGHLIGHTERDIR
|
||||||
|
|||||||
@@ -58,7 +58,7 @@ struct HighlightSequence
|
|||||||
QList<QTextCharFormat> m_formats;
|
QList<QTextCharFormat> m_formats;
|
||||||
};
|
};
|
||||||
|
|
||||||
class HighlighterMock : public TextEditor::Internal::Highlighter
|
class HighlighterMock : public TextEditor::Highlighter
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
HighlighterMock(QTextDocument *parent = 0);
|
HighlighterMock(QTextDocument *parent = 0);
|
||||||
|
|||||||
Reference in New Issue
Block a user