Commit 86f9a2b7 authored by jkobus's avatar jkobus Committed by Jarek Kobus

Fix generic highlighter autotest

Change-Id: I35994a8c29374edfeb8a230af10c2a3277232f22
Reviewed-by: default avatarChristian Stenger <christian.stenger@digia.com>
Reviewed-by: default avatarChristian Kandeler <christian.kandeler@digia.com>
parent 513b884d
......@@ -46,6 +46,7 @@
#include <texteditor/fontsettings.h>
#include <texteditor/displaysettings.h>
#include <texteditor/generichighlighter/highlighter.h>
#include <texteditor/generichighlighter/highlighterutils.h>
#include <coreplugin/icore.h>
#include <coreplugin/minisplitter.h>
......@@ -282,7 +283,7 @@ void MultiHighlighter::setDocuments(const QList<QPair<DiffEditorWidget::DiffFile
if (!highlighter) {
TextEditor::Highlighter *h = new TextEditor::Highlighter();
highlighter = h;
h->setMimeType(mimeType);
setMimeTypeForHighlighter(h, mimeType);
highlighter->setDocument(document);
}
m_documents.append(document);
......
......@@ -35,9 +35,7 @@
#include "highlighterexception.h"
#include "progressdata.h"
#include "reuse.h"
#include "tabsettings.h"
#include "manager.h"
#include <coreplugin/icore.h>
#include <texteditor/tabsettings.h>
#include <QLatin1String>
#include <QLatin1Char>
......@@ -119,40 +117,6 @@ void Highlighter::setDefaultContext(const QSharedPointer<Context> &defaultContex
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)
{
m_tabSettings = &ts;
......
......@@ -32,6 +32,9 @@
#include <texteditor/basetextdocumentlayout.h>
#include <texteditor/syntaxhighlighter.h>
#include <texteditor/texteditor_global.h>
#include "context.h"
#include <QString>
#include <QVector>
......@@ -41,16 +44,12 @@
#include <QTextCharFormat>
namespace Core {
class MimeType;
}
namespace TextEditor {
class TabSettings;
namespace Internal {
class Rule;
class Context;
class HighlightDefinition;
class ProgressData;
......@@ -83,9 +82,7 @@ public:
};
void setTabSettings(const TabSettings &ts);
void setMimeType(const Core::MimeType &mimeType);
static QString findDefinitionId(const Core::MimeType &mimeType, bool considerParents);
void setDefaultContext(const QSharedPointer<Internal::Context> &defaultContext);
protected:
virtual void highlightBlock(const QString &text);
......@@ -104,7 +101,6 @@ private:
const bool childRule,
const QList<QSharedPointer<Internal::Rule> > &rules);
void setDefaultContext(const QSharedPointer<Internal::Context> &defaultContext);
void assignCurrentContext();
bool contextChangeRequired(const QString &contextName) const;
void handleContextChange(const QString &contextName,
......
/****************************************************************************
**
** 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());
}
}
}
/****************************************************************************
**
** 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 "context.h"
#include "normalindenter.h"
#include "generichighlighter/highlighterutils.h"
#include <coreplugin/coreconstants.h>
#include <coreplugin/icore.h>
......@@ -125,13 +126,13 @@ void PlainTextEditorWidget::configure(const Core::MimeType &mimeType)
if (!mimeType.isNull()) {
m_isMissingSyntaxDefinition = true;
highlighter->setMimeType(mimeType);
setMimeTypeForHighlighter(highlighter, mimeType);
const QString &type = mimeType.type();
setMimeType(type);
QString definitionId = Manager::instance()->definitionIdByMimeType(type);
if (definitionId.isEmpty())
definitionId = Highlighter::findDefinitionId(mimeType, true);
definitionId = findDefinitionId(mimeType, true);
if (!definitionId.isEmpty()) {
m_isMissingSyntaxDefinition = false;
......
......@@ -57,6 +57,7 @@ SOURCES += texteditorplugin.cpp \
generichighlighter/highlightersettings.cpp \
generichighlighter/managedefinitionsdialog.cpp \
generichighlighter/definitiondownloader.cpp \
generichighlighter/highlighterutils.cpp \
refactoringchanges.cpp \
refactoroverlay.cpp \
outlinefactory.cpp \
......@@ -168,6 +169,7 @@ HEADERS += texteditorplugin.h \
generichighlighter/managedefinitionsdialog.h \
generichighlighter/highlightdefinitionmetadata.h \
generichighlighter/definitiondownloader.h \
generichighlighter/highlighterutils.h \
refactoringchanges.h \
refactoroverlay.h \
outlinefactory.h \
......
......@@ -223,6 +223,8 @@ QtcPlugin {
"highlightersettingspage.cpp",
"highlightersettingspage.h",
"highlightersettingspage.ui",
"highlighterutils.cpp",
"highlighterutils.h",
"includerulesinstruction.cpp",
"includerulesinstruction.h",
"itemdata.cpp",
......
include(../../qttest.pri)
QT += gui
PLUGINSDIR = $$IDE_SOURCE_TREE/src/plugins
GENERICHIGHLIGHTERDIR = $$PLUGINSDIR/texteditor/generichighlighter
......@@ -8,7 +7,7 @@ SOURCES += \
tst_highlighterengine.cpp \
highlightermock.cpp \
formats.cpp \
syntaxhighlighter.cpp \
texteditor/syntaxhighlighter.cpp \
$$GENERICHIGHLIGHTERDIR/highlighter.cpp \
$$GENERICHIGHLIGHTERDIR/context.cpp \
$$GENERICHIGHLIGHTERDIR/dynamicrule.cpp \
......@@ -21,10 +20,10 @@ SOURCES += \
HEADERS += \
highlightermock.h \
basetextdocumentlayout.h \
formats.h \
tabsettings.h \
syntaxhighlighter.h \
texteditor/basetextdocumentlayout.h \
texteditor/syntaxhighlighter.h \
texteditor/tabsettings.h \
$$GENERICHIGHLIGHTERDIR/highlighter.h \
$$GENERICHIGHLIGHTERDIR/context.h \
$$GENERICHIGHLIGHTERDIR/dynamicrule.h \
......@@ -35,4 +34,4 @@ HEADERS += \
$$GENERICHIGHLIGHTERDIR/keywordlist.h \
$$GENERICHIGHLIGHTERDIR/itemdata.h
INCLUDEPATH += $$GENERICHIGHLIGHTERDIR $$PWD
INCLUDEPATH += $$PWD $$GENERICHIGHLIGHTERDIR
......@@ -58,7 +58,7 @@ struct HighlightSequence
QList<QTextCharFormat> m_formats;
};
class HighlighterMock : public TextEditor::Internal::Highlighter
class HighlighterMock : public TextEditor::Highlighter
{
public:
HighlighterMock(QTextDocument *parent = 0);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment