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>
This commit is contained in:
jkobus
2013-08-14 13:52:13 +02:00
committed by Jarek Kobus
parent a06da47d5b
commit 33a7952745
43 changed files with 956 additions and 72 deletions

View File

@@ -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;
}

View File

@@ -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

View File

@@ -12,6 +12,7 @@ HEADERS = cmakeproject.h \
cmakeeditorfactory.h \ cmakeeditorfactory.h \
cmakeeditor.h \ cmakeeditor.h \
cmakehighlighter.h \ cmakehighlighter.h \
cmakehighlighterfactory.h \
cmakelocatorfilter.h \ cmakelocatorfilter.h \
cmakefilecompletionassist.h \ cmakefilecompletionassist.h \
cmakevalidator.h \ cmakevalidator.h \
@@ -28,6 +29,7 @@ SOURCES = cmakeproject.cpp \
cmakeeditorfactory.cpp \ cmakeeditorfactory.cpp \
cmakeeditor.cpp \ cmakeeditor.cpp \
cmakehighlighter.cpp \ cmakehighlighter.cpp \
cmakehighlighterfactory.cpp \
cmakelocatorfilter.cpp \ cmakelocatorfilter.cpp \
cmakefilecompletionassist.cpp \ cmakefilecompletionassist.cpp \
cmakevalidator.cpp \ cmakevalidator.cpp \

View File

@@ -30,6 +30,8 @@ QtcPlugin {
"cmakefilecompletionassist.h", "cmakefilecompletionassist.h",
"cmakehighlighter.cpp", "cmakehighlighter.cpp",
"cmakehighlighter.h", "cmakehighlighter.h",
"cmakehighlighterfactory.cpp",
"cmakehighlighterfactory.h",
"cmakelocatorfilter.cpp", "cmakelocatorfilter.cpp",
"cmakelocatorfilter.h", "cmakelocatorfilter.h",
"cmakeopenprojectwizard.cpp", "cmakeopenprojectwizard.cpp",

View File

@@ -36,6 +36,7 @@
#include "cmakeprojectconstants.h" #include "cmakeprojectconstants.h"
#include "cmakelocatorfilter.h" #include "cmakelocatorfilter.h"
#include "cmakefilecompletionassist.h" #include "cmakefilecompletionassist.h"
#include "cmakehighlighterfactory.h"
#include <coreplugin/featureprovider.h> #include <coreplugin/featureprovider.h>
#include <coreplugin/icore.h> #include <coreplugin/icore.h>
@@ -82,6 +83,7 @@ bool CMakeProjectPlugin::initialize(const QStringList & /*arguments*/, QString *
addAutoReleasedObject(new CMakeLocatorFilter); addAutoReleasedObject(new CMakeLocatorFilter);
addAutoReleasedObject(new CMakeFileCompletionAssistProvider(cmp)); addAutoReleasedObject(new CMakeFileCompletionAssistProvider(cmp));
addAutoReleasedObject(new CMakeFeatureProvider); addAutoReleasedObject(new CMakeFeatureProvider);
addAutoReleasedObject(new CMakeHighlighterFactory);
return true; return true;
} }

View File

@@ -11,6 +11,7 @@ HEADERS += cppeditorplugin.h \
cppfilewizard.h \ cppfilewizard.h \
cppfunctiondecldeflink.h \ cppfunctiondecldeflink.h \
cpphighlighter.h \ cpphighlighter.h \
cpphighlighterfactory.h \
cpphoverhandler.h \ cpphoverhandler.h \
cppoutline.h \ cppoutline.h \
cppquickfixassistant.h \ cppquickfixassistant.h \
@@ -27,6 +28,7 @@ SOURCES += cppeditorplugin.cpp \
cppfilewizard.cpp \ cppfilewizard.cpp \
cppfunctiondecldeflink.cpp \ cppfunctiondecldeflink.cpp \
cpphighlighter.cpp \ cpphighlighter.cpp \
cpphighlighterfactory.cpp \
cpphoverhandler.cpp \ cpphoverhandler.cpp \
cppoutline.cpp \ cppoutline.cpp \
cppquickfixassistant.cpp \ cppquickfixassistant.cpp \

View File

@@ -37,6 +37,8 @@ QtcPlugin {
"cppfunctiondecldeflink.h", "cppfunctiondecldeflink.h",
"cpphighlighter.cpp", "cpphighlighter.cpp",
"cpphighlighter.h", "cpphighlighter.h",
"cpphighlighterfactory.cpp",
"cpphighlighterfactory.h",
"cpphoverhandler.cpp", "cpphoverhandler.cpp",
"cpphoverhandler.h", "cpphoverhandler.h",
"cppoutline.cpp", "cppoutline.cpp",

View File

@@ -39,6 +39,7 @@
#include "cppsnippetprovider.h" #include "cppsnippetprovider.h"
#include "cppquickfixassistant.h" #include "cppquickfixassistant.h"
#include "cppquickfixes.h" #include "cppquickfixes.h"
#include "cpphighlighterfactory.h"
#include <coreplugin/actionmanager/actioncontainer.h> #include <coreplugin/actionmanager/actioncontainer.h>
#include <coreplugin/actionmanager/actionmanager.h> #include <coreplugin/actionmanager/actionmanager.h>
@@ -160,6 +161,7 @@ bool CppEditorPlugin::initialize(const QStringList & /*arguments*/, QString *err
addAutoReleasedObject(new CppOutlineWidgetFactory); addAutoReleasedObject(new CppOutlineWidgetFactory);
addAutoReleasedObject(new CppTypeHierarchyFactory); addAutoReleasedObject(new CppTypeHierarchyFactory);
addAutoReleasedObject(new CppSnippetProvider); addAutoReleasedObject(new CppSnippetProvider);
addAutoReleasedObject(new CppHighlighterFactory);
m_quickFixProvider = new CppQuickFixAssistProvider; m_quickFixProvider = new CppQuickFixAssistProvider;
addAutoReleasedObject(m_quickFixProvider); addAutoReleasedObject(m_quickFixProvider);

View File

@@ -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;
}

View File

@@ -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

View File

@@ -38,15 +38,20 @@
#include <QToolButton> #include <QToolButton>
#include <texteditor/basetexteditor.h> #include <texteditor/basetexteditor.h>
#include <texteditor/snippets/snippeteditor.h>
#include <texteditor/basetextdocumentlayout.h> #include <texteditor/basetextdocumentlayout.h>
#include <texteditor/ihighlighterfactory.h>
#include <texteditor/syntaxhighlighter.h> #include <texteditor/syntaxhighlighter.h>
#include <texteditor/basetextdocument.h> #include <texteditor/basetextdocument.h>
#include <texteditor/texteditorsettings.h> #include <texteditor/texteditorsettings.h>
#include <texteditor/fontsettings.h> #include <texteditor/fontsettings.h>
#include <texteditor/displaysettings.h> #include <texteditor/displaysettings.h>
#include <texteditor/generichighlighter/highlighter.h>
#include <coreplugin/icore.h>
#include <coreplugin/minisplitter.h> #include <coreplugin/minisplitter.h>
#include <coreplugin/mimedatabase.h>
#include <extensionsystem/pluginmanager.h>
#include <utils/tooltip/tipcontents.h> #include <utils/tooltip/tipcontents.h>
#include <utils/tooltip/tooltip.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 FILE_LEVEL = 1;
static const int CHUNK_LEVEL = 2; static const int CHUNK_LEVEL = 2;
using namespace Core;
using namespace TextEditor; using namespace TextEditor;
namespace DiffEditor { namespace DiffEditor {
@@ -103,7 +109,7 @@ struct FileData {
class DiffViewEditorEditable : public BaseTextEditor class DiffViewEditorEditable : public BaseTextEditor
{ {
Q_OBJECT Q_OBJECT
public: public:
DiffViewEditorEditable(BaseTextEditorWidget *editorWidget) DiffViewEditorEditable(BaseTextEditorWidget *editorWidget)
: BaseTextEditor(editorWidget) : BaseTextEditor(editorWidget)
@@ -119,27 +125,50 @@ private slots:
}; };
class MultiHighlighter : public SyntaxHighlighter
////////////////////////
class DiffViewEditorWidget : public SnippetEditorWidget
{ {
Q_OBJECT Q_OBJECT
public: 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 BaseTextEditorWidget
{
Q_OBJECT
public:
struct ExtendedFileInfo
{
DiffEditorWidget::DiffFileInfo fileInfo;
TextEditor::SyntaxHighlighter *highlighter;
};
DiffViewEditorWidget(QWidget *parent = 0); DiffViewEditorWidget(QWidget *parent = 0);
void setSyntaxHighlighter(SyntaxHighlighter *sh) { // TODO: remove me, codec should be taken from somewhere else
baseTextDocument()->setSyntaxHighlighter(sh);
}
QTextCodec *codec() const { QTextCodec *codec() const {
return const_cast<QTextCodec *>(baseTextDocument()->codec()); 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; } QMap<int, DiffEditorWidget::DiffFileInfo> fileInfo() const { return m_fileInfo; }
void setLineNumber(int blockNumber, int lineNumber); 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 setSkippedLines(int blockNumber, int skippedLines) { m_skippedLines[blockNumber] = skippedLines; setSeparator(blockNumber, true); }
void setSeparator(int blockNumber, bool separator) { m_separators[blockNumber] = separator; } void setSeparator(int blockNumber, bool separator) { m_separators[blockNumber] = separator; }
bool isFileLine(int blockNumber) const { return m_fileInfo.contains(blockNumber); } bool isFileLine(int blockNumber) const { return m_fileInfo.contains(blockNumber); }
@@ -149,7 +178,8 @@ public:
void clearAll(); void clearAll();
void clearAll(const QString &message); void clearAll(const QString &message);
void clearAllData(); 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: public slots:
void setDisplaySettings(const DisplaySettings &ds); void setDisplaySettings(const DisplaySettings &ds);
@@ -183,20 +213,108 @@ private:
const QTextBlock &block, int top); const QTextBlock &block, int top);
void jumpToOriginalFile(const QTextCursor &cursor); void jumpToOriginalFile(const QTextCursor &cursor);
// block number, visual line number.
QMap<int, int> m_lineNumbers; QMap<int, int> m_lineNumbers;
int m_lineNumberDigits; int m_lineNumberDigits;
// block number, fileInfo // block number, fileInfo. Set for file lines only.
QMap<int, DiffEditorWidget::DiffFileInfo> m_fileInfo; QMap<int, DiffEditorWidget::DiffFileInfo> m_fileInfo;
// block number, skipped lines // block number, skipped lines. Set for chunk lines only.
QMap<int, int> m_skippedLines; 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; QMap<int, bool> m_separators;
bool m_inPaintEvent; bool m_inPaintEvent;
QColor m_fileLineForeground; QColor m_fileLineForeground;
QColor m_chunkLineForeground; QColor m_chunkLineForeground;
QColor m_textForeground; 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) void DiffViewEditorEditable::slotTooltipRequested(TextEditor::ITextEditor *editor, const QPoint &globalPoint, int position)
{ {
DiffViewEditorWidget *ew = qobject_cast<DiffViewEditorWidget *>(editorWidget()); DiffViewEditorWidget *ew = qobject_cast<DiffViewEditorWidget *>(editorWidget());
@@ -216,7 +334,7 @@ void DiffViewEditorEditable::slotTooltipRequested(TextEditor::ITextEditor *edito
} }
DiffViewEditorWidget::DiffViewEditorWidget(QWidget *parent) DiffViewEditorWidget::DiffViewEditorWidget(QWidget *parent)
: SnippetEditorWidget(parent), m_lineNumberDigits(1), m_inPaintEvent(false) : BaseTextEditorWidget(parent), m_lineNumberDigits(1), m_inPaintEvent(false)
{ {
DisplaySettings settings = displaySettings(); DisplaySettings settings = displaySettings();
settings.m_textWrapping = false; settings.m_textWrapping = false;
@@ -225,22 +343,25 @@ DiffViewEditorWidget::DiffViewEditorWidget(QWidget *parent)
settings.m_displayFoldingMarkers = true; settings.m_displayFoldingMarkers = true;
settings.m_markTextChanges = false; settings.m_markTextChanges = false;
settings.m_highlightBlocks = false; settings.m_highlightBlocks = false;
SnippetEditorWidget::setDisplaySettings(settings); BaseTextEditorWidget::setDisplaySettings(settings);
setCodeFoldingSupported(true); setCodeFoldingSupported(true);
setFrameStyle(QFrame::NoFrame); setFrameStyle(QFrame::NoFrame);
m_highlighter = new MultiHighlighter(this, baseTextDocument()->document());
baseTextDocument()->setSyntaxHighlighter(m_highlighter);
} }
void DiffViewEditorWidget::setDisplaySettings(const DisplaySettings &ds) void DiffViewEditorWidget::setDisplaySettings(const DisplaySettings &ds)
{ {
DisplaySettings settings = displaySettings(); DisplaySettings settings = displaySettings();
settings.m_visualizeWhitespace = ds.m_visualizeWhitespace; settings.m_visualizeWhitespace = ds.m_visualizeWhitespace;
SnippetEditorWidget::setDisplaySettings(settings); BaseTextEditorWidget::setDisplaySettings(settings);
} }
void DiffViewEditorWidget::setFontSettings(const TextEditor::FontSettings &fs) void DiffViewEditorWidget::setFontSettings(const TextEditor::FontSettings &fs)
{ {
SnippetEditorWidget::setFontSettings(fs); BaseTextEditorWidget::setFontSettings(fs);
m_fileLineForeground = fs.formatFor(C_DIFF_FILE_LINE).foreground(); m_fileLineForeground = fs.formatFor(C_DIFF_FILE_LINE).foreground();
m_chunkLineForeground = fs.formatFor(C_DIFF_CONTEXT_LINE).foreground(); m_chunkLineForeground = fs.formatFor(C_DIFF_CONTEXT_LINE).foreground();
m_textForeground = fs.toTextCharFormat(C_TEXT).foreground().color(); 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()); 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 int DiffViewEditorWidget::blockNumberForFileIndex(int fileIndex) const
{ {
if (fileIndex < 0 || fileIndex >= m_fileInfo.count()) if (fileIndex < 0 || fileIndex >= m_fileInfo.count())
@@ -359,6 +486,7 @@ void DiffViewEditorWidget::clearAll(const QString &message)
clear(); clear();
clearAllData(); clearAllData();
setPlainText(message); setPlainText(message);
m_highlighter->setDocuments(QList<QPair<DiffEditorWidget::DiffFileInfo, QString> >());
} }
void DiffViewEditorWidget::clearAllData() void DiffViewEditorWidget::clearAllData()
@@ -370,9 +498,14 @@ void DiffViewEditorWidget::clearAllData()
m_separators.clear(); m_separators.clear();
} }
void DiffViewEditorWidget::setDocuments(const QList<QPair<DiffEditorWidget::DiffFileInfo, QString> > &documents)
{
m_highlighter->setDocuments(documents);
}
void DiffViewEditorWidget::scrollContentsBy(int dx, int dy) void DiffViewEditorWidget::scrollContentsBy(int dx, int dy)
{ {
SnippetEditorWidget::scrollContentsBy(dx, dy); BaseTextEditorWidget::scrollContentsBy(dx, dy);
// TODO: update only chunk lines // TODO: update only chunk lines
viewport()->update(); viewport()->update();
} }
@@ -423,7 +556,7 @@ void DiffViewEditorWidget::mouseDoubleClickEvent(QMouseEvent *e)
e->accept(); e->accept();
return; return;
} }
SnippetEditorWidget::mouseDoubleClickEvent(e); BaseTextEditorWidget::mouseDoubleClickEvent(e);
} }
void DiffViewEditorWidget::jumpToOriginalFile(const QTextCursor &cursor) void DiffViewEditorWidget::jumpToOriginalFile(const QTextCursor &cursor)
@@ -444,7 +577,7 @@ void DiffViewEditorWidget::jumpToOriginalFile(const QTextCursor &cursor)
void DiffViewEditorWidget::paintEvent(QPaintEvent *e) void DiffViewEditorWidget::paintEvent(QPaintEvent *e)
{ {
m_inPaintEvent = true; m_inPaintEvent = true;
SnippetEditorWidget::paintEvent(e); BaseTextEditorWidget::paintEvent(e);
m_inPaintEvent = false; m_inPaintEvent = false;
QPainter painter(viewport()); QPainter painter(viewport());
@@ -760,12 +893,12 @@ QTextCodec *DiffEditorWidget::codec() const
return const_cast<QTextCodec *>(m_leftEditor->codec()); return const_cast<QTextCodec *>(m_leftEditor->codec());
} }
SnippetEditorWidget *DiffEditorWidget::leftEditor() const BaseTextEditorWidget *DiffEditorWidget::leftEditor() const
{ {
return m_leftEditor; return m_leftEditor;
} }
SnippetEditorWidget *DiffEditorWidget::rightEditor() const BaseTextEditorWidget *DiffEditorWidget::rightEditor() const
{ {
return m_rightEditor; return m_rightEditor;
} }
@@ -1150,18 +1283,20 @@ void DiffEditorWidget::showDiff()
clear(); clear();
QString leftText, rightText; QList<QPair<DiffEditorWidget::DiffFileInfo, QString> > leftDocs, rightDocs;
QString leftTexts, rightTexts;
int blockNumber = 0; int blockNumber = 0;
QChar separator = QLatin1Char('\n'); QChar separator = QLatin1Char('\n');
for (int i = 0; i < m_contextFileData.count(); i++) { for (int i = 0; i < m_contextFileData.count(); i++) {
QString leftText, rightText;
const FileData &contextFileData = m_contextFileData.at(i); const FileData &contextFileData = m_contextFileData.at(i);
int leftLineNumber = 0; int leftLineNumber = 0;
int rightLineNumber = 0; int rightLineNumber = 0;
m_leftEditor->setFileInfo(blockNumber, contextFileData.leftFileInfo); m_leftEditor->setFileInfo(blockNumber, contextFileData.leftFileInfo);
m_rightEditor->setFileInfo(blockNumber, contextFileData.rightFileInfo); m_rightEditor->setFileInfo(blockNumber, contextFileData.rightFileInfo);
leftText += separator; leftText = separator;
rightText += separator; rightText = separator;
blockNumber++; blockNumber++;
for (int j = 0; j < contextFileData.chunks.count(); j++) { for (int j = 0; j < contextFileData.chunks.count(); j++) {
@@ -1199,13 +1334,20 @@ void DiffEditorWidget::showDiff()
blockNumber++; 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; return;
m_leftEditor->setPlainText(leftText); m_leftEditor->setDocuments(leftDocs);
m_rightEditor->setPlainText(rightText); m_rightEditor->setDocuments(rightDocs);
m_leftEditor->setPlainText(leftTexts);
m_rightEditor->setPlainText(rightTexts);
colorDiff(m_contextFileData); colorDiff(m_contextFileData);

View File

@@ -37,7 +37,6 @@
namespace TextEditor { namespace TextEditor {
class BaseTextEditorWidget; class BaseTextEditorWidget;
class SnippetEditorWidget;
class FontSettings; class FontSettings;
} }
@@ -98,8 +97,8 @@ signals:
void navigatedToDiffFile(int diffFileIndex); void navigatedToDiffFile(int diffFileIndex);
protected: protected:
TextEditor::SnippetEditorWidget *leftEditor() const; TextEditor::BaseTextEditorWidget *leftEditor() const;
TextEditor::SnippetEditorWidget *rightEditor() const; TextEditor::BaseTextEditorWidget *rightEditor() const;
private slots: private slots:
void setFontSettings(const TextEditor::FontSettings &fontSettings); void setFontSettings(const TextEditor::FontSettings &fontSettings);

View File

@@ -11,6 +11,7 @@ glsleditorfactory.h \
glsleditorplugin.h \ glsleditorplugin.h \
glslfilewizard.h \ glslfilewizard.h \
glslhighlighter.h \ glslhighlighter.h \
glslhighlighterfactory.h \
glslautocompleter.h \ glslautocompleter.h \
glslindenter.h \ glslindenter.h \
glslhoverhandler.h \ glslhoverhandler.h \
@@ -24,6 +25,7 @@ glsleditorfactory.cpp \
glsleditorplugin.cpp \ glsleditorplugin.cpp \
glslfilewizard.cpp \ glslfilewizard.cpp \
glslhighlighter.cpp \ glslhighlighter.cpp \
glslhighlighterfactory.cpp \
glslautocompleter.cpp \ glslautocompleter.cpp \
glslindenter.cpp \ glslindenter.cpp \
glslhoverhandler.cpp \ glslhoverhandler.cpp \

View File

@@ -32,6 +32,8 @@ QtcPlugin {
"glslfilewizard.h", "glslfilewizard.h",
"glslhighlighter.cpp", "glslhighlighter.cpp",
"glslhighlighter.h", "glslhighlighter.h",
"glslhighlighterfactory.cpp",
"glslhighlighterfactory.h",
"glslhoverhandler.cpp", "glslhoverhandler.cpp",
"glslhoverhandler.h", "glslhoverhandler.h",
"glslindenter.cpp", "glslindenter.cpp",

View File

@@ -34,6 +34,7 @@
#include "glslfilewizard.h" #include "glslfilewizard.h"
#include "glslhoverhandler.h" #include "glslhoverhandler.h"
#include "glslcompletionassist.h" #include "glslcompletionassist.h"
#include "glslhighlighterfactory.h"
#include <coreplugin/icore.h> #include <coreplugin/icore.h>
#include <coreplugin/coreconstants.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.setDisplayName(tr("Vertex Shader (Desktop OpenGL)"));
vertWizardParameters.setId(QLatin1String("K.GLSL")); vertWizardParameters.setId(QLatin1String("K.GLSL"));
addAutoReleasedObject(new GLSLFileWizard(vertWizardParameters, GLSLFileWizard::VertexShaderDesktop, core)); addAutoReleasedObject(new GLSLFileWizard(vertWizardParameters, GLSLFileWizard::VertexShaderDesktop, core));
addAutoReleasedObject(new GLSLHighlighterFactory);
return true; return true;
} }

View File

@@ -39,8 +39,19 @@ using namespace GLSLEditor;
using namespace GLSLEditor::Internal; using namespace GLSLEditor::Internal;
using namespace TextEditor; using namespace TextEditor;
Highlighter::Highlighter(QTextDocument *parent)
: TextEditor::SyntaxHighlighter(parent)
{
init();
}
Highlighter::Highlighter(BaseTextDocument *parent) Highlighter::Highlighter(BaseTextDocument *parent)
: TextEditor::SyntaxHighlighter(parent) : TextEditor::SyntaxHighlighter(parent)
{
init();
}
void Highlighter::init()
{ {
static QVector<TextEditor::TextStyle> categories; static QVector<TextEditor::TextStyle> categories;
if (categories.isEmpty()) { if (categories.isEmpty()) {

View File

@@ -57,6 +57,7 @@ public:
NumGLSLFormats NumGLSLFormats
}; };
explicit Highlighter(QTextDocument *parent = 0);
explicit Highlighter(TextEditor::BaseTextDocument *parent); explicit Highlighter(TextEditor::BaseTextDocument *parent);
virtual ~Highlighter(); virtual ~Highlighter();
@@ -64,6 +65,9 @@ protected:
void highlightBlock(const QString &text); void highlightBlock(const QString &text);
void highlightLine(const QString &text, int position, int length, const QTextCharFormat &format); void highlightLine(const QString &text, int position, int length, const QTextCharFormat &format);
bool isPPKeyword(const QStringRef &text) const; bool isPPKeyword(const QStringRef &text) const;
private:
void init();
}; };
} // namespace Internal } // namespace Internal

View File

@@ -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;
}

View File

@@ -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

View File

@@ -18,6 +18,7 @@ HEADERS += \
wizard/pythonclasswizarddialog.h \ wizard/pythonclasswizarddialog.h \
wizard/pythonsourcegenerator.h \ wizard/pythonsourcegenerator.h \
tools/pythonhighlighter.h \ tools/pythonhighlighter.h \
tools/pythonhighlighterfactory.h \
tools/pythonindenter.h \ tools/pythonindenter.h \
tools/lexical/pythonformattoken.h \ tools/lexical/pythonformattoken.h \
tools/lexical/pythonscanner.h \ tools/lexical/pythonscanner.h \
@@ -34,5 +35,6 @@ SOURCES += \
wizard/pythonclassnamepage.cpp \ wizard/pythonclassnamepage.cpp \
wizard/pythonsourcegenerator.cpp \ wizard/pythonsourcegenerator.cpp \
tools/pythonhighlighter.cpp \ tools/pythonhighlighter.cpp \
tools/pythonhighlighterfactory.cpp \
tools/pythonindenter.cpp \ tools/pythonindenter.cpp \
tools/lexical/pythonscanner.cpp tools/lexical/pythonscanner.cpp

View File

@@ -32,6 +32,7 @@ QtcPlugin {
"lexical/pythonscanner.h", "lexical/pythonscanner.cpp", "lexical/pythonscanner.h", "lexical/pythonscanner.cpp",
"lexical/sourcecodestream.h", "lexical/sourcecodestream.h",
"pythonhighlighter.h", "pythonhighlighter.cpp", "pythonhighlighter.h", "pythonhighlighter.cpp",
"pythonhighlighterfactory.h", "pythonhighlighterfactory.cpp",
"pythonindenter.cpp", "pythonindenter.h" "pythonindenter.cpp", "pythonindenter.h"
] ]
} }

View File

@@ -33,6 +33,7 @@
#include "wizard/pythonclasswizard.h" #include "wizard/pythonclasswizard.h"
#include "pythoneditorwidget.h" #include "pythoneditorwidget.h"
#include "pythoneditorfactory.h" #include "pythoneditorfactory.h"
#include "tools/pythonhighlighterfactory.h"
#include <coreplugin/icore.h> #include <coreplugin/icore.h>
#include <coreplugin/coreconstants.h> #include <coreplugin/coreconstants.h>
@@ -252,6 +253,7 @@ bool PythonEditorPlugin::initialize(
//////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////
addAutoReleasedObject(new FileWizard(Core::ICore::instance())); addAutoReleasedObject(new FileWizard(Core::ICore::instance()));
addAutoReleasedObject(new ClassWizard(Core::ICore::instance())); addAutoReleasedObject(new ClassWizard(Core::ICore::instance()));
addAutoReleasedObject(new Internal::PythonHighlighterFactory);
return true; return true;
} }

View File

@@ -65,9 +65,20 @@ using namespace PythonEditor::Internal;
* @endcode * @endcode
*/ */
PythonHighlighter::PythonHighlighter(QTextDocument *parent) :
TextEditor::SyntaxHighlighter(parent)
{
init();
}
/// New instance created when opening any document in editor /// New instance created when opening any document in editor
PythonHighlighter::PythonHighlighter(TextEditor::BaseTextDocument *parent) : PythonHighlighter::PythonHighlighter(TextEditor::BaseTextDocument *parent) :
TextEditor::SyntaxHighlighter(parent) TextEditor::SyntaxHighlighter(parent)
{
init();
}
void PythonHighlighter::init()
{ {
static QVector<TextEditor::TextStyle> categories; static QVector<TextEditor::TextStyle> categories;
if (categories.isEmpty()) { if (categories.isEmpty()) {

View File

@@ -40,6 +40,7 @@ class PythonHighlighter : public TextEditor::SyntaxHighlighter
{ {
Q_OBJECT Q_OBJECT
public: public:
explicit PythonHighlighter(QTextDocument *parent = 0);
explicit PythonHighlighter(TextEditor::BaseTextDocument *parent); explicit PythonHighlighter(TextEditor::BaseTextDocument *parent);
virtual ~PythonHighlighter(); virtual ~PythonHighlighter();
@@ -49,6 +50,7 @@ protected:
private: private:
int highlightLine(const QString &text, int initialState); int highlightLine(const QString &text, int initialState);
void highlightImport(Internal::Scanner &scanner); void highlightImport(Internal::Scanner &scanner);
void init();
}; };
} // namespace PythonEditor } // namespace PythonEditor

View File

@@ -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;
}

View File

@@ -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

View File

@@ -13,6 +13,7 @@ HEADERS += \
qmlexpressionundercursor.h \ qmlexpressionundercursor.h \
qmlfilewizard.h \ qmlfilewizard.h \
qmljshighlighter.h \ qmljshighlighter.h \
qmljshighlighterfactory.h \
qmljshoverhandler.h \ qmljshoverhandler.h \
qmljspreviewrunner.h \ qmljspreviewrunner.h \
qmljscomponentfromobjectdef.h \ qmljscomponentfromobjectdef.h \
@@ -43,6 +44,7 @@ SOURCES += \
qmlexpressionundercursor.cpp \ qmlexpressionundercursor.cpp \
qmlfilewizard.cpp \ qmlfilewizard.cpp \
qmljshighlighter.cpp \ qmljshighlighter.cpp \
qmljshighlighterfactory.cpp \
qmljshoverhandler.cpp \ qmljshoverhandler.cpp \
qmljspreviewrunner.cpp \ qmljspreviewrunner.cpp \
qmljscomponentfromobjectdef.cpp \ qmljscomponentfromobjectdef.cpp \

View File

@@ -47,6 +47,8 @@ QtcPlugin {
"qmljsfindreferences.h", "qmljsfindreferences.h",
"qmljshighlighter.cpp", "qmljshighlighter.cpp",
"qmljshighlighter.h", "qmljshighlighter.h",
"qmljshighlighterfactory.cpp",
"qmljshighlighterfactory.h",
"qmljshoverhandler.cpp", "qmljshoverhandler.cpp",
"qmljshoverhandler.h", "qmljshoverhandler.h",
"qmljsoutline.cpp", "qmljsoutline.cpp",

View File

@@ -43,6 +43,7 @@
#include "quicktoolbarsettingspage.h" #include "quicktoolbarsettingspage.h"
#include "qmljscompletionassist.h" #include "qmljscompletionassist.h"
#include "qmljsquickfixassist.h" #include "qmljsquickfixassist.h"
#include "qmljshighlighterfactory.h"
#include <qmljs/qmljsicons.h> #include <qmljs/qmljsicons.h>
#include <qmljs/qmljsmodelmanagerinterface.h> #include <qmljs/qmljsmodelmanagerinterface.h>
@@ -115,6 +116,7 @@ bool QmlJSEditorPlugin::initialize(const QStringList & /*arguments*/, QString *e
{ {
m_modelManager = QmlJS::ModelManagerInterface::instance(); m_modelManager = QmlJS::ModelManagerInterface::instance();
addAutoReleasedObject(new QmlJSSnippetProvider); addAutoReleasedObject(new QmlJSSnippetProvider);
addAutoReleasedObject(new QmlJSHighlighterFactory);
// QML task updating manager // QML task updating manager
m_qmlTaskManager = new QmlTaskManager; m_qmlTaskManager = new QmlTaskManager;

View File

@@ -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;
}

View File

@@ -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

View File

@@ -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;
}

View File

@@ -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

View File

@@ -14,6 +14,7 @@ HEADERS += \
qt4nodes.h \ qt4nodes.h \
profileeditor.h \ profileeditor.h \
profilehighlighter.h \ profilehighlighter.h \
profilehighlighterfactory.h \
profileeditorfactory.h \ profileeditorfactory.h \
profilehoverhandler.h \ profilehoverhandler.h \
wizards/qtprojectparameters.h \ wizards/qtprojectparameters.h \
@@ -77,6 +78,7 @@ SOURCES += \
qt4nodes.cpp \ qt4nodes.cpp \
profileeditor.cpp \ profileeditor.cpp \
profilehighlighter.cpp \ profilehighlighter.cpp \
profilehighlighterfactory.cpp \
profileeditorfactory.cpp \ profileeditorfactory.cpp \
profilehoverhandler.cpp \ profilehoverhandler.cpp \
wizards/qtprojectparameters.cpp \ wizards/qtprojectparameters.cpp \

View File

@@ -39,6 +39,7 @@ QtcPlugin {
"profileeditor.cpp", "profileeditor.h", "profileeditor.cpp", "profileeditor.h",
"profileeditorfactory.cpp", "profileeditorfactory.h", "profileeditorfactory.cpp", "profileeditorfactory.h",
"profilehighlighter.cpp", "profilehighlighter.h", "profilehighlighter.cpp", "profilehighlighter.h",
"profilehighlighterfactory.cpp", "profilehighlighterfactory.h",
"profilehoverhandler.cpp", "profilehoverhandler.h", "profilehoverhandler.cpp", "profilehoverhandler.h",
"qmakeparser.cpp", "qmakeparser.h", "qmakeparser.cpp", "qmakeparser.h",
"qmakekitconfigwidget.cpp", "qmakekitconfigwidget.h", "qmakekitconfigwidget.cpp", "qmakekitconfigwidget.h",

View File

@@ -55,6 +55,7 @@
#include "winceqtversionfactory.h" #include "winceqtversionfactory.h"
#include "unconfiguredprojectpanel.h" #include "unconfiguredprojectpanel.h"
#include "qmakekitinformation.h" #include "qmakekitinformation.h"
#include "profilehighlighterfactory.h"
#include <coreplugin/icore.h> #include <coreplugin/icore.h>
#include <projectexplorer/buildmanager.h> #include <projectexplorer/buildmanager.h>
@@ -156,6 +157,7 @@ bool Qt4ProjectManagerPlugin::initialize(const QStringList &arguments, QString *
addAutoReleasedObject(new ProFileCompletionAssistProvider); addAutoReleasedObject(new ProFileCompletionAssistProvider);
addAutoReleasedObject(new ProFileHoverHandler(this)); addAutoReleasedObject(new ProFileHoverHandler(this));
addAutoReleasedObject(new UnconfiguredProjectPanel); addAutoReleasedObject(new UnconfiguredProjectPanel);
addAutoReleasedObject(new ProFileHighlighterFactory);
//menus //menus
Core::ActionContainer *mbuild = Core::ActionContainer *mbuild =

View File

@@ -36,6 +36,8 @@
#include "progressdata.h" #include "progressdata.h"
#include "reuse.h" #include "reuse.h"
#include "tabsettings.h" #include "tabsettings.h"
#include "manager.h"
#include <coreplugin/icore.h>
#include <QLatin1String> #include <QLatin1String>
#include <QLatin1Char> #include <QLatin1Char>
@@ -117,6 +119,40 @@ 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;

View File

@@ -30,8 +30,8 @@
#ifndef HIGHLIGHTER_H #ifndef HIGHLIGHTER_H
#define HIGHLIGHTER_H #define HIGHLIGHTER_H
#include "basetextdocumentlayout.h" #include <texteditor/basetextdocumentlayout.h>
#include "syntaxhighlighter.h" #include <texteditor/syntaxhighlighter.h>
#include <QString> #include <QString>
#include <QVector> #include <QVector>
@@ -41,10 +41,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;
@@ -52,7 +54,9 @@ class Context;
class HighlightDefinition; class HighlightDefinition;
class ProgressData; class ProgressData;
class Highlighter : public TextEditor::SyntaxHighlighter } // namespace Internal
class TEXTEDITOR_EXPORT Highlighter : public TextEditor::SyntaxHighlighter
{ {
Q_OBJECT Q_OBJECT
@@ -79,7 +83,9 @@ public:
}; };
void setTabSettings(const TabSettings &ts); 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: protected:
virtual void highlightBlock(const QString &text); virtual void highlightBlock(const QString &text);
@@ -94,17 +100,18 @@ private:
void iterateThroughRules(const QString &text, void iterateThroughRules(const QString &text,
const int length, const int length,
ProgressData *progress, Internal::ProgressData *progress,
const bool childRule, const bool childRule,
const QList<QSharedPointer<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,
const QSharedPointer<HighlightDefinition> &definition, const QSharedPointer<Internal::HighlightDefinition> &definition,
const bool setCurrent = true); const bool setCurrent = true);
void changeContext(const QString &contextName, void changeContext(const QString &contextName,
const QSharedPointer<HighlightDefinition> &definition, const QSharedPointer<Internal::HighlightDefinition> &definition,
const bool assignCurrent = true); const bool assignCurrent = true);
QString currentContextSequence() const; QString currentContextSequence() const;
@@ -112,7 +119,7 @@ private:
void mapLeadingSequence(const QString &contextSequence); void mapLeadingSequence(const QString &contextSequence);
void pushContextSequence(int state); void pushContextSequence(int state);
void pushDynamicContext(const QSharedPointer<Context> &baseContext); void pushDynamicContext(const QSharedPointer<Internal::Context> &baseContext);
void createWillContinueBlock(); void createWillContinueBlock();
void analyseConsistencyOfWillContinueBlock(const QString &text); void analyseConsistencyOfWillContinueBlock(const QString &text);
@@ -120,7 +127,7 @@ private:
void applyFormat(int offset, void applyFormat(int offset,
int count, int count,
const QString &itemDataName, const QString &itemDataName,
const QSharedPointer<HighlightDefinition> &definition); const QSharedPointer<Internal::HighlightDefinition> &definition);
void applyRegionBasedFolding() const; void applyRegionBasedFolding() const;
void applyIndentationBasedFolding(const QString &text) const; void applyIndentationBasedFolding(const QString &text) const;
@@ -142,7 +149,7 @@ private:
int m_foldingIndentDelta; int m_foldingIndentDelta;
int m_originalObservableState; int m_originalObservableState;
QStack<QString> m_foldingRegions; QStack<QString> m_foldingRegions;
QSharedPointer<Context> m_contextToContinue; QSharedPointer<Internal::Context> m_contextToContinue;
}; };
BlockData *initializeBlockData(); BlockData *initializeBlockData();
static BlockData *blockData(QTextBlockUserData *userData); static BlockData *blockData(QTextBlockUserData *userData);
@@ -179,22 +186,21 @@ private:
bool m_isBroken; bool m_isBroken;
QSharedPointer<Context> m_defaultContext; QSharedPointer<Internal::Context> m_defaultContext;
QSharedPointer<Context> m_currentContext; QSharedPointer<Internal::Context> m_currentContext;
QVector<QSharedPointer<Context> > m_contexts; QVector<QSharedPointer<Internal::Context> > m_contexts;
// Mapping from context sequences to the observable persistent state they represent. // Mapping from context sequences to the observable persistent state they represent.
QHash<QString, int> m_persistentObservableStates; QHash<QString, int> m_persistentObservableStates;
// Mapping from context sequences to the non-persistent observable state that led to them. // Mapping from context sequences to the non-persistent observable state that led to them.
QHash<QString, int> m_leadingObservableStates; QHash<QString, int> m_leadingObservableStates;
// Mapping from observable persistent states to context sequences (the actual "stack"). // 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. // Captures used in dynamic rules.
QStringList m_currentCaptures; QStringList m_currentCaptures;
}; };
} // namespace Internal
} // namespace TextEditor } // namespace TextEditor
#endif // HIGHLIGHTER_H #endif // HIGHLIGHTER_H

View File

@@ -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

View File

@@ -125,20 +125,19 @@ void PlainTextEditorWidget::configure(const Core::MimeType &mimeType)
if (!mimeType.isNull()) { if (!mimeType.isNull()) {
m_isMissingSyntaxDefinition = true; m_isMissingSyntaxDefinition = true;
highlighter->setMimeType(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 = findDefinitionId(mimeType, true); definitionId = Highlighter::findDefinitionId(mimeType, true);
if (!definitionId.isEmpty()) { if (!definitionId.isEmpty()) {
m_isMissingSyntaxDefinition = false; m_isMissingSyntaxDefinition = false;
const QSharedPointer<HighlightDefinition> &definition = const QSharedPointer<HighlightDefinition> &definition =
Manager::instance()->definition(definitionId); Manager::instance()->definition(definitionId);
if (!definition.isNull() && definition->isValid()) { if (!definition.isNull() && definition->isValid()) {
highlighter->setDefaultContext(definition->initialContext());
m_commentDefinition.isAfterWhiteSpaces = definition->isCommentAfterWhiteSpaces(); m_commentDefinition.isAfterWhiteSpaces = definition->isCommentAfterWhiteSpaces();
m_commentDefinition.singleLine = definition->singleLineComment(); m_commentDefinition.singleLine = definition->singleLineComment();
m_commentDefinition.multiLineStart = definition->multiLineCommentStart(); m_commentDefinition.multiLineStart = definition->multiLineCommentStart();
@@ -163,23 +162,6 @@ bool PlainTextEditorWidget::isMissingSyntaxDefinition() const
return m_isMissingSyntaxDefinition; 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() void PlainTextEditorWidget::acceptMissingSyntaxDefinitionInfo()
{ {
ICore::showOptionsDialog(Constants::TEXT_EDITOR_SETTINGS_CATEGORY, ICore::showOptionsDialog(Constants::TEXT_EDITOR_SETTINGS_CATEGORY,

View File

@@ -80,8 +80,6 @@ protected:
virtual BaseTextEditor *createEditor() { return new PlainTextEditor(this); } virtual BaseTextEditor *createEditor() { return new PlainTextEditor(this); }
private: private:
QString findDefinitionId(const Core::MimeType &mimeType, bool considerParents) const;
bool m_isMissingSyntaxDefinition; bool m_isMissingSyntaxDefinition;
Utils::CommentDefinition m_commentDefinition; Utils::CommentDefinition m_commentDefinition;
}; };

View File

@@ -146,6 +146,7 @@ HEADERS += texteditorplugin.h \
normalindenter.h \ normalindenter.h \
indenter.h \ indenter.h \
quickfix.h \ quickfix.h \
ihighlighterfactory.h \
syntaxhighlighter.h \ syntaxhighlighter.h \
generichighlighter/reuse.h \ generichighlighter/reuse.h \
generichighlighter/itemdata.h \ generichighlighter/itemdata.h \

View File

@@ -89,6 +89,7 @@ QtcPlugin {
"icodestylepreferences.h", "icodestylepreferences.h",
"icodestylepreferencesfactory.cpp", "icodestylepreferencesfactory.cpp",
"icodestylepreferencesfactory.h", "icodestylepreferencesfactory.h",
"ihighlighterfactory.cpp",
"indenter.cpp", "indenter.cpp",
"indenter.h", "indenter.h",
"ioutlinewidget.h", "ioutlinewidget.h",