Changeset View
Changeset View
Standalone View
Standalone View
src/backends/python/pythonhighlighter.cpp
Show All 14 Lines | 1 | /* | |||
---|---|---|---|---|---|
15 | Boston, MA 02110-1301, USA. | 15 | Boston, MA 02110-1301, USA. | ||
16 | 16 | | |||
17 | --- | 17 | --- | ||
18 | Copyright (C) 2013 Filipe Saraiva <filipe@kde.org> | 18 | Copyright (C) 2013 Filipe Saraiva <filipe@kde.org> | ||
19 | */ | 19 | */ | ||
20 | 20 | | |||
21 | #include "pythonhighlighter.h" | 21 | #include "pythonhighlighter.h" | ||
22 | #include "pythonkeywords.h" | 22 | #include "pythonkeywords.h" | ||
23 | #include "pythonsession.h" | ||||
23 | 24 | | |||
24 | #include <QTextEdit> | 25 | #include <QTextEdit> | ||
25 | #include <QDebug> | 26 | #include <QDebug> | ||
26 | 27 | | |||
27 | PythonHighlighter::PythonHighlighter(QObject* parent, const int pythonVersion) : Cantor::DefaultHighlighter(parent) | 28 | PythonHighlighter::PythonHighlighter(QObject* parent, PythonSession* session, const int pythonVersion) : Cantor::DefaultHighlighter(parent, session) | ||
28 | { | 29 | { | ||
29 | qDebug() << "PythonHighlighter constructor"; | 30 | qDebug() << "PythonHighlighter constructor"; | ||
30 | addRule(QRegExp(QLatin1String("\\b\\w+(?=\\()")), functionFormat()); | 31 | addRule(QRegExp(QLatin1String("\\b\\w+(?=\\()")), functionFormat()); | ||
31 | 32 | | |||
32 | //Code highlighting the different keywords | 33 | //Code highlighting the different keywords | ||
33 | addKeywords(PythonKeywords::instance()->keywords()); | 34 | addKeywords(PythonKeywords::instance()->keywords()); | ||
34 | addFunctions(PythonKeywords::instance()->functions()); | 35 | addFunctions(PythonKeywords::instance()->functions()); | ||
35 | addVariables(PythonKeywords::instance()->variables()); | 36 | addVariables(PythonKeywords::instance()->variables()); | ||
▲ Show 20 Lines • Show All 101 Lines • ▼ Show 20 Line(s) | 135 | } else if (minRegexp) { | |||
137 | setFormat(minPos, minRegexp->matchedLength(), formats[minIdx]); | 138 | setFormat(minPos, minRegexp->matchedLength(), formats[minIdx]); | ||
138 | } else { | 139 | } else { | ||
139 | break; | 140 | break; | ||
140 | } | 141 | } | ||
141 | } | 142 | } | ||
142 | 143 | | |||
143 | setCurrentBlockState(state); | 144 | setCurrentBlockState(state); | ||
144 | } | 145 | } | ||
145 | | ||||
146 | void PythonHighlighter::updateHighlight() | | |||
147 | { | | |||
148 | addVariables(m_variables); | | |||
149 | rehighlight(); | | |||
150 | } | | |||
151 | | ||||
152 | void PythonHighlighter::addVariable(const QString variable) | | |||
153 | { | | |||
154 | m_variables << variable; | | |||
155 | } | | |||
156 | | ||||
157 | void PythonHighlighter::clearVariables() | | |||
158 | { | | |||
159 | removeRules(m_variables); | | |||
160 | m_variables.clear(); | | |||
161 | rehighlight(); | | |||
162 | } | |