diff options
author | jkobus <jaroslaw.kobus@digia.com> | 2013-08-13 12:57:31 +0200 |
---|---|---|
committer | Jarek Kobus <jaroslaw.kobus@digia.com> | 2013-08-26 13:39:40 +0200 |
commit | e8801167aa7a0047c9c9be0942ed0b368e5b5aa4 (patch) | |
tree | eb1dcf7998b0457518681126ddf9b49f198dd2d4 /src/plugins/pythoneditor/tools/pythonhighlighter.cpp | |
parent | 760aa0f8bce34e094abecdd99c77c359fb96bb67 (diff) | |
download | qt-creator-e8801167aa7a0047c9c9be0942ed0b368e5b5aa4.tar.gz |
Add common interface for text formats inside syntax highlighter
Change-Id: I87f64446161a57aea0896f68e4eafacef791969b
Reviewed-by: Orgad Shaneh <orgads@gmail.com>
Reviewed-by: Erik Verbruggen <erik.verbruggen@digia.com>
Diffstat (limited to 'src/plugins/pythoneditor/tools/pythonhighlighter.cpp')
-rw-r--r-- | src/plugins/pythoneditor/tools/pythonhighlighter.cpp | 56 |
1 files changed, 19 insertions, 37 deletions
diff --git a/src/plugins/pythoneditor/tools/pythonhighlighter.cpp b/src/plugins/pythoneditor/tools/pythonhighlighter.cpp index 6e59d4a013..ea809c4e6f 100644 --- a/src/plugins/pythoneditor/tools/pythonhighlighter.cpp +++ b/src/plugins/pythoneditor/tools/pythonhighlighter.cpp @@ -40,9 +40,7 @@ #include "pythonhighlighter.h" #include "lexical/pythonscanner.h" -#include <texteditor/basetextdocumentlayout.h> #include <texteditor/basetextdocument.h> -#include <texteditor/fontsettings.h> #include <texteditor/texteditorconstants.h> namespace PythonEditor { @@ -67,30 +65,26 @@ using namespace PythonEditor::Internal; * @endcode */ -/// @return List that maps enum Format values to TextEditor plugin formats -QVector<TextEditor::TextStyle> initFormatCategories() -{ - QVector<TextEditor::TextStyle> categories(Format_FormatsAmount); - categories[Format_Number] = TextEditor::C_NUMBER; - categories[Format_String] = TextEditor::C_STRING; - categories[Format_Keyword] = TextEditor::C_KEYWORD; - categories[Format_Type] = TextEditor::C_TYPE; - categories[Format_ClassField] = TextEditor::C_FIELD; - categories[Format_MagicAttr] = TextEditor::C_JS_SCOPE_VAR; - categories[Format_Operator] = TextEditor::C_OPERATOR; - categories[Format_Comment] = TextEditor::C_COMMENT; - categories[Format_Doxygen] = TextEditor::C_DOXYGEN_COMMENT; - categories[Format_Whitespace] = TextEditor::C_VISUAL_WHITESPACE; - categories[Format_Identifier] = TextEditor::C_TEXT; - categories[Format_ImportedModule] = TextEditor::C_STRING; - - return categories; -} - /// New instance created when opening any document in editor PythonHighlighter::PythonHighlighter(TextEditor::BaseTextDocument *parent) : TextEditor::SyntaxHighlighter(parent) { + static QVector<TextEditor::TextStyle> categories; + if (categories.isEmpty()) { + categories << TextEditor::C_NUMBER + << TextEditor::C_STRING + << TextEditor::C_KEYWORD + << TextEditor::C_TYPE + << TextEditor::C_FIELD + << TextEditor::C_JS_SCOPE_VAR + << TextEditor::C_OPERATOR + << TextEditor::C_COMMENT + << TextEditor::C_DOXYGEN_COMMENT + << TextEditor::C_TEXT + << TextEditor::C_VISUAL_WHITESPACE + << TextEditor::C_STRING; + } + setTextFormatCategories(categories); } /// Instance destroyed when one of documents closed from editor @@ -99,18 +93,6 @@ PythonHighlighter::~PythonHighlighter() } /** - QtCreator has own fonts&color settings. Highlighter wants get access to - this settings before highlightBlock() called first time. - Settings provided by PyEditor::EditorWidget class. - */ -void PythonHighlighter::setFontSettings(const TextEditor::FontSettings &fs) -{ - QVector<TextEditor::TextStyle> categories = initFormatCategories(); - m_formats = fs.toTextCharFormats(categories); - rehighlight(); -} - -/** * @brief Highlighter::highlightBlock highlights single line of Python code * @param text is single line without EOLN symbol. Access to all block data * can be obtained through inherited currentBlock() method. @@ -155,13 +137,13 @@ int PythonHighlighter::highlightLine(const QString &text, int initialState) if (format == Format_Keyword) { QString value = scanner.value(tk); if (isImportKeyword(value) && hasOnlyWhitespace) { - setFormat(tk.begin(), tk.length(), m_formats[format]); + setFormat(tk.begin(), tk.length(), formatForCategory(format)); highlightImport(scanner); break; } } - setFormat(tk.begin(), tk.length(), m_formats[format]); + setFormat(tk.begin(), tk.length(), formatForCategory(format)); if (format != Format_Whitespace) hasOnlyWhitespace = false; } @@ -178,7 +160,7 @@ void PythonHighlighter::highlightImport(Scanner &scanner) Format format = tk.format(); if (tk.format() == Format_Identifier) format = Format_ImportedModule; - setFormat(tk.begin(), tk.length(), m_formats[format]); + setFormat(tk.begin(), tk.length(), formatForCategory(format)); } } |