summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjkobus <jaroslaw.kobus@digia.com>2013-08-14 13:52:13 +0200
committerJarek Kobus <jaroslaw.kobus@digia.com>2013-08-29 08:54:04 +0200
commit33a7952745571576fb955fd33bc96e86f0e456fd (patch)
treee9eae74813d85ce1bcb75fbe73d9d4916ce62531
parenta06da47d5b74f9d680b2201e218c1df87f023faa (diff)
downloadqt-creator-33a7952745571576fb955fd33bc96e86f0e456fd.tar.gz
Implement syntax highlighting in diff editor
All Qt Creator's main highlighters are used in the first place, for other mimetypes generic highlighter is used as a fallback. Task-number: QTCREATORBUG-9580 Change-Id: I863b9085520e5bdda142ce88f2074afeacee0531 Reviewed-by: Orgad Shaneh <orgads@gmail.com> Reviewed-by: Petar Perisin <petar.perisin@gmail.com> Reviewed-by: Jarek Kobus <jaroslaw.kobus@digia.com>
-rw-r--r--src/plugins/cmakeprojectmanager/cmakehighlighterfactory.cpp45
-rw-r--r--src/plugins/cmakeprojectmanager/cmakehighlighterfactory.h51
-rw-r--r--src/plugins/cmakeprojectmanager/cmakeprojectmanager.pro2
-rw-r--r--src/plugins/cmakeprojectmanager/cmakeprojectmanager.qbs2
-rw-r--r--src/plugins/cmakeprojectmanager/cmakeprojectplugin.cpp2
-rw-r--r--src/plugins/cppeditor/cppeditor.pro2
-rw-r--r--src/plugins/cppeditor/cppeditor.qbs2
-rw-r--r--src/plugins/cppeditor/cppeditorplugin.cpp2
-rw-r--r--src/plugins/cppeditor/cpphighlighterfactory.cpp48
-rw-r--r--src/plugins/cppeditor/cpphighlighterfactory.h51
-rw-r--r--src/plugins/diffeditor/diffeditorwidget.cpp196
-rw-r--r--src/plugins/diffeditor/diffeditorwidget.h5
-rw-r--r--src/plugins/glsleditor/glsleditor.pro2
-rw-r--r--src/plugins/glsleditor/glsleditor.qbs2
-rw-r--r--src/plugins/glsleditor/glsleditorplugin.cpp2
-rw-r--r--src/plugins/glsleditor/glslhighlighter.cpp11
-rw-r--r--src/plugins/glsleditor/glslhighlighter.h4
-rw-r--r--src/plugins/glsleditor/glslhighlighterfactory.cpp49
-rw-r--r--src/plugins/glsleditor/glslhighlighterfactory.h51
-rw-r--r--src/plugins/pythoneditor/pythoneditor.pro2
-rw-r--r--src/plugins/pythoneditor/pythoneditor.qbs1
-rw-r--r--src/plugins/pythoneditor/pythoneditorplugin.cpp2
-rw-r--r--src/plugins/pythoneditor/tools/pythonhighlighter.cpp11
-rw-r--r--src/plugins/pythoneditor/tools/pythonhighlighter.h2
-rw-r--r--src/plugins/pythoneditor/tools/pythonhighlighterfactory.cpp45
-rw-r--r--src/plugins/pythoneditor/tools/pythonhighlighterfactory.h51
-rw-r--r--src/plugins/qmljseditor/qmljseditor.pro2
-rw-r--r--src/plugins/qmljseditor/qmljseditor.qbs2
-rw-r--r--src/plugins/qmljseditor/qmljseditorplugin.cpp2
-rw-r--r--src/plugins/qmljseditor/qmljshighlighterfactory.cpp51
-rw-r--r--src/plugins/qmljseditor/qmljshighlighterfactory.h51
-rw-r--r--src/plugins/qt4projectmanager/profilehighlighterfactory.cpp47
-rw-r--r--src/plugins/qt4projectmanager/profilehighlighterfactory.h51
-rw-r--r--src/plugins/qt4projectmanager/qt4projectmanager.pro2
-rw-r--r--src/plugins/qt4projectmanager/qt4projectmanager.qbs1
-rw-r--r--src/plugins/qt4projectmanager/qt4projectmanagerplugin.cpp2
-rw-r--r--src/plugins/texteditor/generichighlighter/highlighter.cpp36
-rw-r--r--src/plugins/texteditor/generichighlighter/highlighter.h40
-rw-r--r--src/plugins/texteditor/ihighlighterfactory.h66
-rw-r--r--src/plugins/texteditor/plaintexteditor.cpp22
-rw-r--r--src/plugins/texteditor/plaintexteditor.h2
-rw-r--r--src/plugins/texteditor/texteditor.pro1
-rw-r--r--src/plugins/texteditor/texteditor.qbs1
43 files changed, 953 insertions, 69 deletions
diff --git a/src/plugins/cmakeprojectmanager/cmakehighlighterfactory.cpp b/src/plugins/cmakeprojectmanager/cmakehighlighterfactory.cpp
new file mode 100644
index 0000000000..1899afcf88
--- /dev/null
+++ b/src/plugins/cmakeprojectmanager/cmakehighlighterfactory.cpp
@@ -0,0 +1,45 @@
+/****************************************************************************
+**
+** 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 "cmakehighlighterfactory.h"
+#include "cmakeprojectconstants.h"
+#include "cmakehighlighter.h"
+
+using namespace CMakeProjectManager::Internal;
+
+CMakeHighlighterFactory::CMakeHighlighterFactory()
+{
+ setId(CMakeProjectManager::Constants::CMAKE_EDITOR_ID);
+ addMimeType(CMakeProjectManager::Constants::CMAKEMIMETYPE);
+}
+
+TextEditor::SyntaxHighlighter *CMakeHighlighterFactory::createHighlighter() const
+{
+ return new CMakeHighlighter;
+}
diff --git a/src/plugins/cmakeprojectmanager/cmakehighlighterfactory.h b/src/plugins/cmakeprojectmanager/cmakehighlighterfactory.h
new file mode 100644
index 0000000000..a6545022c6
--- /dev/null
+++ b/src/plugins/cmakeprojectmanager/cmakehighlighterfactory.h
@@ -0,0 +1,51 @@
+/****************************************************************************
+**
+** 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 CMAKEHIGHLIGHTERFACTORY_H
+#define CMAKEHIGHLIGHTERFACTORY_H
+
+#include <texteditor/ihighlighterfactory.h>
+
+namespace CMakeProjectManager {
+namespace Internal {
+
+class CMakeHighlighterFactory : public TextEditor::IHighlighterFactory
+{
+ Q_OBJECT
+
+public:
+ CMakeHighlighterFactory();
+
+ virtual TextEditor::SyntaxHighlighter *createHighlighter() const;
+};
+
+} // namespace Internal
+} // namespace CMakeProjectManager
+
+#endif // CMAKEHIGHLIGHTERFACTORY_H
diff --git a/src/plugins/cmakeprojectmanager/cmakeprojectmanager.pro b/src/plugins/cmakeprojectmanager/cmakeprojectmanager.pro
index e58bd7878d..49e87adffa 100644
--- a/src/plugins/cmakeprojectmanager/cmakeprojectmanager.pro
+++ b/src/plugins/cmakeprojectmanager/cmakeprojectmanager.pro
@@ -12,6 +12,7 @@ HEADERS = cmakeproject.h \
cmakeeditorfactory.h \
cmakeeditor.h \
cmakehighlighter.h \
+ cmakehighlighterfactory.h \
cmakelocatorfilter.h \
cmakefilecompletionassist.h \
cmakevalidator.h \
@@ -28,6 +29,7 @@ SOURCES = cmakeproject.cpp \
cmakeeditorfactory.cpp \
cmakeeditor.cpp \
cmakehighlighter.cpp \
+ cmakehighlighterfactory.cpp \
cmakelocatorfilter.cpp \
cmakefilecompletionassist.cpp \
cmakevalidator.cpp \
diff --git a/src/plugins/cmakeprojectmanager/cmakeprojectmanager.qbs b/src/plugins/cmakeprojectmanager/cmakeprojectmanager.qbs
index 52cc38ac7d..335ff10862 100644
--- a/src/plugins/cmakeprojectmanager/cmakeprojectmanager.qbs
+++ b/src/plugins/cmakeprojectmanager/cmakeprojectmanager.qbs
@@ -30,6 +30,8 @@ QtcPlugin {
"cmakefilecompletionassist.h",
"cmakehighlighter.cpp",
"cmakehighlighter.h",
+ "cmakehighlighterfactory.cpp",
+ "cmakehighlighterfactory.h",
"cmakelocatorfilter.cpp",
"cmakelocatorfilter.h",
"cmakeopenprojectwizard.cpp",
diff --git a/src/plugins/cmakeprojectmanager/cmakeprojectplugin.cpp b/src/plugins/cmakeprojectmanager/cmakeprojectplugin.cpp
index 5b96bb7eaf..3f06dab0ab 100644
--- a/src/plugins/cmakeprojectmanager/cmakeprojectplugin.cpp
+++ b/src/plugins/cmakeprojectmanager/cmakeprojectplugin.cpp
@@ -36,6 +36,7 @@
#include "cmakeprojectconstants.h"
#include "cmakelocatorfilter.h"
#include "cmakefilecompletionassist.h"
+#include "cmakehighlighterfactory.h"
#include <coreplugin/featureprovider.h>
#include <coreplugin/icore.h>
@@ -82,6 +83,7 @@ bool CMakeProjectPlugin::initialize(const QStringList & /*arguments*/, QString *
addAutoReleasedObject(new CMakeLocatorFilter);
addAutoReleasedObject(new CMakeFileCompletionAssistProvider(cmp));
addAutoReleasedObject(new CMakeFeatureProvider);
+ addAutoReleasedObject(new CMakeHighlighterFactory);
return true;
}
diff --git a/src/plugins/cppeditor/cppeditor.pro b/src/plugins/cppeditor/cppeditor.pro
index d646ca23b1..d715c81e16 100644
--- a/src/plugins/cppeditor/cppeditor.pro
+++ b/src/plugins/cppeditor/cppeditor.pro
@@ -11,6 +11,7 @@ HEADERS += cppeditorplugin.h \
cppfilewizard.h \
cppfunctiondecldeflink.h \
cpphighlighter.h \
+ cpphighlighterfactory.h \
cpphoverhandler.h \
cppoutline.h \
cppquickfixassistant.h \
@@ -27,6 +28,7 @@ SOURCES += cppeditorplugin.cpp \
cppfilewizard.cpp \
cppfunctiondecldeflink.cpp \
cpphighlighter.cpp \
+ cpphighlighterfactory.cpp \
cpphoverhandler.cpp \
cppoutline.cpp \
cppquickfixassistant.cpp \
diff --git a/src/plugins/cppeditor/cppeditor.qbs b/src/plugins/cppeditor/cppeditor.qbs
index 39533511cd..96e685b128 100644
--- a/src/plugins/cppeditor/cppeditor.qbs
+++ b/src/plugins/cppeditor/cppeditor.qbs
@@ -37,6 +37,8 @@ QtcPlugin {
"cppfunctiondecldeflink.h",
"cpphighlighter.cpp",
"cpphighlighter.h",
+ "cpphighlighterfactory.cpp",
+ "cpphighlighterfactory.h",
"cpphoverhandler.cpp",
"cpphoverhandler.h",
"cppoutline.cpp",
diff --git a/src/plugins/cppeditor/cppeditorplugin.cpp b/src/plugins/cppeditor/cppeditorplugin.cpp
index 8df51752aa..13e0bfb93c 100644
--- a/src/plugins/cppeditor/cppeditorplugin.cpp
+++ b/src/plugins/cppeditor/cppeditorplugin.cpp
@@ -39,6 +39,7 @@
#include "cppsnippetprovider.h"
#include "cppquickfixassistant.h"
#include "cppquickfixes.h"
+#include "cpphighlighterfactory.h"
#include <coreplugin/actionmanager/actioncontainer.h>
#include <coreplugin/actionmanager/actionmanager.h>
@@ -160,6 +161,7 @@ bool CppEditorPlugin::initialize(const QStringList & /*arguments*/, QString *err
addAutoReleasedObject(new CppOutlineWidgetFactory);
addAutoReleasedObject(new CppTypeHierarchyFactory);
addAutoReleasedObject(new CppSnippetProvider);
+ addAutoReleasedObject(new CppHighlighterFactory);
m_quickFixProvider = new CppQuickFixAssistProvider;
addAutoReleasedObject(m_quickFixProvider);
diff --git a/src/plugins/cppeditor/cpphighlighterfactory.cpp b/src/plugins/cppeditor/cpphighlighterfactory.cpp
new file mode 100644
index 0000000000..32af1d125e
--- /dev/null
+++ b/src/plugins/cppeditor/cpphighlighterfactory.cpp
@@ -0,0 +1,48 @@
+/****************************************************************************
+**
+** 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 "cpphighlighterfactory.h"
+#include "cppeditorconstants.h"
+#include "cpphighlighter.h"
+
+using namespace CppEditor::Internal;
+
+CppHighlighterFactory::CppHighlighterFactory()
+{
+ setId(CppEditor::Constants::CPPEDITOR_ID);
+ addMimeType(CppEditor::Constants::C_SOURCE_MIMETYPE);
+ addMimeType(CppEditor::Constants::C_HEADER_MIMETYPE);
+ addMimeType(CppEditor::Constants::CPP_SOURCE_MIMETYPE);
+ addMimeType(CppEditor::Constants::CPP_HEADER_MIMETYPE);
+}
+
+TextEditor::SyntaxHighlighter *CppHighlighterFactory::createHighlighter() const
+{
+ return new CppHighlighter;
+}
diff --git a/src/plugins/cppeditor/cpphighlighterfactory.h b/src/plugins/cppeditor/cpphighlighterfactory.h
new file mode 100644
index 0000000000..6fc4283b31
--- /dev/null
+++ b/src/plugins/cppeditor/cpphighlighterfactory.h
@@ -0,0 +1,51 @@
+/****************************************************************************
+**
+** 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 CPPHIGHLIGHTERFACTORY_H
+#define CPPHIGHLIGHTERFACTORY_H
+
+#include <texteditor/ihighlighterfactory.h>
+
+namespace CppEditor {
+namespace Internal {
+
+class CppHighlighterFactory : public TextEditor::IHighlighterFactory
+{
+ Q_OBJECT
+
+public:
+ CppHighlighterFactory();
+
+ virtual TextEditor::SyntaxHighlighter *createHighlighter() const;
+};
+
+} // namespace Internal
+} // namespace CppEditor
+
+#endif // CPPHIGHLIGHTERFACTORY_H
diff --git a/src/plugins/diffeditor/diffeditorwidget.cpp b/src/plugins/diffeditor/diffeditorwidget.cpp
index aff227c8b5..3f19b6b991 100644
--- a/src/plugins/diffeditor/diffeditorwidget.cpp
+++ b/src/plugins/diffeditor/diffeditorwidget.cpp
@@ -38,15 +38,20 @@
#include <QToolButton>
#include <texteditor/basetexteditor.h>
-#include <texteditor/snippets/snippeteditor.h>
#include <texteditor/basetextdocumentlayout.h>
+#include <texteditor/ihighlighterfactory.h>
#include <texteditor/syntaxhighlighter.h>
#include <texteditor/basetextdocument.h>
#include <texteditor/texteditorsettings.h>
#include <texteditor/fontsettings.h>
#include <texteditor/displaysettings.h>
+#include <texteditor/generichighlighter/highlighter.h>
+#include <coreplugin/icore.h>
#include <coreplugin/minisplitter.h>
+#include <coreplugin/mimedatabase.h>
+
+#include <extensionsystem/pluginmanager.h>
#include <utils/tooltip/tipcontents.h>
#include <utils/tooltip/tooltip.h>
@@ -55,6 +60,7 @@ static const int BASE_LEVEL = 0;
static const int FILE_LEVEL = 1;
static const int CHUNK_LEVEL = 2;
+using namespace Core;
using namespace TextEditor;
namespace DiffEditor {
@@ -103,7 +109,7 @@ struct FileData {
class DiffViewEditorEditable : public BaseTextEditor
{
-Q_OBJECT
+ Q_OBJECT
public:
DiffViewEditorEditable(BaseTextEditorWidget *editorWidget)
: BaseTextEditor(editorWidget)
@@ -119,27 +125,50 @@ private slots:
};
+class MultiHighlighter : public SyntaxHighlighter
+{
+ Q_OBJECT
+public:
+ MultiHighlighter(DiffViewEditorWidget *editor, QTextDocument *document = 0);
+ ~MultiHighlighter();
+
+ virtual void setFontSettings(const TextEditor::FontSettings &fontSettings);
+ void setDocuments(const QList<QPair<DiffEditorWidget::DiffFileInfo, QString> > &documents);
+
+protected:
+ virtual void highlightBlock(const QString &text);
+
+private:
+ DiffViewEditorWidget *m_editor;
+ QMap<QString, IHighlighterFactory *> m_mimeTypeToHighlighterFactory;
+ QList<SyntaxHighlighter *> m_highlighters;
+ QList<QTextDocument *> m_documents;
+};
////////////////////////
-class DiffViewEditorWidget : public SnippetEditorWidget
+class DiffViewEditorWidget : public BaseTextEditorWidget
{
Q_OBJECT
public:
+ struct ExtendedFileInfo
+ {
+ DiffEditorWidget::DiffFileInfo fileInfo;
+ TextEditor::SyntaxHighlighter *highlighter;
+ };
+
DiffViewEditorWidget(QWidget *parent = 0);
- void setSyntaxHighlighter(SyntaxHighlighter *sh) {
- baseTextDocument()->setSyntaxHighlighter(sh);
- }
+ // TODO: remove me, codec should be taken from somewhere else
QTextCodec *codec() const {
return const_cast<QTextCodec *>(baseTextDocument()->codec());
}
- QMap<int, int> skippedLines() const { return m_skippedLines; }
+ // block number, file info
QMap<int, DiffEditorWidget::DiffFileInfo> fileInfo() const { return m_fileInfo; }
void setLineNumber(int blockNumber, int lineNumber);
- void setFileInfo(int blockNumber, const DiffEditorWidget::DiffFileInfo &fileInfo) { m_fileInfo[blockNumber] = fileInfo; setSeparator(blockNumber, true); }
+ void setFileInfo(int blockNumber, const DiffEditorWidget::DiffFileInfo &fileInfo);
void setSkippedLines(int blockNumber, int skippedLines) { m_skippedLines[blockNumber] = skippedLines; setSeparator(blockNumber, true); }
void setSeparator(int blockNumber, bool separator) { m_separators[blockNumber] = separator; }
bool isFileLine(int blockNumber) const { return m_fileInfo.contains(blockNumber); }
@@ -149,7 +178,8 @@ public:
void clearAll();
void clearAll(const QString &message);
void clearAllData();
- QTextBlock firstVisibleBlock() const { return SnippetEditorWidget::firstVisibleBlock(); }
+ QTextBlock firstVisibleBlock() const { return BaseTextEditorWidget::firstVisibleBlock(); }
+ void setDocuments(const QList<QPair<DiffEditorWidget::DiffFileInfo, QString> > &documents);
public slots:
void setDisplaySettings(const DisplaySettings &ds);
@@ -183,20 +213,108 @@ private:
const QTextBlock &block, int top);
void jumpToOriginalFile(const QTextCursor &cursor);
+ // block number, visual line number.
QMap<int, int> m_lineNumbers;
int m_lineNumberDigits;
- // block number, fileInfo
+ // block number, fileInfo. Set for file lines only.
QMap<int, DiffEditorWidget::DiffFileInfo> m_fileInfo;
- // block number, skipped lines
+ // block number, skipped lines. Set for chunk lines only.
QMap<int, int> m_skippedLines;
- // block number, separator. Separator used as lines alignment and inside skipped lines
+ // block number, separator. Set for file, chunk or span line.
QMap<int, bool> m_separators;
bool m_inPaintEvent;
QColor m_fileLineForeground;
QColor m_chunkLineForeground;
QColor m_textForeground;
+ MultiHighlighter *m_highlighter;
};
+MultiHighlighter::MultiHighlighter(DiffViewEditorWidget *editor, QTextDocument *document)
+ : SyntaxHighlighter(document),
+ m_editor(editor)
+{
+ const QList<IHighlighterFactory *> &factories =
+ ExtensionSystem::PluginManager::getObjects<TextEditor::IHighlighterFactory>();
+ foreach (IHighlighterFactory *factory, factories) {
+ QStringList mimeTypes = factory->mimeTypes();
+ foreach (const QString &mimeType, mimeTypes)
+ m_mimeTypeToHighlighterFactory.insert(mimeType, factory);
+ }
+}
+
+MultiHighlighter::~MultiHighlighter()
+{
+ setDocuments(QList<QPair<DiffEditorWidget::DiffFileInfo, QString> >());
+}
+
+void MultiHighlighter::setFontSettings(const TextEditor::FontSettings &fontSettings)
+{
+ foreach (SyntaxHighlighter *highlighter, m_highlighters) {
+ if (highlighter) {
+ highlighter->setFontSettings(fontSettings);
+ highlighter->rehighlight();
+ }
+ }
+}
+
+void MultiHighlighter::setDocuments(const QList<QPair<DiffEditorWidget::DiffFileInfo, QString> > &documents)
+{
+ // clear old documents
+ qDeleteAll(m_documents);
+ m_documents.clear();
+ qDeleteAll(m_highlighters);
+ m_highlighters.clear();
+
+ const MimeDatabase *mimeDatabase = ICore::mimeDatabase();
+
+ // create new documents
+ for (int i = 0; i < documents.count(); i++) {
+ DiffEditorWidget::DiffFileInfo fileInfo = documents.at(i).first;
+ const QString contents = documents.at(i).second;
+ QTextDocument *document = new QTextDocument(contents);
+ const MimeType mimeType = mimeDatabase->findByFile(QFileInfo(fileInfo.fileName));
+ SyntaxHighlighter *highlighter = 0;
+ if (const IHighlighterFactory *factory = m_mimeTypeToHighlighterFactory.value(mimeType.type())) {
+ highlighter = factory->createHighlighter();
+ if (highlighter)
+ highlighter->setDocument(document);
+ }
+ if (!highlighter) {
+ TextEditor::Highlighter *h = new TextEditor::Highlighter();
+ highlighter = h;
+ h->setMimeType(mimeType);
+ highlighter->setDocument(document);
+ }
+ m_documents.append(document);
+ m_highlighters.append(highlighter);
+ }
+}
+
+void MultiHighlighter::highlightBlock(const QString &text)
+{
+ Q_UNUSED(text)
+
+ QTextBlock block = currentBlock();
+ const int fileIndex = m_editor->fileIndexForBlockNumber(block.blockNumber());
+ if (fileIndex < 0)
+ return;
+
+ SyntaxHighlighter *currentHighlighter = m_highlighters.at(fileIndex);
+ if (!currentHighlighter)
+ return;
+
+ // find block in document
+ QTextDocument *currentDocument = m_documents.at(fileIndex);
+ if (!currentDocument)
+ return;
+
+ QTextBlock documentBlock = currentDocument->findBlockByNumber(
+ block.blockNumber() - m_editor->blockNumberForFileIndex(fileIndex));
+
+ QList<QTextLayout::FormatRange> formats = documentBlock.layout()->additionalFormats();
+ setExtraAdditionalFormats(block, formats);
+}
+
void DiffViewEditorEditable::slotTooltipRequested(TextEditor::ITextEditor *editor, const QPoint &globalPoint, int position)
{
DiffViewEditorWidget *ew = qobject_cast<DiffViewEditorWidget *>(editorWidget());
@@ -216,7 +334,7 @@ void DiffViewEditorEditable::slotTooltipRequested(TextEditor::ITextEditor *edito
}
DiffViewEditorWidget::DiffViewEditorWidget(QWidget *parent)
- : SnippetEditorWidget(parent), m_lineNumberDigits(1), m_inPaintEvent(false)
+ : BaseTextEditorWidget(parent), m_lineNumberDigits(1), m_inPaintEvent(false)
{
DisplaySettings settings = displaySettings();
settings.m_textWrapping = false;
@@ -225,22 +343,25 @@ DiffViewEditorWidget::DiffViewEditorWidget(QWidget *parent)
settings.m_displayFoldingMarkers = true;
settings.m_markTextChanges = false;
settings.m_highlightBlocks = false;
- SnippetEditorWidget::setDisplaySettings(settings);
+ BaseTextEditorWidget::setDisplaySettings(settings);
setCodeFoldingSupported(true);
setFrameStyle(QFrame::NoFrame);
+
+ m_highlighter = new MultiHighlighter(this, baseTextDocument()->document());
+ baseTextDocument()->setSyntaxHighlighter(m_highlighter);
}
void DiffViewEditorWidget::setDisplaySettings(const DisplaySettings &ds)
{
DisplaySettings settings = displaySettings();
settings.m_visualizeWhitespace = ds.m_visualizeWhitespace;
- SnippetEditorWidget::setDisplaySettings(settings);
+ BaseTextEditorWidget::setDisplaySettings(settings);
}
void DiffViewEditorWidget::setFontSettings(const TextEditor::FontSettings &fs)
{
- SnippetEditorWidget::setFontSettings(fs);
+ BaseTextEditorWidget::setFontSettings(fs);
m_fileLineForeground = fs.formatFor(C_DIFF_FILE_LINE).foreground();
m_chunkLineForeground = fs.formatFor(C_DIFF_CONTEXT_LINE).foreground();
m_textForeground = fs.toTextCharFormat(C_TEXT).foreground().color();
@@ -318,6 +439,12 @@ void DiffViewEditorWidget::setLineNumber(int blockNumber, int lineNumber)
m_lineNumberDigits = qMax(m_lineNumberDigits, lineNumberString.count());
}
+void DiffViewEditorWidget::setFileInfo(int blockNumber, const DiffEditorWidget::DiffFileInfo &fileInfo)
+{
+ m_fileInfo[blockNumber] = fileInfo;
+ setSeparator(blockNumber, true);
+}
+
int DiffViewEditorWidget::blockNumberForFileIndex(int fileIndex) const
{
if (fileIndex < 0 || fileIndex >= m_fileInfo.count())
@@ -359,6 +486,7 @@ void DiffViewEditorWidget::clearAll(const QString &message)
clear();
clearAllData();
setPlainText(message);
+ m_highlighter->setDocuments(QList<QPair<DiffEditorWidget::DiffFileInfo, QString> >());
}
void DiffViewEditorWidget::clearAllData()
@@ -370,9 +498,14 @@ void DiffViewEditorWidget::clearAllData()
m_separators.clear();
}
+void DiffViewEditorWidget::setDocuments(const QList<QPair<DiffEditorWidget::DiffFileInfo, QString> > &documents)
+{
+ m_highlighter->setDocuments(documents);
+}
+
void DiffViewEditorWidget::scrollContentsBy(int dx, int dy)
{
- SnippetEditorWidget::scrollContentsBy(dx, dy);
+ BaseTextEditorWidget::scrollContentsBy(dx, dy);
// TODO: update only chunk lines
viewport()->update();
}
@@ -423,7 +556,7 @@ void DiffViewEditorWidget::mouseDoubleClickEvent(QMouseEvent *e)
e->accept();
return;
}
- SnippetEditorWidget::mouseDoubleClickEvent(e);
+ BaseTextEditorWidget::mouseDoubleClickEvent(e);
}
void DiffViewEditorWidget::jumpToOriginalFile(const QTextCursor &cursor)
@@ -444,7 +577,7 @@ void DiffViewEditorWidget::jumpToOriginalFile(const QTextCursor &cursor)
void DiffViewEditorWidget::paintEvent(QPaintEvent *e)
{
m_inPaintEvent = true;
- SnippetEditorWidget::paintEvent(e);
+ BaseTextEditorWidget::paintEvent(e);
m_inPaintEvent = false;
QPainter painter(viewport());
@@ -760,12 +893,12 @@ QTextCodec *DiffEditorWidget::codec() const
return const_cast<QTextCodec *>(m_leftEditor->codec());
}
-SnippetEditorWidget *DiffEditorWidget::leftEditor() const
+BaseTextEditorWidget *DiffEditorWidget::leftEditor() const
{
return m_leftEditor;
}
-SnippetEditorWidget *DiffEditorWidget::rightEditor() const
+BaseTextEditorWidget *DiffEditorWidget::rightEditor() const
{
return m_rightEditor;
}
@@ -1150,18 +1283,20 @@ void DiffEditorWidget::showDiff()
clear();
- QString leftText, rightText;
+ QList<QPair<DiffEditorWidget::DiffFileInfo, QString> > leftDocs, rightDocs;
+ QString leftTexts, rightTexts;
int blockNumber = 0;
QChar separator = QLatin1Char('\n');
for (int i = 0; i < m_contextFileData.count(); i++) {
+ QString leftText, rightText;
const FileData &contextFileData = m_contextFileData.at(i);
int leftLineNumber = 0;
int rightLineNumber = 0;
m_leftEditor->setFileInfo(blockNumber, contextFileData.leftFileInfo);
m_rightEditor->setFileInfo(blockNumber, contextFileData.rightFileInfo);
- leftText += separator;
- rightText += separator;
+ leftText = separator;
+ rightText = separator;
blockNumber++;
for (int j = 0; j < contextFileData.chunks.count(); j++) {
@@ -1199,13 +1334,20 @@ void DiffEditorWidget::showDiff()
blockNumber++;
}
}
+ leftTexts += leftText;
+ rightTexts += rightText;
+ leftDocs.append(qMakePair(contextFileData.leftFileInfo, leftText));
+ rightDocs.append(qMakePair(contextFileData.rightFileInfo, rightText));
}
- if (leftText.isEmpty() && rightText.isEmpty())
+ if (leftTexts.isEmpty() && rightTexts.isEmpty())
return;
- m_leftEditor->setPlainText(leftText);
- m_rightEditor->setPlainText(rightText);
+ m_leftEditor->setDocuments(leftDocs);
+ m_rightEditor->setDocuments(rightDocs);
+
+ m_leftEditor->setPlainText(leftTexts);
+ m_rightEditor->setPlainText(rightTexts);
colorDiff(m_contextFileData);
diff --git a/src/plugins/diffeditor/diffeditorwidget.h b/src/plugins/diffeditor/diffeditorwidget.h
index 3b82a4ccba..fe324c3eb1 100644
--- a/src/plugins/diffeditor/diffeditorwidget.h
+++ b/src/plugins/diffeditor/diffeditorwidget.h
@@ -37,7 +37,6 @@
namespace TextEditor {
class BaseTextEditorWidget;
-class SnippetEditorWidget;
class FontSettings;
}
@@ -98,8 +97,8 @@ signals:
void navigatedToDiffFile(int diffFileIndex);
protected:
- TextEditor::SnippetEditorWidget *leftEditor() const;
- TextEditor::SnippetEditorWidget *rightEditor() const;
+ TextEditor::BaseTextEditorWidget *leftEditor() const;
+ TextEditor::BaseTextEditorWidget *rightEditor() const;
private slots:
void setFontSettings(const TextEditor::FontSettings &fontSettings);
diff --git a/src/plugins/glsleditor/glsleditor.pro b/src/plugins/glsleditor/glsleditor.pro
index ad353b0b46..e7f5375a74 100644
--- a/src/plugins/glsleditor/glsleditor.pro
+++ b/src/plugins/glsleditor/glsleditor.pro
@@ -11,6 +11,7 @@ glsleditorfactory.h \
glsleditorplugin.h \
glslfilewizard.h \
glslhighlighter.h \
+glslhighlighterfactory.h \
glslautocompleter.h \
glslindenter.h \
glslhoverhandler.h \
@@ -24,6 +25,7 @@ glsleditorfactory.cpp \
glsleditorplugin.cpp \
glslfilewizard.cpp \
glslhighlighter.cpp \
+glslhighlighterfactory.cpp \
glslautocompleter.cpp \
glslindenter.cpp \
glslhoverhandler.cpp \
diff --git a/src/plugins/glsleditor/glsleditor.qbs b/src/plugins/glsleditor/glsleditor.qbs
index 000d22e3fc..d99571f1b5 100644
--- a/src/plugins/glsleditor/glsleditor.qbs
+++ b/src/plugins/glsleditor/glsleditor.qbs
@@ -32,6 +32,8 @@ QtcPlugin {
"glslfilewizard.h",
"glslhighlighter.cpp",
"glslhighlighter.h",
+ "glslhighlighterfactory.cpp",
+ "glslhighlighterfactory.h",
"glslhoverhandler.cpp",
"glslhoverhandler.h",
"glslindenter.cpp",
diff --git a/src/plugins/glsleditor/glsleditorplugin.cpp b/src/plugins/glsleditor/glsleditorplugin.cpp
index 9bb1cc6a7f..88ee6d36c4 100644
--- a/src/plugins/glsleditor/glsleditorplugin.cpp
+++ b/src/plugins/glsleditor/glsleditorplugin.cpp
@@ -34,6 +34,7 @@
#include "glslfilewizard.h"
#include "glslhoverhandler.h"
#include "glslcompletionassist.h"
+#include "glslhighlighterfactory.h"
#include <coreplugin/icore.h>
#include <coreplugin/coreconstants.h>
@@ -201,6 +202,7 @@ bool GLSLEditorPlugin::initialize(const QStringList & /*arguments*/, QString *er
vertWizardParameters.setDisplayName(tr("Vertex Shader (Desktop OpenGL)"));
vertWizardParameters.setId(QLatin1String("K.GLSL"));
addAutoReleasedObject(new GLSLFileWizard(vertWizardParameters, GLSLFileWizard::VertexShaderDesktop, core));
+ addAutoReleasedObject(new GLSLHighlighterFactory);
return true;
}
diff --git a/src/plugins/glsleditor/glslhighlighter.cpp b/src/plugins/glsleditor/glslhighlighter.cpp
index 709023ea9f..ae64cd24fa 100644
--- a/src/plugins/glsleditor/glslhighlighter.cpp
+++ b/src/plugins/glsleditor/glslhighlighter.cpp
@@ -39,9 +39,20 @@ using namespace GLSLEditor;
using namespace GLSLEditor::Internal;
using namespace TextEditor;
+Highlighter::Highlighter(QTextDocument *parent)
+ : TextEditor::SyntaxHighlighter(parent)
+{
+ init();
+}
+
Highlighter::Highlighter(BaseTextDocument *parent)
: TextEditor::SyntaxHighlighter(parent)
{
+ init();
+}
+
+void Highlighter::init()
+{
static QVector<TextEditor::TextStyle> categories;
if (categories.isEmpty()) {
categories << TextEditor::C_NUMBER
diff --git a/src/plugins/glsleditor/glslhighlighter.h b/src/plugins/glsleditor/glslhighlighter.h
index 6dd93c83ab..0f5660092a 100644
--- a/src/plugins/glsleditor/glslhighlighter.h
+++ b/src/plugins/glsleditor/glslhighlighter.h
@@ -57,6 +57,7 @@ public:
NumGLSLFormats
};
+ explicit Highlighter(QTextDocument *parent = 0);
explicit Highlighter(TextEditor::BaseTextDocument *parent);
virtual ~Highlighter();
@@ -64,6 +65,9 @@ protected:
void highlightBlock(const QString &text);
void highlightLine(const QString &text, int position, int length, const QTextCharFormat &format);
bool isPPKeyword(const QStringRef &text) const;
+
+private:
+ void init();
};
} // namespace Internal
diff --git a/src/plugins/glsleditor/glslhighlighterfactory.cpp b/src/plugins/glsleditor/glslhighlighterfactory.cpp
new file mode 100644
index 0000000000..db9faa86e0
--- /dev/null
+++ b/src/plugins/glsleditor/glslhighlighterfactory.cpp
@@ -0,0 +1,49 @@
+/****************************************************************************
+**
+** 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 "glslhighlighterfactory.h"
+#include "glsleditorconstants.h"
+#include "glslhighlighter.h"
+
+using namespace GLSLEditor::Internal;
+
+GLSLHighlighterFactory::GLSLHighlighterFactory()
+{
+ setId(GLSLEditor::Constants::C_GLSLEDITOR_ID);
+ addMimeType(GLSLEditor::Constants::GLSL_MIMETYPE);
+ addMimeType(GLSLEditor::Constants::GLSL_MIMETYPE_VERT);
+ addMimeType(GLSLEditor::Constants::GLSL_MIMETYPE_FRAG);
+ addMimeType(GLSLEditor::Constants::GLSL_MIMETYPE_VERT_ES);
+ addMimeType(GLSLEditor::Constants::GLSL_MIMETYPE_FRAG_ES);
+}
+
+TextEditor::SyntaxHighlighter *GLSLHighlighterFactory::createHighlighter() const
+{
+ return new Highlighter;
+}
diff --git a/src/plugins/glsleditor/glslhighlighterfactory.h b/src/plugins/glsleditor/glslhighlighterfactory.h
new file mode 100644
index 0000000000..e6dbbddedc
--- /dev/null
+++ b/src/plugins/glsleditor/glslhighlighterfactory.h
@@ -0,0 +1,51 @@
+/****************************************************************************
+**
+** 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 GLSLHIGHLIGHTERFACTORY_H
+#define GLSLHIGHLIGHTERFACTORY_H
+
+#include <texteditor/ihighlighterfactory.h>
+
+namespace GLSLEditor {
+namespace Internal {
+
+class GLSLHighlighterFactory : public TextEditor::IHighlighterFactory
+{
+ Q_OBJECT
+
+public:
+ GLSLHighlighterFactory();
+
+ virtual TextEditor::SyntaxHighlighter *createHighlighter() const;
+};
+
+} // namespace Internal
+} // namespace GLSLEditor
+
+#endif // GLSLHIGHLIGHTERFACTORY_H
diff --git a/src/plugins/pythoneditor/pythoneditor.pro b/src/plugins/pythoneditor/pythoneditor.pro
index 0e7e02672f..9d87e03a12 100644
--- a/src/plugins/pythoneditor/pythoneditor.pro
+++ b/src/plugins/pythoneditor/pythoneditor.pro
@@ -18,6 +18,7 @@ HEADERS += \
wizard/pythonclasswizarddialog.h \
wizard/pythonsourcegenerator.h \
tools/pythonhighlighter.h \
+ tools/pythonhighlighterfactory.h \
tools/pythonindenter.h \
tools/lexical/pythonformattoken.h \
tools/lexical/pythonscanner.h \
@@ -34,5 +35,6 @@ SOURCES += \
wizard/pythonclassnamepage.cpp \
wizard/pythonsourcegenerator.cpp \
tools/pythonhighlighter.cpp \
+ tools/pythonhighlighterfactory.cpp \
tools/pythonindenter.cpp \
tools/lexical/pythonscanner.cpp
diff --git a/src/plugins/pythoneditor/pythoneditor.qbs b/src/plugins/pythoneditor/pythoneditor.qbs
index 5637b891b1..3b0a4899a6 100644
--- a/src/plugins/pythoneditor/pythoneditor.qbs
+++ b/src/plugins/pythoneditor/pythoneditor.qbs
@@ -32,6 +32,7 @@ QtcPlugin {
"lexical/pythonscanner.h", "lexical/pythonscanner.cpp",
"lexical/sourcecodestream.h",
"pythonhighlighter.h", "pythonhighlighter.cpp",
+ "pythonhighlighterfactory.h", "pythonhighlighterfactory.cpp",
"pythonindenter.cpp", "pythonindenter.h"
]
}
diff --git a/src/plugins/pythoneditor/pythoneditorplugin.cpp b/src/plugins/pythoneditor/pythoneditorplugin.cpp
index b49ae92f48..1f8ec02163 100644
--- a/src/plugins/pythoneditor/pythoneditorplugin.cpp
+++ b/src/plugins/pythoneditor/pythoneditorplugin.cpp
@@ -33,6 +33,7 @@
#include "wizard/pythonclasswizard.h"
#include "pythoneditorwidget.h"
#include "pythoneditorfactory.h"
+#include "tools/pythonhighlighterfactory.h"
#include <coreplugin/icore.h>
#include <coreplugin/coreconstants.h>
@@ -252,6 +253,7 @@ bool PythonEditorPlugin::initialize(
////////////////////////////////////////////////////////////////////////////
addAutoReleasedObject(new FileWizard(Core::ICore::instance()));
addAutoReleasedObject(new ClassWizard(Core::ICore::instance()));
+ addAutoReleasedObject(new Internal::PythonHighlighterFactory);
return true;
}
diff --git a/src/plugins/pythoneditor/tools/pythonhighlighter.cpp b/src/plugins/pythoneditor/tools/pythonhighlighter.cpp
index ea809c4e6f..32c59ef6b0 100644
--- a/src/plugins/pythoneditor/tools/pythonhighlighter.cpp
+++ b/src/plugins/pythoneditor/tools/pythonhighlighter.cpp
@@ -65,10 +65,21 @@ using namespace PythonEditor::Internal;
* @endcode
*/
+PythonHighlighter::PythonHighlighter(QTextDocument *parent) :
+ TextEditor::SyntaxHighlighter(parent)
+{
+ init();
+}
+
/// New instance created when opening any document in editor
PythonHighlighter::PythonHighlighter(TextEditor::BaseTextDocument *parent) :
TextEditor::SyntaxHighlighter(parent)
{
+ init();
+}
+
+void PythonHighlighter::init()
+{
static QVector<TextEditor::TextStyle> categories;
if (categories.isEmpty()) {
categories << TextEditor::C_NUMBER
diff --git a/src/plugins/pythoneditor/tools/pythonhighlighter.h b/src/plugins/pythoneditor/tools/pythonhighlighter.h
index 41b7eb6c71..d5287fc0b5 100644
--- a/src/plugins/pythoneditor/tools/pythonhighlighter.h
+++ b/src/plugins/pythoneditor/tools/pythonhighlighter.h
@@ -40,6 +40,7 @@ class PythonHighlighter : public TextEditor::SyntaxHighlighter
{
Q_OBJECT
public:
+ explicit PythonHighlighter(QTextDocument *parent = 0);
explicit PythonHighlighter(TextEditor::BaseTextDocument *parent);
virtual ~PythonHighlighter();
@@ -49,6 +50,7 @@ protected:
private:
int highlightLine(const QString &text, int initialState);
void highlightImport(Internal::Scanner &scanner);
+ void init();
};
} // namespace PythonEditor
diff --git a/src/plugins/pythoneditor/tools/pythonhighlighterfactory.cpp b/src/plugins/pythoneditor/tools/pythonhighlighterfactory.cpp
new file mode 100644
index 0000000000..3ea998d48e
--- /dev/null
+++ b/src/plugins/pythoneditor/tools/pythonhighlighterfactory.cpp
@@ -0,0 +1,45 @@
+/****************************************************************************
+**
+** 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 "pythonhighlighterfactory.h"
+#include "pythoneditorconstants.h"
+#include "tools/pythonhighlighter.h"
+
+using namespace PythonEditor::Internal;
+
+PythonHighlighterFactory::PythonHighlighterFactory()
+{
+ setId(Constants::C_PYTHONEDITOR_ID);
+ addMimeType(QLatin1String(Constants::C_PY_MIMETYPE));
+}
+
+TextEditor::SyntaxHighlighter *PythonHighlighterFactory::createHighlighter() const
+{
+ return new PythonHighlighter;
+}
diff --git a/src/plugins/pythoneditor/tools/pythonhighlighterfactory.h b/src/plugins/pythoneditor/tools/pythonhighlighterfactory.h
new file mode 100644
index 0000000000..fa7dc02825
--- /dev/null
+++ b/src/plugins/pythoneditor/tools/pythonhighlighterfactory.h
@@ -0,0 +1,51 @@
+/****************************************************************************
+**
+** 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 PYTHONHIGHLIGHTERFACTORY_H
+#define PYTHONHIGHLIGHTERFACTORY_H
+
+#include <texteditor/ihighlighterfactory.h>
+
+namespace PythonEditor {
+namespace Internal {
+
+class PythonHighlighterFactory : public TextEditor::IHighlighterFactory
+{
+ Q_OBJECT
+
+public:
+ PythonHighlighterFactory();
+
+ virtual TextEditor::SyntaxHighlighter *createHighlighter() const;
+};
+
+} // namespace Internal
+} // namespace PythonEditor
+
+#endif // PYTHONHIGHLIGHTERFACTORY_H
diff --git a/src/plugins/qmljseditor/qmljseditor.pro b/src/plugins/qmljseditor/qmljseditor.pro
index 9a40aa33ea..6d80ea429c 100644
--- a/src/plugins/qmljseditor/qmljseditor.pro
+++ b/src/plugins/qmljseditor/qmljseditor.pro
@@ -13,6 +13,7 @@ HEADERS += \
qmlexpressionundercursor.h \
qmlfilewizard.h \
qmljshighlighter.h \
+ qmljshighlighterfactory.h \
qmljshoverhandler.h \
qmljspreviewrunner.h \
qmljscomponentfromobjectdef.h \
@@ -43,6 +44,7 @@ SOURCES += \
qmlexpressionundercursor.cpp \
qmlfilewizard.cpp \
qmljshighlighter.cpp \
+ qmljshighlighterfactory.cpp \
qmljshoverhandler.cpp \
qmljspreviewrunner.cpp \
qmljscomponentfromobjectdef.cpp \
diff --git a/src/plugins/qmljseditor/qmljseditor.qbs b/src/plugins/qmljseditor/qmljseditor.qbs
index 72c9294c14..5f460b0ce1 100644
--- a/src/plugins/qmljseditor/qmljseditor.qbs
+++ b/src/plugins/qmljseditor/qmljseditor.qbs
@@ -47,6 +47,8 @@ QtcPlugin {
"qmljsfindreferences.h",
"qmljshighlighter.cpp",
"qmljshighlighter.h",
+ "qmljshighlighterfactory.cpp",
+ "qmljshighlighterfactory.h",
"qmljshoverhandler.cpp",
"qmljshoverhandler.h",
"qmljsoutline.cpp",
diff --git a/src/plugins/qmljseditor/qmljseditorplugin.cpp b/src/plugins/qmljseditor/qmljseditorplugin.cpp
index ba276026cb..6973b39b7f 100644
--- a/src/plugins/qmljseditor/qmljseditorplugin.cpp
+++ b/src/plugins/qmljseditor/qmljseditorplugin.cpp
@@ -43,6 +43,7 @@
#include "quicktoolbarsettingspage.h"
#include "qmljscompletionassist.h"
#include "qmljsquickfixassist.h"
+#include "qmljshighlighterfactory.h"
#include <qmljs/qmljsicons.h>
#include <qmljs/qmljsmodelmanagerinterface.h>
@@ -115,6 +116,7 @@ bool QmlJSEditorPlugin::initialize(const QStringList & /*arguments*/, QString *e
{
m_modelManager = QmlJS::ModelManagerInterface::instance();
addAutoReleasedObject(new QmlJSSnippetProvider);
+ addAutoReleasedObject(new QmlJSHighlighterFactory);
// QML task updating manager
m_qmlTaskManager = new QmlTaskManager;
diff --git a/src/plugins/qmljseditor/qmljshighlighterfactory.cpp b/src/plugins/qmljseditor/qmljshighlighterfactory.cpp
new file mode 100644
index 0000000000..576d419f30
--- /dev/null
+++ b/src/plugins/qmljseditor/qmljshighlighterfactory.cpp
@@ -0,0 +1,51 @@
+/****************************************************************************
+**
+** 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 "qmljshighlighterfactory.h"
+#include "qmljseditorconstants.h"
+#include "qmljshighlighter.h"
+#include <qmljstools/qmljstoolsconstants.h>
+
+using namespace QmlJSEditor::Internal;
+
+QmlJSHighlighterFactory::QmlJSHighlighterFactory()
+{
+ setId(Constants::C_QMLJSEDITOR_ID);
+ addMimeType(QmlJSTools::Constants::QML_MIMETYPE);
+ addMimeType(QmlJSTools::Constants::QMLPROJECT_MIMETYPE);
+ addMimeType(QmlJSTools::Constants::QBS_MIMETYPE);
+ addMimeType(QmlJSTools::Constants::QMLTYPES_MIMETYPE);
+ addMimeType(QmlJSTools::Constants::JS_MIMETYPE);
+ addMimeType(QmlJSTools::Constants::JSON_MIMETYPE);
+}
+
+TextEditor::SyntaxHighlighter *QmlJSHighlighterFactory::createHighlighter() const
+{
+ return new Highlighter;
+}
diff --git a/src/plugins/qmljseditor/qmljshighlighterfactory.h b/src/plugins/qmljseditor/qmljshighlighterfactory.h
new file mode 100644
index 0000000000..ab768f8a0d
--- /dev/null
+++ b/src/plugins/qmljseditor/qmljshighlighterfactory.h
@@ -0,0 +1,51 @@
+/****************************************************************************
+**
+** 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 QMLJSHIGHLIGHTERFACTORY_H
+#define QMLJSHIGHLIGHTERFACTORY_H
+
+#include <texteditor/ihighlighterfactory.h>
+
+namespace QmlJSEditor {
+namespace Internal {
+
+class QmlJSHighlighterFactory : public TextEditor::IHighlighterFactory
+{
+ Q_OBJECT
+
+public:
+ QmlJSHighlighterFactory();
+
+ virtual TextEditor::SyntaxHighlighter *createHighlighter() const;
+};
+
+} // namespace Internal
+} // namespace QmlJSEditor
+
+#endif // QMLJSHIGHLIGHTERFACTORY_H
diff --git a/src/plugins/qt4projectmanager/profilehighlighterfactory.cpp b/src/plugins/qt4projectmanager/profilehighlighterfactory.cpp
new file mode 100644
index 0000000000..a4b8afa812
--- /dev/null
+++ b/src/plugins/qt4projectmanager/profilehighlighterfactory.cpp
@@ -0,0 +1,47 @@
+/****************************************************************************
+**
+** 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 "profilehighlighterfactory.h"
+#include "qt4projectmanagerconstants.h"
+#include "profilehighlighter.h"
+
+using namespace Qt4ProjectManager::Internal;
+
+ProFileHighlighterFactory::ProFileHighlighterFactory()
+{
+ setId(Qt4ProjectManager::Constants::PROFILE_EDITOR_ID);
+ addMimeType(Qt4ProjectManager::Constants::PROFILE_MIMETYPE);
+ addMimeType(Qt4ProjectManager::Constants::PROINCLUDEFILE_MIMETYPE);
+ addMimeType(Qt4ProjectManager::Constants::PROFEATUREFILE_MIMETYPE);
+}
+
+TextEditor::SyntaxHighlighter *ProFileHighlighterFactory::createHighlighter() const
+{
+ return new ProFileHighlighter;
+}
diff --git a/src/plugins/qt4projectmanager/profilehighlighterfactory.h b/src/plugins/qt4projectmanager/profilehighlighterfactory.h
new file mode 100644
index 0000000000..358a74ab2c
--- /dev/null
+++ b/src/plugins/qt4projectmanager/profilehighlighterfactory.h
@@ -0,0 +1,51 @@
+/****************************************************************************
+**
+** 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 PROFILEHIGHLIGHTERFACTORY_H
+#define PROFILEHIGHLIGHTERFACTORY_H
+
+#include <texteditor/ihighlighterfactory.h>
+
+namespace Qt4ProjectManager {
+namespace Internal {
+
+class ProFileHighlighterFactory : public TextEditor::IHighlighterFactory
+{
+ Q_OBJECT
+
+public:
+ ProFileHighlighterFactory();
+
+ virtual TextEditor::SyntaxHighlighter *createHighlighter() const;
+};
+
+} // namespace Internal
+} // namespace Qt4ProjectManager
+
+#endif // PROFILEHIGHLIGHTERFACTORY_H
diff --git a/src/plugins/qt4projectmanager/qt4projectmanager.pro b/src/plugins/qt4projectmanager/qt4projectmanager.pro
index c37d4b7648..ad19843ece 100644
--- a/src/plugins/qt4projectmanager/qt4projectmanager.pro
+++ b/src/plugins/qt4projectmanager/qt4projectmanager.pro
@@ -14,6 +14,7 @@ HEADERS += \
qt4nodes.h \
profileeditor.h \
profilehighlighter.h \
+ profilehighlighterfactory.h \
profileeditorfactory.h \
profilehoverhandler.h \
wizards/qtprojectparameters.h \
@@ -77,6 +78,7 @@ SOURCES += \
qt4nodes.cpp \
profileeditor.cpp \
profilehighlighter.cpp \
+ profilehighlighterfactory.cpp \
profileeditorfactory.cpp \
profilehoverhandler.cpp \
wizards/qtprojectparameters.cpp \
diff --git a/src/plugins/qt4projectmanager/qt4projectmanager.qbs b/src/plugins/qt4projectmanager/qt4projectmanager.qbs
index 7cf39fba3b..25952b4be2 100644
--- a/src/plugins/qt4projectmanager/qt4projectmanager.qbs
+++ b/src/plugins/qt4projectmanager/qt4projectmanager.qbs
@@ -39,6 +39,7 @@ QtcPlugin {
"profileeditor.cpp", "profileeditor.h",
"profileeditorfactory.cpp", "profileeditorfactory.h",
"profilehighlighter.cpp", "profilehighlighter.h",
+ "profilehighlighterfactory.cpp", "profilehighlighterfactory.h",
"profilehoverhandler.cpp", "profilehoverhandler.h",
"qmakeparser.cpp", "qmakeparser.h",
"qmakekitconfigwidget.cpp", "qmakekitconfigwidget.h",
diff --git a/src/plugins/qt4projectmanager/qt4projectmanagerplugin.cpp b/src/plugins/qt4projectmanager/qt4projectmanagerplugin.cpp
index c3d1185af3..f7c48c6972 100644
--- a/src/plugins/qt4projectmanager/qt4projectmanagerplugin.cpp
+++ b/src/plugins/qt4projectmanager/qt4projectmanagerplugin.cpp
@@ -55,6 +55,7 @@
#include "winceqtversionfactory.h"
#include "unconfiguredprojectpanel.h"
#include "qmakekitinformation.h"
+#include "profilehighlighterfactory.h"
#include <coreplugin/icore.h>
#include <projectexplorer/buildmanager.h>
@@ -156,6 +157,7 @@ bool Qt4ProjectManagerPlugin::initialize(const QStringList &arguments, QString *
addAutoReleasedObject(new ProFileCompletionAssistProvider);
addAutoReleasedObject(new ProFileHoverHandler(this));
addAutoReleasedObject(new UnconfiguredProjectPanel);
+ addAutoReleasedObject(new ProFileHighlighterFactory);
//menus
Core::ActionContainer *mbuild =
diff --git a/src/plugins/texteditor/generichighlighter/highlighter.cpp b/src/plugins/texteditor/generichighlighter/highlighter.cpp
index 43c6e587b8..4e333a1000 100644
--- a/src/plugins/texteditor/generichighlighter/highlighter.cpp
+++ b/src/plugins/texteditor/generichighlighter/highlighter.cpp
@@ -36,6 +36,8 @@
#include "progressdata.h"
#include "reuse.h"
#include "tabsettings.h"
+#include "manager.h"
+#include <coreplugin/icore.h>
#include <QLatin1String>
#include <QLatin1Char>
@@ -117,6 +119,40 @@ 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;
diff --git a/src/plugins/texteditor/generichighlighter/highlighter.h b/src/plugins/texteditor/generichighlighter/highlighter.h
index 5dbe5e6fc6..c8e2a28d41 100644
--- a/src/plugins/texteditor/generichighlighter/highlighter.h
+++ b/src/plugins/texteditor/generichighlighter/highlighter.h
@@ -30,8 +30,8 @@
#ifndef HIGHLIGHTER_H
#define HIGHLIGHTER_H
-#include "basetextdocumentlayout.h"
-#include "syntaxhighlighter.h"
+#include <texteditor/basetextdocumentlayout.h>
+#include <texteditor/syntaxhighlighter.h>
#include <QString>
#include <QVector>
@@ -41,10 +41,12 @@
#include <QTextCharFormat>
+namespace Core {
+class MimeType;
+}
namespace TextEditor {
class TabSettings;
-
namespace Internal {
class Rule;
@@ -52,7 +54,9 @@ class Context;
class HighlightDefinition;
class ProgressData;
-class Highlighter : public TextEditor::SyntaxHighlighter
+} // namespace Internal
+
+class TEXTEDITOR_EXPORT Highlighter : public TextEditor::SyntaxHighlighter
{
Q_OBJECT
@@ -79,7 +83,9 @@ public:
};
void setTabSettings(const TabSettings &ts);
- void setDefaultContext(const QSharedPointer<Context> &defaultContext);
+ void setMimeType(const Core::MimeType &mimeType);
+
+ static QString findDefinitionId(const Core::MimeType &mimeType, bool considerParents);
protected:
virtual void highlightBlock(const QString &text);
@@ -94,17 +100,18 @@ private:
void iterateThroughRules(const QString &text,
const int length,
- ProgressData *progress,
+ Internal::ProgressData *progress,
const bool childRule,
- const QList<QSharedPointer<Rule> > &rules);
+ 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,
- const QSharedPointer<HighlightDefinition> &definition,
+ const QSharedPointer<Internal::HighlightDefinition> &definition,
const bool setCurrent = true);
void changeContext(const QString &contextName,
- const QSharedPointer<HighlightDefinition> &definition,
+ const QSharedPointer<Internal::HighlightDefinition> &definition,
const bool assignCurrent = true);
QString currentContextSequence() const;
@@ -112,7 +119,7 @@ private:
void mapLeadingSequence(const QString &contextSequence);
void pushContextSequence(int state);
- void pushDynamicContext(const QSharedPointer<Context> &baseContext);
+ void pushDynamicContext(const QSharedPointer<Internal::Context> &baseContext);
void createWillContinueBlock();
void analyseConsistencyOfWillContinueBlock(const QString &text);
@@ -120,7 +127,7 @@ private:
void applyFormat(int offset,
int count,
const QString &itemDataName,
- const QSharedPointer<HighlightDefinition> &definition);
+ const QSharedPointer<Internal::HighlightDefinition> &definition);
void applyRegionBasedFolding() const;
void applyIndentationBasedFolding(const QString &text) const;
@@ -142,7 +149,7 @@ private:
int m_foldingIndentDelta;
int m_originalObservableState;
QStack<QString> m_foldingRegions;
- QSharedPointer<Context> m_contextToContinue;
+ QSharedPointer<Internal::Context> m_contextToContinue;
};
BlockData *initializeBlockData();
static BlockData *blockData(QTextBlockUserData *userData);
@@ -179,22 +186,21 @@ private:
bool m_isBroken;
- QSharedPointer<Context> m_defaultContext;
- QSharedPointer<Context> m_currentContext;
- QVector<QSharedPointer<Context> > m_contexts;
+ QSharedPointer<Internal::Context> m_defaultContext;
+ QSharedPointer<Internal::Context> m_currentContext;
+ QVector<QSharedPointer<Internal::Context> > m_contexts;
// Mapping from context sequences to the observable persistent state they represent.
QHash<QString, int> m_persistentObservableStates;
// Mapping from context sequences to the non-persistent observable state that led to them.
QHash<QString, int> m_leadingObservableStates;
// Mapping from observable persistent states to context sequences (the actual "stack").
- QHash<int, QVector<QSharedPointer<Context> > > m_persistentContexts;
+ QHash<int, QVector<QSharedPointer<Internal::Context> > > m_persistentContexts;
// Captures used in dynamic rules.
QStringList m_currentCaptures;
};
-} // namespace Internal
} // namespace TextEditor
#endif // HIGHLIGHTER_H
diff --git a/src/plugins/texteditor/ihighlighterfactory.h b/src/plugins/texteditor/ihighlighterfactory.h
new file mode 100644
index 0000000000..0909d72898
--- /dev/null
+++ b/src/plugins/texteditor/ihighlighterfactory.h
@@ -0,0 +1,66 @@
+/****************************************************************************
+**
+** 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 IHIGHLIGHTERFACTORY_H
+#define IHIGHLIGHTERFACTORY_H
+
+#include <texteditor/texteditor_global.h>
+#include <coreplugin/id.h>
+
+#include <QObject>
+#include <QStringList>
+
+namespace TextEditor {
+
+class SyntaxHighlighter;
+
+class TEXTEDITOR_EXPORT IHighlighterFactory : public QObject
+{
+ Q_OBJECT
+public:
+ virtual TextEditor::SyntaxHighlighter *createHighlighter() const = 0;
+
+ Core::Id id() const { return m_id; }
+ QStringList mimeTypes() const { return m_mimeTypes; }
+
+protected:
+ void setId(Core::Id id) { m_id = id; }
+ void setMimeTypes(const QStringList &mimeTypes) { m_mimeTypes = mimeTypes; }
+ void addMimeType(const char *mimeType) { m_mimeTypes.append(QLatin1String(mimeType)); }
+ void addMimeType(const QString &mimeType) { m_mimeTypes.append(mimeType); }
+
+private:
+ Core::Id m_id;
+ QStringList m_mimeTypes;
+};
+
+} // TextEditor
+
+#endif // IHIGHLIGHTERFACTORY_H
+
diff --git a/src/plugins/texteditor/plaintexteditor.cpp b/src/plugins/texteditor/plaintexteditor.cpp
index 61103b7bbf..a5fe10c3d9 100644
--- a/src/plugins/texteditor/plaintexteditor.cpp
+++ b/src/plugins/texteditor/plaintexteditor.cpp
@@ -125,20 +125,19 @@ void PlainTextEditorWidget::configure(const Core::MimeType &mimeType)
if (!mimeType.isNull()) {
m_isMissingSyntaxDefinition = true;
+ highlighter->setMimeType(mimeType);
const QString &type = mimeType.type();
setMimeType(type);
QString definitionId = Manager::instance()->definitionIdByMimeType(type);
if (definitionId.isEmpty())
- definitionId = findDefinitionId(mimeType, true);
+ definitionId = Highlighter::findDefinitionId(mimeType, true);
if (!definitionId.isEmpty()) {
m_isMissingSyntaxDefinition = false;
const QSharedPointer<HighlightDefinition> &definition =
Manager::instance()->definition(definitionId);
if (!definition.isNull() && definition->isValid()) {
- highlighter->setDefaultContext(definition->initialContext());
-
m_commentDefinition.isAfterWhiteSpaces = definition->isCommentAfterWhiteSpaces();
m_commentDefinition.singleLine = definition->singleLineComment();
m_commentDefinition.multiLineStart = definition->multiLineCommentStart();
@@ -163,23 +162,6 @@ bool PlainTextEditorWidget::isMissingSyntaxDefinition() const
return m_isMissingSyntaxDefinition;
}
-QString PlainTextEditorWidget::findDefinitionId(const Core::MimeType &mimeType,
- bool considerParents) const
-{
- 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 PlainTextEditorWidget::acceptMissingSyntaxDefinitionInfo()
{
ICore::showOptionsDialog(Constants::TEXT_EDITOR_SETTINGS_CATEGORY,
diff --git a/src/plugins/texteditor/plaintexteditor.h b/src/plugins/texteditor/plaintexteditor.h
index b1540b467b..35850625a4 100644
--- a/src/plugins/texteditor/plaintexteditor.h
+++ b/src/plugins/texteditor/plaintexteditor.h
@@ -80,8 +80,6 @@ protected:
virtual BaseTextEditor *createEditor() { return new PlainTextEditor(this); }
private:
- QString findDefinitionId(const Core::MimeType &mimeType, bool considerParents) const;
-
bool m_isMissingSyntaxDefinition;
Utils::CommentDefinition m_commentDefinition;
};
diff --git a/src/plugins/texteditor/texteditor.pro b/src/plugins/texteditor/texteditor.pro
index 34b4463488..a8471a9dd5 100644
--- a/src/plugins/texteditor/texteditor.pro
+++ b/src/plugins/texteditor/texteditor.pro
@@ -146,6 +146,7 @@ HEADERS += texteditorplugin.h \
normalindenter.h \
indenter.h \
quickfix.h \
+ ihighlighterfactory.h \
syntaxhighlighter.h \
generichighlighter/reuse.h \
generichighlighter/itemdata.h \
diff --git a/src/plugins/texteditor/texteditor.qbs b/src/plugins/texteditor/texteditor.qbs
index a004705c04..e2e3c3c202 100644
--- a/src/plugins/texteditor/texteditor.qbs
+++ b/src/plugins/texteditor/texteditor.qbs
@@ -89,6 +89,7 @@ QtcPlugin {
"icodestylepreferences.h",
"icodestylepreferencesfactory.cpp",
"icodestylepreferencesfactory.h",
+ "ihighlighterfactory.cpp",
"indenter.cpp",
"indenter.h",
"ioutlinewidget.h",