forked from qt-creator/qt-creator
TextEditor: Clean up/streamline SyntaxHighlighter setup
No need for the third construction way if that's not really used by the factories anyway. Change-Id: Id3b34da5b0320babae9bef96a79bbaa52e0db06d Reviewed-by: Christian Stenger <christian.stenger@digia.com>
This commit is contained in:
@@ -290,9 +290,9 @@ void GitEditorWidget::init()
|
|||||||
VcsBase::VcsBaseEditorWidget::init();
|
VcsBase::VcsBaseEditorWidget::init();
|
||||||
Core::Id editorId = editor()->document()->id();
|
Core::Id editorId = editor()->document()->id();
|
||||||
if (editorId == Git::Constants::GIT_COMMIT_TEXT_EDITOR_ID)
|
if (editorId == Git::Constants::GIT_COMMIT_TEXT_EDITOR_ID)
|
||||||
new GitSubmitHighlighter(textDocument());
|
textDocument()->setSyntaxHighlighter(new GitSubmitHighlighter);
|
||||||
else if (editorId == Git::Constants::GIT_REBASE_EDITOR_ID)
|
else if (editorId == Git::Constants::GIT_REBASE_EDITOR_ID)
|
||||||
new GitRebaseHighlighter(textDocument());
|
textDocument()->setSyntaxHighlighter(new GitRebaseHighlighter);
|
||||||
}
|
}
|
||||||
|
|
||||||
void GitEditorWidget::addDiffActions(QMenu *menu, const VcsBase::DiffChunk &chunk)
|
void GitEditorWidget::addDiffActions(QMenu *menu, const VcsBase::DiffChunk &chunk)
|
||||||
|
|||||||
@@ -40,17 +40,6 @@ static const char CHANGE_PATTERN[] = "\\b[a-f0-9]{7,40}\\b";
|
|||||||
|
|
||||||
GitSubmitHighlighter::GitSubmitHighlighter(QTextEdit * parent) :
|
GitSubmitHighlighter::GitSubmitHighlighter(QTextEdit * parent) :
|
||||||
TextEditor::SyntaxHighlighter(parent)
|
TextEditor::SyntaxHighlighter(parent)
|
||||||
{
|
|
||||||
initialize();
|
|
||||||
}
|
|
||||||
|
|
||||||
GitSubmitHighlighter::GitSubmitHighlighter(TextEditor::BaseTextDocument *parent) :
|
|
||||||
TextEditor::SyntaxHighlighter(parent)
|
|
||||||
{
|
|
||||||
initialize();
|
|
||||||
}
|
|
||||||
|
|
||||||
void GitSubmitHighlighter::initialize()
|
|
||||||
{
|
{
|
||||||
static QVector<TextEditor::TextStyle> categories;
|
static QVector<TextEditor::TextStyle> categories;
|
||||||
if (categories.isEmpty())
|
if (categories.isEmpty())
|
||||||
@@ -108,7 +97,7 @@ GitRebaseHighlighter::RebaseAction::RebaseAction(const QString ®exp,
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
GitRebaseHighlighter::GitRebaseHighlighter(TextEditor::BaseTextDocument *parent) :
|
GitRebaseHighlighter::GitRebaseHighlighter(QTextDocument *parent) :
|
||||||
TextEditor::SyntaxHighlighter(parent),
|
TextEditor::SyntaxHighlighter(parent),
|
||||||
m_hashChar(QLatin1Char('#')),
|
m_hashChar(QLatin1Char('#')),
|
||||||
m_changeNumberPattern(QLatin1String(CHANGE_PATTERN))
|
m_changeNumberPattern(QLatin1String(CHANGE_PATTERN))
|
||||||
|
|||||||
@@ -32,8 +32,6 @@
|
|||||||
|
|
||||||
#include <texteditor/syntaxhighlighter.h>
|
#include <texteditor/syntaxhighlighter.h>
|
||||||
|
|
||||||
namespace TextEditor { class FontSettings; }
|
|
||||||
|
|
||||||
namespace Git {
|
namespace Git {
|
||||||
namespace Internal {
|
namespace Internal {
|
||||||
|
|
||||||
@@ -55,13 +53,10 @@ enum Format {
|
|||||||
class GitSubmitHighlighter : public TextEditor::SyntaxHighlighter
|
class GitSubmitHighlighter : public TextEditor::SyntaxHighlighter
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
explicit GitSubmitHighlighter(QTextEdit *parent);
|
explicit GitSubmitHighlighter(QTextEdit *parent = 0);
|
||||||
explicit GitSubmitHighlighter(TextEditor::BaseTextDocument *parent);
|
|
||||||
void highlightBlock(const QString &text);
|
void highlightBlock(const QString &text);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void initialize();
|
|
||||||
|
|
||||||
enum State { None = -1, Header, Other };
|
enum State { None = -1, Header, Other };
|
||||||
QRegExp m_keywordPattern;
|
QRegExp m_keywordPattern;
|
||||||
QChar m_hashChar;
|
QChar m_hashChar;
|
||||||
@@ -72,7 +67,7 @@ private:
|
|||||||
class GitRebaseHighlighter : public TextEditor::SyntaxHighlighter
|
class GitRebaseHighlighter : public TextEditor::SyntaxHighlighter
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
explicit GitRebaseHighlighter(TextEditor::BaseTextDocument *parent);
|
explicit GitRebaseHighlighter(QTextDocument *parent = 0);
|
||||||
void highlightBlock(const QString &text);
|
void highlightBlock(const QString &text);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|||||||
@@ -374,7 +374,7 @@ GlslEditorFactory::GlslEditorFactory()
|
|||||||
setEditorWidgetCreator([]() { return new GlslEditorWidget; });
|
setEditorWidgetCreator([]() { return new GlslEditorWidget; });
|
||||||
setEditorCreator([]() { return new GlslEditor; });
|
setEditorCreator([]() { return new GlslEditor; });
|
||||||
setIndenterCreator([]() { return new GlslIndenter; });
|
setIndenterCreator([]() { return new GlslIndenter; });
|
||||||
setSyntaxHighlighterCreator([]() { return new Highlighter; });
|
setSyntaxHighlighterCreator([]() { return new GlslHighlighter; });
|
||||||
|
|
||||||
setEditorActionHandlers(Constants::C_GLSLEDITOR_ID,
|
setEditorActionHandlers(Constants::C_GLSLEDITOR_ID,
|
||||||
TextEditorActionHandler::Format
|
TextEditorActionHandler::Format
|
||||||
|
|||||||
@@ -212,7 +212,7 @@ bool GlslEditorPlugin::initialize(const QStringList & /*arguments*/, QString *er
|
|||||||
addAutoReleasedObject(wizard);
|
addAutoReleasedObject(wizard);
|
||||||
|
|
||||||
auto hf = new HighlighterFactory;
|
auto hf = new HighlighterFactory;
|
||||||
hf->setProductType<Highlighter>();
|
hf->setProductType<GlslHighlighter>();
|
||||||
hf->setId(Constants::C_GLSLEDITOR_ID);
|
hf->setId(Constants::C_GLSLEDITOR_ID);
|
||||||
hf->addMimeType(Constants::GLSL_MIMETYPE);
|
hf->addMimeType(Constants::GLSL_MIMETYPE);
|
||||||
hf->addMimeType(Constants::GLSL_MIMETYPE_VERT);
|
hf->addMimeType(Constants::GLSL_MIMETYPE_VERT);
|
||||||
|
|||||||
@@ -35,23 +35,12 @@
|
|||||||
|
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
|
|
||||||
using namespace GlslEditor;
|
|
||||||
using namespace GlslEditor::Internal;
|
|
||||||
using namespace TextEditor;
|
using namespace TextEditor;
|
||||||
|
|
||||||
Highlighter::Highlighter(QTextDocument *parent)
|
namespace GlslEditor {
|
||||||
: TextEditor::SyntaxHighlighter(parent)
|
namespace Internal {
|
||||||
{
|
|
||||||
init();
|
|
||||||
}
|
|
||||||
|
|
||||||
Highlighter::Highlighter(BaseTextDocument *parent)
|
GlslHighlighter::GlslHighlighter()
|
||||||
: TextEditor::SyntaxHighlighter(parent)
|
|
||||||
{
|
|
||||||
init();
|
|
||||||
}
|
|
||||||
|
|
||||||
void Highlighter::init()
|
|
||||||
{
|
{
|
||||||
static QVector<TextEditor::TextStyle> categories;
|
static QVector<TextEditor::TextStyle> categories;
|
||||||
if (categories.isEmpty()) {
|
if (categories.isEmpty()) {
|
||||||
@@ -71,12 +60,7 @@ void Highlighter::init()
|
|||||||
setTextFormatCategories(categories);
|
setTextFormatCategories(categories);
|
||||||
}
|
}
|
||||||
|
|
||||||
Highlighter::~Highlighter()
|
void GlslHighlighter::highlightBlock(const QString &text)
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
void Highlighter::highlightBlock(const QString &text)
|
|
||||||
{
|
{
|
||||||
const int previousState = previousBlockState();
|
const int previousState = previousBlockState();
|
||||||
int state = 0, initialBraceDepth = 0;
|
int state = 0, initialBraceDepth = 0;
|
||||||
@@ -265,7 +249,7 @@ void Highlighter::highlightBlock(const QString &text)
|
|||||||
setCurrentBlockState((braceDepth << 8) | lex.state());
|
setCurrentBlockState((braceDepth << 8) | lex.state());
|
||||||
}
|
}
|
||||||
|
|
||||||
void Highlighter::highlightLine(const QString &text, int position, int length,
|
void GlslHighlighter::highlightLine(const QString &text, int position, int length,
|
||||||
const QTextCharFormat &format)
|
const QTextCharFormat &format)
|
||||||
{
|
{
|
||||||
const QTextCharFormat visualSpaceFormat = formatForCategory(GLSLVisualWhitespace);
|
const QTextCharFormat visualSpaceFormat = formatForCategory(GLSLVisualWhitespace);
|
||||||
@@ -288,7 +272,7 @@ void Highlighter::highlightLine(const QString &text, int position, int length,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Highlighter::isPPKeyword(const QStringRef &text) const
|
bool GlslHighlighter::isPPKeyword(const QStringRef &text) const
|
||||||
{
|
{
|
||||||
switch (text.length())
|
switch (text.length())
|
||||||
{
|
{
|
||||||
@@ -427,3 +411,6 @@ void Highlighter::highlightBlock(const QString &text)
|
|||||||
setCurrentBlockState((braceDepth << 8) | lex.state());
|
setCurrentBlockState((braceDepth << 8) | lex.state());
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
} // namespace Internal
|
||||||
|
} // namespace GlslEditor
|
||||||
|
|||||||
@@ -26,6 +26,7 @@
|
|||||||
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
||||||
**
|
**
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
#ifndef GLSLHIGHLIGHTER_H
|
#ifndef GLSLHIGHLIGHTER_H
|
||||||
#define GLSLHIGHLIGHTER_H
|
#define GLSLHIGHLIGHTER_H
|
||||||
|
|
||||||
@@ -34,9 +35,7 @@
|
|||||||
namespace GlslEditor {
|
namespace GlslEditor {
|
||||||
namespace Internal {
|
namespace Internal {
|
||||||
|
|
||||||
class GlslEditorWidget;
|
class GlslHighlighter : public TextEditor::SyntaxHighlighter
|
||||||
|
|
||||||
class Highlighter : public TextEditor::SyntaxHighlighter
|
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
@@ -57,17 +56,12 @@ public:
|
|||||||
NumGLSLFormats
|
NumGLSLFormats
|
||||||
};
|
};
|
||||||
|
|
||||||
explicit Highlighter(QTextDocument *parent = 0);
|
GlslHighlighter();
|
||||||
explicit Highlighter(TextEditor::BaseTextDocument *parent);
|
|
||||||
virtual ~Highlighter();
|
|
||||||
|
|
||||||
protected:
|
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
|
||||||
|
|||||||
@@ -44,8 +44,7 @@
|
|||||||
#include <texteditor/texteditorconstants.h>
|
#include <texteditor/texteditorconstants.h>
|
||||||
|
|
||||||
namespace PythonEditor {
|
namespace PythonEditor {
|
||||||
|
namespace Internal {
|
||||||
using namespace PythonEditor::Internal;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @class PyEditor::Highlighter
|
* @class PyEditor::Highlighter
|
||||||
@@ -65,20 +64,7 @@ using namespace PythonEditor::Internal;
|
|||||||
* @endcode
|
* @endcode
|
||||||
*/
|
*/
|
||||||
|
|
||||||
PythonHighlighter::PythonHighlighter(QTextDocument *parent) :
|
PythonHighlighter::PythonHighlighter()
|
||||||
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;
|
static QVector<TextEditor::TextStyle> categories;
|
||||||
if (categories.isEmpty()) {
|
if (categories.isEmpty()) {
|
||||||
@@ -98,11 +84,6 @@ void PythonHighlighter::init()
|
|||||||
setTextFormatCategories(categories);
|
setTextFormatCategories(categories);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Instance destroyed when one of documents closed from editor
|
|
||||||
PythonHighlighter::~PythonHighlighter()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Highlighter::highlightBlock highlights single line of Python code
|
* @brief Highlighter::highlightBlock highlights single line of Python code
|
||||||
* @param text is single line without EOLN symbol. Access to all block data
|
* @param text is single line without EOLN symbol. Access to all block data
|
||||||
@@ -123,11 +104,9 @@ void PythonHighlighter::highlightBlock(const QString &text)
|
|||||||
/**
|
/**
|
||||||
* @return True if this keyword is acceptable at start of import line
|
* @return True if this keyword is acceptable at start of import line
|
||||||
*/
|
*/
|
||||||
static inline
|
static bool isImportKeyword(const QString &keyword)
|
||||||
bool isImportKeyword(const QString &keyword)
|
|
||||||
{
|
{
|
||||||
return (keyword == QLatin1String("import")
|
return keyword == QLatin1String("import") || keyword == QLatin1String("from");
|
||||||
|| keyword == QLatin1String("from"));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -175,4 +154,5 @@ void PythonHighlighter::highlightImport(Scanner &scanner)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
} // namespace Internal
|
||||||
} // namespace PythonEditor
|
} // namespace PythonEditor
|
||||||
|
|||||||
@@ -33,26 +33,24 @@
|
|||||||
#include <texteditor/syntaxhighlighter.h>
|
#include <texteditor/syntaxhighlighter.h>
|
||||||
|
|
||||||
namespace PythonEditor {
|
namespace PythonEditor {
|
||||||
|
namespace Internal {
|
||||||
|
|
||||||
namespace Internal { class Scanner; }
|
class Scanner;
|
||||||
|
|
||||||
class PythonHighlighter : public TextEditor::SyntaxHighlighter
|
class PythonHighlighter : public TextEditor::SyntaxHighlighter
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
|
||||||
public:
|
public:
|
||||||
explicit PythonHighlighter(QTextDocument *parent = 0);
|
PythonHighlighter();
|
||||||
explicit PythonHighlighter(TextEditor::BaseTextDocument *parent);
|
|
||||||
virtual ~PythonHighlighter();
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual void highlightBlock(const QString &text);
|
void highlightBlock(const QString &text);
|
||||||
|
|
||||||
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 Internal
|
||||||
} // namespace PythonEditor
|
} // namespace PythonEditor
|
||||||
|
|
||||||
#endif // PYTHONHIGHLIGHTER_H
|
#endif // PYTHONHIGHLIGHTER_H
|
||||||
|
|||||||
@@ -538,7 +538,7 @@ QmlJSEditorDocument::QmlJSEditorDocument()
|
|||||||
setId(Constants::C_QMLJSEDITOR_ID);
|
setId(Constants::C_QMLJSEDITOR_ID);
|
||||||
connect(this, SIGNAL(tabSettingsChanged()),
|
connect(this, SIGNAL(tabSettingsChanged()),
|
||||||
d, SLOT(invalidateFormatterCache()));
|
d, SLOT(invalidateFormatterCache()));
|
||||||
setSyntaxHighlighter(new Highlighter(document()));
|
setSyntaxHighlighter(new QmlJSHighlighter(document()));
|
||||||
setIndenter(new Internal::Indenter);
|
setIndenter(new Internal::Indenter);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -113,7 +113,7 @@ bool QmlJSEditorPlugin::initialize(const QStringList & /*arguments*/, QString *e
|
|||||||
addAutoReleasedObject(new QmlJSSnippetProvider);
|
addAutoReleasedObject(new QmlJSSnippetProvider);
|
||||||
|
|
||||||
auto hf = new TextEditor::HighlighterFactory;
|
auto hf = new TextEditor::HighlighterFactory;
|
||||||
hf->setProductType<Highlighter>();
|
hf->setProductType<QmlJSHighlighter>();
|
||||||
hf->setId(Constants::C_QMLJSEDITOR_ID);
|
hf->setId(Constants::C_QMLJSEDITOR_ID);
|
||||||
hf->addMimeType(QmlJSTools::Constants::QML_MIMETYPE);
|
hf->addMimeType(QmlJSTools::Constants::QML_MIMETYPE);
|
||||||
hf->addMimeType(QmlJSTools::Constants::QMLPROJECT_MIMETYPE);
|
hf->addMimeType(QmlJSTools::Constants::QMLPROJECT_MIMETYPE);
|
||||||
|
|||||||
@@ -33,11 +33,13 @@
|
|||||||
|
|
||||||
#include <utils/qtcassert.h>
|
#include <utils/qtcassert.h>
|
||||||
|
|
||||||
using namespace QmlJSEditor;
|
|
||||||
using namespace QmlJS;
|
using namespace QmlJS;
|
||||||
|
using namespace TextEditor;
|
||||||
|
|
||||||
Highlighter::Highlighter(QTextDocument *parent)
|
namespace QmlJSEditor {
|
||||||
: TextEditor::SyntaxHighlighter(parent),
|
|
||||||
|
QmlJSHighlighter::QmlJSHighlighter(QTextDocument *parent)
|
||||||
|
: SyntaxHighlighter(parent),
|
||||||
m_qmlEnabled(true),
|
m_qmlEnabled(true),
|
||||||
m_braceDepth(0),
|
m_braceDepth(0),
|
||||||
m_foldingIndent(0),
|
m_foldingIndent(0),
|
||||||
@@ -57,21 +59,21 @@ Highlighter::Highlighter(QTextDocument *parent)
|
|||||||
setTextFormatCategories(categories);
|
setTextFormatCategories(categories);
|
||||||
}
|
}
|
||||||
|
|
||||||
Highlighter::~Highlighter()
|
QmlJSHighlighter::~QmlJSHighlighter()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Highlighter::isQmlEnabled() const
|
bool QmlJSHighlighter::isQmlEnabled() const
|
||||||
{
|
{
|
||||||
return m_qmlEnabled;
|
return m_qmlEnabled;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Highlighter::setQmlEnabled(bool qmlEnabled)
|
void QmlJSHighlighter::setQmlEnabled(bool qmlEnabled)
|
||||||
{
|
{
|
||||||
m_qmlEnabled = qmlEnabled;
|
m_qmlEnabled = qmlEnabled;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Highlighter::highlightBlock(const QString &text)
|
void QmlJSHighlighter::highlightBlock(const QString &text)
|
||||||
{
|
{
|
||||||
const QList<Token> tokens = m_scanner(text, onBlockStart());
|
const QList<Token> tokens = m_scanner(text, onBlockStart());
|
||||||
|
|
||||||
@@ -200,7 +202,7 @@ void Highlighter::highlightBlock(const QString &text)
|
|||||||
onBlockEnd(m_scanner.state());
|
onBlockEnd(m_scanner.state());
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Highlighter::maybeQmlKeyword(const QStringRef &text) const
|
bool QmlJSHighlighter::maybeQmlKeyword(const QStringRef &text) const
|
||||||
{
|
{
|
||||||
if (text.isEmpty())
|
if (text.isEmpty())
|
||||||
return false;
|
return false;
|
||||||
@@ -224,7 +226,7 @@ bool Highlighter::maybeQmlKeyword(const QStringRef &text) const
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Highlighter::maybeQmlBuiltinType(const QStringRef &text) const
|
bool QmlJSHighlighter::maybeQmlBuiltinType(const QStringRef &text) const
|
||||||
{
|
{
|
||||||
if (text.isEmpty())
|
if (text.isEmpty())
|
||||||
return false;
|
return false;
|
||||||
@@ -281,13 +283,13 @@ bool Highlighter::maybeQmlBuiltinType(const QStringRef &text) const
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
int Highlighter::onBlockStart()
|
int QmlJSHighlighter::onBlockStart()
|
||||||
{
|
{
|
||||||
m_currentBlockParentheses.clear();
|
m_currentBlockParentheses.clear();
|
||||||
m_braceDepth = 0;
|
m_braceDepth = 0;
|
||||||
m_foldingIndent = 0;
|
m_foldingIndent = 0;
|
||||||
m_inMultilineComment = false;
|
m_inMultilineComment = false;
|
||||||
if (TextEditor::TextBlockUserData *userData = TextEditor::BaseTextDocumentLayout::testUserData(currentBlock())) {
|
if (TextBlockUserData *userData = BaseTextDocumentLayout::testUserData(currentBlock())) {
|
||||||
userData->setFoldingIndent(0);
|
userData->setFoldingIndent(0);
|
||||||
userData->setFoldingStartIncluded(false);
|
userData->setFoldingStartIncluded(false);
|
||||||
userData->setFoldingEndIncluded(false);
|
userData->setFoldingEndIncluded(false);
|
||||||
@@ -305,34 +307,35 @@ int Highlighter::onBlockStart()
|
|||||||
return state;
|
return state;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Highlighter::onBlockEnd(int state)
|
void QmlJSHighlighter::onBlockEnd(int state)
|
||||||
{
|
{
|
||||||
setCurrentBlockState((m_braceDepth << 8) | state);
|
setCurrentBlockState((m_braceDepth << 8) | state);
|
||||||
TextEditor::BaseTextDocumentLayout::setParentheses(currentBlock(), m_currentBlockParentheses);
|
BaseTextDocumentLayout::setParentheses(currentBlock(), m_currentBlockParentheses);
|
||||||
TextEditor::BaseTextDocumentLayout::setFoldingIndent(currentBlock(), m_foldingIndent);
|
BaseTextDocumentLayout::setFoldingIndent(currentBlock(), m_foldingIndent);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Highlighter::onOpeningParenthesis(QChar parenthesis, int pos, bool atStart)
|
void QmlJSHighlighter::onOpeningParenthesis(QChar parenthesis, int pos, bool atStart)
|
||||||
{
|
{
|
||||||
if (parenthesis == QLatin1Char('{') || parenthesis == QLatin1Char('[') || parenthesis == QLatin1Char('+')) {
|
if (parenthesis == QLatin1Char('{') || parenthesis == QLatin1Char('[') || parenthesis == QLatin1Char('+')) {
|
||||||
++m_braceDepth;
|
++m_braceDepth;
|
||||||
// if a folding block opens at the beginning of a line, treat the entire line
|
// if a folding block opens at the beginning of a line, treat the entire line
|
||||||
// as if it were inside the folding block
|
// as if it were inside the folding block
|
||||||
if (atStart)
|
if (atStart)
|
||||||
TextEditor::BaseTextDocumentLayout::userData(currentBlock())->setFoldingStartIncluded(true);
|
BaseTextDocumentLayout::userData(currentBlock())->setFoldingStartIncluded(true);
|
||||||
}
|
}
|
||||||
m_currentBlockParentheses.push_back(Parenthesis(Parenthesis::Opened, parenthesis, pos));
|
m_currentBlockParentheses.push_back(Parenthesis(Parenthesis::Opened, parenthesis, pos));
|
||||||
}
|
}
|
||||||
|
|
||||||
void Highlighter::onClosingParenthesis(QChar parenthesis, int pos, bool atEnd)
|
void QmlJSHighlighter::onClosingParenthesis(QChar parenthesis, int pos, bool atEnd)
|
||||||
{
|
{
|
||||||
if (parenthesis == QLatin1Char('}') || parenthesis == QLatin1Char(']') || parenthesis == QLatin1Char('-')) {
|
if (parenthesis == QLatin1Char('}') || parenthesis == QLatin1Char(']') || parenthesis == QLatin1Char('-')) {
|
||||||
--m_braceDepth;
|
--m_braceDepth;
|
||||||
if (atEnd)
|
if (atEnd)
|
||||||
TextEditor::BaseTextDocumentLayout::userData(currentBlock())->setFoldingEndIncluded(true);
|
BaseTextDocumentLayout::userData(currentBlock())->setFoldingEndIncluded(true);
|
||||||
else
|
else
|
||||||
m_foldingIndent = qMin(m_braceDepth, m_foldingIndent); // folding indent is the minimum brace depth of a block
|
m_foldingIndent = qMin(m_braceDepth, m_foldingIndent); // folding indent is the minimum brace depth of a block
|
||||||
}
|
}
|
||||||
m_currentBlockParentheses.push_back(Parenthesis(Parenthesis::Closed, parenthesis, pos));
|
m_currentBlockParentheses.push_back(Parenthesis(Parenthesis::Closed, parenthesis, pos));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
} // namespace QmlJSEditor
|
||||||
|
|||||||
@@ -39,13 +39,13 @@
|
|||||||
|
|
||||||
namespace QmlJSEditor {
|
namespace QmlJSEditor {
|
||||||
|
|
||||||
class QMLJSEDITOR_EXPORT Highlighter : public TextEditor::SyntaxHighlighter
|
class QMLJSEDITOR_EXPORT QmlJSHighlighter : public TextEditor::SyntaxHighlighter
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Highlighter(QTextDocument *parent = 0);
|
QmlJSHighlighter(QTextDocument *parent = 0);
|
||||||
virtual ~Highlighter();
|
virtual ~QmlJSHighlighter();
|
||||||
|
|
||||||
enum {
|
enum {
|
||||||
NumberFormat,
|
NumberFormat,
|
||||||
@@ -76,16 +76,13 @@ protected:
|
|||||||
bool maybeQmlBuiltinType(const QStringRef &text) const;
|
bool maybeQmlBuiltinType(const QStringRef &text) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
typedef TextEditor::Parenthesis Parenthesis;
|
|
||||||
typedef TextEditor::Parentheses Parentheses;
|
|
||||||
|
|
||||||
bool m_qmlEnabled;
|
bool m_qmlEnabled;
|
||||||
int m_braceDepth;
|
int m_braceDepth;
|
||||||
int m_foldingIndent;
|
int m_foldingIndent;
|
||||||
bool m_inMultilineComment;
|
bool m_inMultilineComment;
|
||||||
|
|
||||||
QmlJS::Scanner m_scanner;
|
QmlJS::Scanner m_scanner;
|
||||||
Parentheses m_currentBlockParentheses;
|
TextEditor::Parentheses m_currentBlockParentheses;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace QmlJSEditor
|
} // namespace QmlJSEditor
|
||||||
|
|||||||
@@ -64,7 +64,7 @@ QString QmlJSSnippetProvider::displayName() const
|
|||||||
|
|
||||||
void QmlJSSnippetProvider::decorateEditor(TextEditor::SnippetEditorWidget *editor) const
|
void QmlJSSnippetProvider::decorateEditor(TextEditor::SnippetEditorWidget *editor) const
|
||||||
{
|
{
|
||||||
editor->textDocument()->setSyntaxHighlighter(new Highlighter);
|
editor->textDocument()->setSyntaxHighlighter(new QmlJSHighlighter);
|
||||||
editor->textDocument()->setIndenter(new Indenter);
|
editor->textDocument()->setIndenter(new Indenter);
|
||||||
editor->setAutoCompleter(new AutoCompleter);
|
editor->setAutoCompleter(new AutoCompleter);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -282,13 +282,6 @@ SyntaxHighlighter::SyntaxHighlighter(QTextDocument *parent)
|
|||||||
setDocument(parent);
|
setDocument(parent);
|
||||||
}
|
}
|
||||||
|
|
||||||
SyntaxHighlighter::SyntaxHighlighter(BaseTextDocument *parent)
|
|
||||||
: d_ptr(new SyntaxHighlighterPrivate)
|
|
||||||
{
|
|
||||||
d_ptr->q_ptr = this;
|
|
||||||
parent->setSyntaxHighlighter(this); // Extra logic (including setting the parent).
|
|
||||||
}
|
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
Constructs a SyntaxHighlighter and installs it on \a parent's
|
Constructs a SyntaxHighlighter and installs it on \a parent's
|
||||||
QTextDocument. The specified QTextEdit also becomes the owner of
|
QTextDocument. The specified QTextEdit also becomes the owner of
|
||||||
|
|||||||
@@ -47,7 +47,6 @@ QT_END_NAMESPACE
|
|||||||
|
|
||||||
namespace TextEditor {
|
namespace TextEditor {
|
||||||
|
|
||||||
class BaseTextDocument;
|
|
||||||
class FontSettings;
|
class FontSettings;
|
||||||
class SyntaxHighlighterPrivate;
|
class SyntaxHighlighterPrivate;
|
||||||
|
|
||||||
@@ -56,9 +55,8 @@ class TEXTEDITOR_EXPORT SyntaxHighlighter : public QObject
|
|||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
Q_DECLARE_PRIVATE(SyntaxHighlighter)
|
Q_DECLARE_PRIVATE(SyntaxHighlighter)
|
||||||
public:
|
public:
|
||||||
SyntaxHighlighter(QObject *parent);
|
SyntaxHighlighter(QObject *parent = 0);
|
||||||
SyntaxHighlighter(QTextDocument *parent);
|
SyntaxHighlighter(QTextDocument *parent);
|
||||||
SyntaxHighlighter(BaseTextDocument *parent);
|
|
||||||
SyntaxHighlighter(QTextEdit *parent);
|
SyntaxHighlighter(QTextEdit *parent);
|
||||||
virtual ~SyntaxHighlighter();
|
virtual ~SyntaxHighlighter();
|
||||||
|
|
||||||
|
|||||||
@@ -34,13 +34,6 @@
|
|||||||
|
|
||||||
#include <QList>
|
#include <QList>
|
||||||
|
|
||||||
namespace TextEditor {
|
|
||||||
namespace Internal {
|
|
||||||
class Context;
|
|
||||||
class HighlightDefinition;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
struct HighlightSequence
|
struct HighlightSequence
|
||||||
{
|
{
|
||||||
HighlightSequence() {}
|
HighlightSequence() {}
|
||||||
|
|||||||
Reference in New Issue
Block a user