+33
-2
@@ -54,6 +54,7 @@ protected:
|
|||||||
private:
|
private:
|
||||||
QSet<QString> m_keywords;
|
QSet<QString> m_keywords;
|
||||||
QSet<QString> m_knownIds;
|
QSet<QString> m_knownIds;
|
||||||
|
QSet<QString> m_customIds;
|
||||||
QHash<JSEdit::ColorComponent, QColor> m_colors;
|
QHash<JSEdit::ColorComponent, QColor> m_colors;
|
||||||
QString m_markString;
|
QString m_markString;
|
||||||
Qt::CaseSensitivity m_markCaseSensitivity;
|
Qt::CaseSensitivity m_markCaseSensitivity;
|
||||||
@@ -73,6 +74,7 @@ JSHighlighter::JSHighlighter(QTextDocument *parent)
|
|||||||
m_colors[JSEdit::Keyword] = QColor("#000080");
|
m_colors[JSEdit::Keyword] = QColor("#000080");
|
||||||
m_colors[JSEdit::BuiltIn] = QColor("#008080");
|
m_colors[JSEdit::BuiltIn] = QColor("#008080");
|
||||||
m_colors[JSEdit::Marker] = QColor("#ffff00");
|
m_colors[JSEdit::Marker] = QColor("#ffff00");
|
||||||
|
m_colors[JSEdit::Custom] = QColor("#ff00ff");
|
||||||
|
|
||||||
// https://developer.mozilla.org/en/JavaScript/Reference/Reserved_Words
|
// https://developer.mozilla.org/en/JavaScript/Reference/Reserved_Words
|
||||||
m_keywords << "break";
|
m_keywords << "break";
|
||||||
@@ -249,6 +251,27 @@ JSHighlighter::JSHighlighter(QTextDocument *parent)
|
|||||||
m_knownIds << "window";
|
m_knownIds << "window";
|
||||||
m_knownIds << "navigator";
|
m_knownIds << "navigator";
|
||||||
m_knownIds << "userAgent";
|
m_knownIds << "userAgent";
|
||||||
|
|
||||||
|
//Custom objects
|
||||||
|
m_customIds << "host";
|
||||||
|
m_customIds << "can";
|
||||||
|
m_customIds << "isotp";
|
||||||
|
m_customIds << "uds";
|
||||||
|
//Custom callback functions
|
||||||
|
m_customIds << "setup";
|
||||||
|
m_customIds << "tick";
|
||||||
|
m_customIds << "gotCANFrame";
|
||||||
|
m_customIds << "gotISOTPMessage";
|
||||||
|
m_customIds << "gotUDSMessage";
|
||||||
|
//Custom functions
|
||||||
|
m_customIds << "setTickInterval";
|
||||||
|
m_customIds << "log"; //Duplicate
|
||||||
|
m_customIds << "addParameter";
|
||||||
|
m_customIds << "setFilter";
|
||||||
|
m_customIds << "clearFilters";
|
||||||
|
m_customIds << "sendFrame";
|
||||||
|
m_customIds << "sendISOTP";
|
||||||
|
m_customIds << "sendUDS";
|
||||||
}
|
}
|
||||||
|
|
||||||
void JSHighlighter::setColor(JSEdit::ColorComponent component, const QColor &color)
|
void JSHighlighter::setColor(JSEdit::ColorComponent component, const QColor &color)
|
||||||
@@ -271,6 +294,7 @@ void JSHighlighter::highlightBlock(const QString &text)
|
|||||||
};
|
};
|
||||||
|
|
||||||
QList<int> bracketPositions;
|
QList<int> bracketPositions;
|
||||||
|
QString previousToken;
|
||||||
|
|
||||||
int blockState = previousBlockState();
|
int blockState = previousBlockState();
|
||||||
int bracketLevel = blockState >> 4;
|
int bracketLevel = blockState >> 4;
|
||||||
@@ -351,10 +375,17 @@ void JSHighlighter::highlightBlock(const QString &text)
|
|||||||
case Identifier:
|
case Identifier:
|
||||||
if (ch.isSpace() || !(ch.isDigit() || ch.isLetter() || ch == '_')) {
|
if (ch.isSpace() || !(ch.isDigit() || ch.isLetter() || ch == '_')) {
|
||||||
QString token = text.mid(start, i - start).trimmed();
|
QString token = text.mid(start, i - start).trimmed();
|
||||||
if (m_keywords.contains(token))
|
if (m_customIds.contains(token) && m_customIds.contains(previousToken)) {
|
||||||
|
setFormat(start, i - start, m_colors[JSEdit::Custom]);
|
||||||
|
} else if (m_keywords.contains(token)) {
|
||||||
setFormat(start, i - start, m_colors[JSEdit::Keyword]);
|
setFormat(start, i - start, m_colors[JSEdit::Keyword]);
|
||||||
else if (m_knownIds.contains(token))
|
} else if (m_knownIds.contains(token)) {
|
||||||
setFormat(start, i - start, m_colors[JSEdit::BuiltIn]);
|
setFormat(start, i - start, m_colors[JSEdit::BuiltIn]);
|
||||||
|
if (ch == '.') previousToken = token;
|
||||||
|
} else if (m_customIds.contains(token)) {
|
||||||
|
setFormat(start, i - start, m_colors[JSEdit::Custom]);
|
||||||
|
if (ch == '.') previousToken = token;
|
||||||
|
}
|
||||||
state = Start;
|
state = Start;
|
||||||
} else {
|
} else {
|
||||||
++i;
|
++i;
|
||||||
|
|||||||
@@ -57,6 +57,7 @@ public:
|
|||||||
Identifier,
|
Identifier,
|
||||||
Keyword,
|
Keyword,
|
||||||
BuiltIn,
|
BuiltIn,
|
||||||
|
Custom,
|
||||||
Sidebar,
|
Sidebar,
|
||||||
LineNumber,
|
LineNumber,
|
||||||
Cursor,
|
Cursor,
|
||||||
|
|||||||
@@ -21,6 +21,12 @@ ScriptingWindow::ScriptingWindow(const QVector<CANFrame> *frames, QWidget *paren
|
|||||||
editor->setEnabled(false);
|
editor->setEnabled(false);
|
||||||
editor->setFont(QFont("Monospace", 12));
|
editor->setFont(QFont("Monospace", 12));
|
||||||
editor->show();
|
editor->show();
|
||||||
|
|
||||||
|
//Show whitespaces
|
||||||
|
QTextOption option = editor->document()->defaultTextOption();
|
||||||
|
option.setFlags(QTextOption::ShowTabsAndSpaces);
|
||||||
|
editor->document()->setDefaultTextOption(option);
|
||||||
|
|
||||||
ui->verticalLayout->insertWidget(2,editor, 10);
|
ui->verticalLayout->insertWidget(2,editor, 10);
|
||||||
|
|
||||||
readSettings();
|
readSettings();
|
||||||
|
|||||||
Reference in New Issue
Block a user