forked from qt-creator/qt-creator
Python: Move highlighter and indenter class definitions to .cpp
Change-Id: Ib71d520977034ca66bd84c9188ffed5fe74e1ba0 Reviewed-by: <github-actions-qt-creator@cristianadam.eu> Reviewed-by: David Schulz <david.schulz@qt.io>
This commit is contained in:
@@ -293,8 +293,8 @@ PythonEditorFactory::PythonEditorFactory()
|
||||
|
||||
setDocumentCreator([]() { return new PythonDocument; });
|
||||
setEditorWidgetCreator([]() { return new PythonEditorWidget; });
|
||||
setIndenterCreator([](QTextDocument *doc) { return new PythonIndenter(doc); });
|
||||
setSyntaxHighlighterCreator([] { return new PythonHighlighter; });
|
||||
setIndenterCreator(&createPythonIndenter);
|
||||
setSyntaxHighlighterCreator(&createPythonHighlighter);
|
||||
setCommentDefinition(CommentDefinition::HashStyle);
|
||||
setParenthesesMatchingEnabled(true);
|
||||
setCodeFoldingSupported(true);
|
||||
|
||||
@@ -17,10 +17,10 @@
|
||||
#include <texteditor/textdocument.h>
|
||||
#include <texteditor/textdocumentlayout.h>
|
||||
#include <texteditor/texteditorconstants.h>
|
||||
|
||||
#include <utils/qtcassert.h>
|
||||
|
||||
namespace Python {
|
||||
namespace Internal {
|
||||
namespace Python::Internal {
|
||||
|
||||
/**
|
||||
* @class PythonEditor::Internal::PythonHighlighter
|
||||
@@ -67,11 +67,23 @@ static TextEditor::TextStyle styleForFormat(int format)
|
||||
return C_TEXT;
|
||||
}
|
||||
|
||||
PythonHighlighter::PythonHighlighter()
|
||||
class PythonHighlighter : public TextEditor::SyntaxHighlighter
|
||||
{
|
||||
public:
|
||||
PythonHighlighter()
|
||||
{
|
||||
setTextFormatCategories(Format_FormatsAmount, styleForFormat);
|
||||
}
|
||||
|
||||
private:
|
||||
void highlightBlock(const QString &text) override;
|
||||
int highlightLine(const QString &text, int initialState);
|
||||
void highlightImport(Internal::Scanner &scanner);
|
||||
|
||||
int m_lastIndent = 0;
|
||||
bool withinLicenseHeader = false;
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief PythonHighlighter::highlightBlock highlights single line of Python code
|
||||
* @param text is single line without EOLN symbol. Access to all block data
|
||||
@@ -187,5 +199,9 @@ void PythonHighlighter::highlightImport(Scanner &scanner)
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace Internal
|
||||
} // namespace Python
|
||||
TextEditor::SyntaxHighlighter *createPythonHighlighter()
|
||||
{
|
||||
return new PythonHighlighter;
|
||||
}
|
||||
|
||||
} // namespace Python::Internal
|
||||
|
||||
@@ -5,24 +5,8 @@
|
||||
|
||||
#include <texteditor/syntaxhighlighter.h>
|
||||
|
||||
namespace Python {
|
||||
namespace Internal {
|
||||
namespace Python::Internal {
|
||||
|
||||
class Scanner;
|
||||
TextEditor::SyntaxHighlighter *createPythonHighlighter();
|
||||
|
||||
class PythonHighlighter : public TextEditor::SyntaxHighlighter
|
||||
{
|
||||
public:
|
||||
PythonHighlighter();
|
||||
|
||||
private:
|
||||
void highlightBlock(const QString &text) override;
|
||||
int highlightLine(const QString &text, int initialState);
|
||||
void highlightImport(Internal::Scanner &scanner);
|
||||
|
||||
int m_lastIndent = 0;
|
||||
bool withinLicenseHeader = false;
|
||||
};
|
||||
|
||||
} // namespace Internal
|
||||
} // namespace Python
|
||||
} // namespace Python::Internal
|
||||
|
||||
@@ -28,10 +28,24 @@ static QTextBlock previousNonEmptyBlock(const QTextBlock &block)
|
||||
return result;
|
||||
}
|
||||
|
||||
PythonIndenter::PythonIndenter(QTextDocument *doc)
|
||||
class PythonIndenter : public TextEditor::TextIndenter
|
||||
{
|
||||
public:
|
||||
explicit PythonIndenter(QTextDocument *doc)
|
||||
: TextEditor::TextIndenter(doc)
|
||||
{}
|
||||
|
||||
private:
|
||||
bool isElectricCharacter(const QChar &ch) const override;
|
||||
int indentFor(const QTextBlock &block,
|
||||
const TextEditor::TabSettings &tabSettings,
|
||||
int cursorPositionInEditor = -1) override;
|
||||
|
||||
bool isElectricLine(const QString &line) const;
|
||||
int getIndentDiff(const QString &previousLine,
|
||||
const TextEditor::TabSettings &tabSettings) const;
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Does given character change indentation level?
|
||||
* @param ch Any value
|
||||
@@ -102,4 +116,9 @@ int PythonIndenter::getIndentDiff(const QString &previousLine,
|
||||
return 0;
|
||||
}
|
||||
|
||||
TextEditor::TextIndenter *createPythonIndenter(QTextDocument *doc)
|
||||
{
|
||||
return new PythonIndenter(doc);
|
||||
}
|
||||
|
||||
} // namespace Python
|
||||
|
||||
@@ -7,19 +7,6 @@
|
||||
|
||||
namespace Python {
|
||||
|
||||
class PythonIndenter : public TextEditor::TextIndenter
|
||||
{
|
||||
public:
|
||||
explicit PythonIndenter(QTextDocument *doc);
|
||||
private:
|
||||
bool isElectricCharacter(const QChar &ch) const override;
|
||||
int indentFor(const QTextBlock &block,
|
||||
const TextEditor::TabSettings &tabSettings,
|
||||
int cursorPositionInEditor = -1) override;
|
||||
|
||||
bool isElectricLine(const QString &line) const;
|
||||
int getIndentDiff(const QString &previousLine,
|
||||
const TextEditor::TabSettings &tabSettings) const;
|
||||
};
|
||||
TextEditor::TextIndenter *createPythonIndenter(QTextDocument *doc);
|
||||
|
||||
} // namespace Python
|
||||
|
||||
Reference in New Issue
Block a user