diff --git a/jsedit.cpp b/jsedit.cpp index 4784219..5a994d0 100644 --- a/jsedit.cpp +++ b/jsedit.cpp @@ -54,6 +54,7 @@ protected: private: QSet m_keywords; QSet m_knownIds; + QSet m_customIds; QHash m_colors; QString m_markString; Qt::CaseSensitivity m_markCaseSensitivity; @@ -73,6 +74,7 @@ JSHighlighter::JSHighlighter(QTextDocument *parent) m_colors[JSEdit::Keyword] = QColor("#000080"); m_colors[JSEdit::BuiltIn] = QColor("#008080"); m_colors[JSEdit::Marker] = QColor("#ffff00"); + m_colors[JSEdit::Custom] = QColor("#ff00ff"); // https://developer.mozilla.org/en/JavaScript/Reference/Reserved_Words m_keywords << "break"; @@ -249,6 +251,27 @@ JSHighlighter::JSHighlighter(QTextDocument *parent) m_knownIds << "window"; m_knownIds << "navigator"; 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) @@ -271,6 +294,7 @@ void JSHighlighter::highlightBlock(const QString &text) }; QList bracketPositions; + QString previousToken; int blockState = previousBlockState(); int bracketLevel = blockState >> 4; @@ -351,10 +375,17 @@ void JSHighlighter::highlightBlock(const QString &text) case Identifier: if (ch.isSpace() || !(ch.isDigit() || ch.isLetter() || ch == '_')) { 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]); - else if (m_knownIds.contains(token)) + } else if (m_knownIds.contains(token)) { 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; } else { ++i; diff --git a/jsedit.h b/jsedit.h index 104856e..52eefc8 100644 --- a/jsedit.h +++ b/jsedit.h @@ -57,6 +57,7 @@ public: Identifier, Keyword, BuiltIn, + Custom, Sidebar, LineNumber, Cursor, diff --git a/scriptingwindow.cpp b/scriptingwindow.cpp index 2fe7238..1d5f378 100644 --- a/scriptingwindow.cpp +++ b/scriptingwindow.cpp @@ -21,6 +21,12 @@ ScriptingWindow::ScriptingWindow(const QVector *frames, QWidget *paren editor->setEnabled(false); editor->setFont(QFont("Monospace", 12)); editor->show(); + + //Show whitespaces + QTextOption option = editor->document()->defaultTextOption(); + option.setFlags(QTextOption::ShowTabsAndSpaces); + editor->document()->setDefaultTextOption(option); + ui->verticalLayout->insertWidget(2,editor, 10); readSettings();