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; });
|
setDocumentCreator([]() { return new PythonDocument; });
|
||||||
setEditorWidgetCreator([]() { return new PythonEditorWidget; });
|
setEditorWidgetCreator([]() { return new PythonEditorWidget; });
|
||||||
setIndenterCreator([](QTextDocument *doc) { return new PythonIndenter(doc); });
|
setIndenterCreator(&createPythonIndenter);
|
||||||
setSyntaxHighlighterCreator([] { return new PythonHighlighter; });
|
setSyntaxHighlighterCreator(&createPythonHighlighter);
|
||||||
setCommentDefinition(CommentDefinition::HashStyle);
|
setCommentDefinition(CommentDefinition::HashStyle);
|
||||||
setParenthesesMatchingEnabled(true);
|
setParenthesesMatchingEnabled(true);
|
||||||
setCodeFoldingSupported(true);
|
setCodeFoldingSupported(true);
|
||||||
|
|||||||
@@ -17,10 +17,10 @@
|
|||||||
#include <texteditor/textdocument.h>
|
#include <texteditor/textdocument.h>
|
||||||
#include <texteditor/textdocumentlayout.h>
|
#include <texteditor/textdocumentlayout.h>
|
||||||
#include <texteditor/texteditorconstants.h>
|
#include <texteditor/texteditorconstants.h>
|
||||||
|
|
||||||
#include <utils/qtcassert.h>
|
#include <utils/qtcassert.h>
|
||||||
|
|
||||||
namespace Python {
|
namespace Python::Internal {
|
||||||
namespace Internal {
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @class PythonEditor::Internal::PythonHighlighter
|
* @class PythonEditor::Internal::PythonHighlighter
|
||||||
@@ -67,10 +67,22 @@ static TextEditor::TextStyle styleForFormat(int format)
|
|||||||
return C_TEXT;
|
return C_TEXT;
|
||||||
}
|
}
|
||||||
|
|
||||||
PythonHighlighter::PythonHighlighter()
|
class PythonHighlighter : public TextEditor::SyntaxHighlighter
|
||||||
{
|
{
|
||||||
setTextFormatCategories(Format_FormatsAmount, styleForFormat);
|
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
|
* @brief PythonHighlighter::highlightBlock highlights single line of Python code
|
||||||
@@ -187,5 +199,9 @@ void PythonHighlighter::highlightImport(Scanner &scanner)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace Internal
|
TextEditor::SyntaxHighlighter *createPythonHighlighter()
|
||||||
} // namespace Python
|
{
|
||||||
|
return new PythonHighlighter;
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace Python::Internal
|
||||||
|
|||||||
@@ -5,24 +5,8 @@
|
|||||||
|
|
||||||
#include <texteditor/syntaxhighlighter.h>
|
#include <texteditor/syntaxhighlighter.h>
|
||||||
|
|
||||||
namespace Python {
|
namespace Python::Internal {
|
||||||
namespace Internal {
|
|
||||||
|
|
||||||
class Scanner;
|
TextEditor::SyntaxHighlighter *createPythonHighlighter();
|
||||||
|
|
||||||
class PythonHighlighter : public TextEditor::SyntaxHighlighter
|
} // namespace Python::Internal
|
||||||
{
|
|
||||||
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
|
|
||||||
|
|||||||
@@ -28,9 +28,23 @@ static QTextBlock previousNonEmptyBlock(const QTextBlock &block)
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
PythonIndenter::PythonIndenter(QTextDocument *doc)
|
class PythonIndenter : public TextEditor::TextIndenter
|
||||||
: TextEditor::TextIndenter(doc)
|
{
|
||||||
{}
|
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?
|
* @brief Does given character change indentation level?
|
||||||
@@ -102,4 +116,9 @@ int PythonIndenter::getIndentDiff(const QString &previousLine,
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TextEditor::TextIndenter *createPythonIndenter(QTextDocument *doc)
|
||||||
|
{
|
||||||
|
return new PythonIndenter(doc);
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace Python
|
} // namespace Python
|
||||||
|
|||||||
@@ -7,19 +7,6 @@
|
|||||||
|
|
||||||
namespace Python {
|
namespace Python {
|
||||||
|
|
||||||
class PythonIndenter : public TextEditor::TextIndenter
|
TextEditor::TextIndenter *createPythonIndenter(QTextDocument *doc);
|
||||||
{
|
|
||||||
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;
|
|
||||||
};
|
|
||||||
|
|
||||||
} // namespace Python
|
} // namespace Python
|
||||||
|
|||||||
Reference in New Issue
Block a user