diff --git a/bin/app/data/color_schemes/bright.xml b/bin/app/data/color_schemes/bright.xml
index 03ab3d97..e0238538 100644
--- a/bin/app/data/color_schemes/bright.xml
+++ b/bin/app/data/color_schemes/bright.xml
@@ -99,6 +99,7 @@
#B2B2B2
#EDEDED
+ #000000
@@ -133,14 +134,17 @@
transparent
#80FF0000
+ #000000
transparent
#FFFF0000
+ #000000
transparent
#FFFF0000
+ #000000
diff --git a/bin/app/data/color_schemes/dark.xml b/bin/app/data/color_schemes/dark.xml
index a521c44f..c4f030f5 100644
--- a/bin/app/data/color_schemes/dark.xml
+++ b/bin/app/data/color_schemes/dark.xml
@@ -99,6 +99,7 @@
#B2B2B2
#4A4A4A
+ #F7F7F7
diff --git a/src/lib/component/controller/UndoRedoController.cpp b/src/lib/component/controller/UndoRedoController.cpp
index b866bc6a..44cd8f64 100644
--- a/src/lib/component/controller/UndoRedoController.cpp
+++ b/src/lib/component/controller/UndoRedoController.cpp
@@ -53,22 +53,6 @@ void UndoRedoController::handleMessage(MessageActivateFile* message)
processCommand(command);
}
-void UndoRedoController::handleMessage(MessageActivateLocalSymbols* message)
-{
- if (m_lastCommand.message &&
- m_lastCommand.message->getType() == message->getType() &&
- utility::isPermutation(
- message->symbolIds,
- static_cast(m_lastCommand.message.get())->symbolIds)
- )
- {
- return;
- }
-
- Command command(std::make_shared(*message), 1);
- processCommand(command);
-}
-
void UndoRedoController::handleMessage(MessageActivateNodes* message)
{
if (m_lastCommand.message &&
diff --git a/src/lib/component/controller/UndoRedoController.h b/src/lib/component/controller/UndoRedoController.h
index 911f3947..cce664bd 100644
--- a/src/lib/component/controller/UndoRedoController.h
+++ b/src/lib/component/controller/UndoRedoController.h
@@ -7,7 +7,6 @@
#include "utility/messaging/MessageListener.h"
#include "utility/messaging/type/MessageActivateEdge.h"
#include "utility/messaging/type/MessageActivateFile.h"
-#include "utility/messaging/type/MessageActivateLocalSymbols.h"
#include "utility/messaging/type/MessageActivateNodes.h"
#include "utility/messaging/type/MessageActivateTokenIds.h"
#include "utility/messaging/type/MessageChangeFileView.h"
@@ -33,7 +32,6 @@ class UndoRedoController
: public Controller
, public MessageListener
, public MessageListener
- , public MessageListener
, public MessageListener
, public MessageListener
, public MessageListener
@@ -67,7 +65,6 @@ private:
virtual void handleMessage(MessageActivateEdge* message);
virtual void handleMessage(MessageActivateFile* message);
- virtual void handleMessage(MessageActivateLocalSymbols* message);
virtual void handleMessage(MessageActivateNodes* message);
virtual void handleMessage(MessageActivateTokenIds* message);
virtual void handleMessage(MessageChangeFileView* message);
diff --git a/src/lib_gui/qt/element/QtCodeArea.cpp b/src/lib_gui/qt/element/QtCodeArea.cpp
index 492588b0..0a8bbd35 100644
--- a/src/lib_gui/qt/element/QtCodeArea.cpp
+++ b/src/lib_gui/qt/element/QtCodeArea.cpp
@@ -96,6 +96,7 @@ QtCodeArea::QtCodeArea(
, m_eventPosition(0, 0)
, m_isActiveFile(false)
, m_lineNumbersHidden(false)
+ , m_wasAnnotated(false)
{
setObjectName("code_area");
setReadOnly(true);
@@ -114,8 +115,6 @@ QtCodeArea::QtCodeArea(
}
setPlainText(QString::fromUtf8(displayCode.c_str()));
- createAnnotations(locationFile);
- annotateText();
m_digits = lineNumberDigits();
updateLineNumberAreaWidth();
@@ -130,6 +129,11 @@ QtCodeArea::QtCodeArea(
horizontalScrollBar()->installEventFilter(new MouseWheelOverScrollbarFilter(this));
createActions();
+
+ m_highlighter->highlightDocument();
+
+ createAnnotations(locationFile);
+ annotateText();
}
QtCodeArea::~QtCodeArea()
@@ -602,12 +606,9 @@ void QtCodeArea::activateLocalSymbols(const std::vector& anno
}
}
- if (!allActive)
+ if (!allActive || !localSymbolIds.size())
{
- if (localSymbolIds.size())
- {
- MessageActivateLocalSymbols(localSymbolIds).dispatch();
- }
+ MessageActivateLocalSymbols(localSymbolIds).dispatch();
}
}
@@ -686,6 +687,7 @@ void QtCodeArea::annotateText()
{
bool wasActive = annotation.isActive;
bool wasFocused = annotation.isFocused;
+ const AnnotationColor& oldColor = getAnnotationColorForAnnotation(annotation);
annotation.isActive = (
std::find(activeTokenIds.begin(), activeTokenIds.end(), annotation.tokenId) != activeTokenIds.end() ||
@@ -695,6 +697,21 @@ void QtCodeArea::annotateText()
annotation.isError = isError;
+ const AnnotationColor& newColor = getAnnotationColorForAnnotation(annotation);
+ if ((newColor.text != oldColor.text || !m_wasAnnotated))
+ {
+ if (newColor.text.size() > 0 && newColor.text != "transparent")
+ {
+ annotation.oldTextColor = m_highlighter->getFormat(annotation.start, annotation.end).foreground().color();
+ setTextColorForAnnotation(annotation, QColor(newColor.text.c_str()));
+ }
+ else if (annotation.oldTextColor.isValid())
+ {
+ setTextColorForAnnotation(annotation, annotation.oldTextColor);
+ annotation.oldTextColor = QColor();
+ }
+ }
+
if (wasFocused != annotation.isFocused || wasActive != annotation.isActive)
{
needsUpdate = true;
@@ -706,6 +723,8 @@ void QtCodeArea::annotateText()
m_lineNumberArea->update();
viewport()->update();
}
+
+ m_wasAnnotated = true;
}
void QtCodeArea::setHoveredAnnotations(const std::vector& annotations)
@@ -838,7 +857,8 @@ std::vector QtCodeArea::getCursorRectsForAnnotation(const Annotation& ann
if (line == annotation.endLine)
{
// Avoid that annotations at line end span down to first column of the next line.
- if (annotation.startLine != annotation.endLine || document()->findBlockByLineNumber(line - m_startLineNumber).length() != annotation.endCol)
+ if (annotation.startLine != annotation.endLine ||
+ document()->findBlockByLineNumber(line - m_startLineNumber).length() != annotation.endCol)
{
cursor.setPosition(annotation.end);
}
@@ -849,7 +869,12 @@ std::vector QtCodeArea::getCursorRectsForAnnotation(const Annotation& ann
}
rectEnd = cursorRect(cursor);
- rects.push_back(QRect(rectStart.left(), rectStart.top(), rectEnd.right() - rectStart.left(), rectEnd.bottom() - rectStart.top()));
+ rects.push_back(QRect(
+ rectStart.left(),
+ rectStart.top(),
+ rectEnd.right() - rectStart.left(),
+ rectEnd.bottom() - rectStart.top()
+ ));
line++;
@@ -886,6 +911,7 @@ const QtCodeArea::AnnotationColor& QtCodeArea::getAnnotationColorForAnnotation(c
AnnotationColor color;
color.border = scheme->getColor("code/snippet/selection/" + type + "/" + state + "/border");
color.fill = scheme->getColor("code/snippet/selection/" + type + "/" + state + "/fill");
+ color.text = scheme->getColor("code/snippet/selection/" + type + "/" + state + "/text");
s_annotationColors.push_back(color);
}
}
@@ -918,6 +944,13 @@ const QtCodeArea::AnnotationColor& QtCodeArea::getAnnotationColorForAnnotation(c
return s_annotationColors[i];
}
+void QtCodeArea::setTextColorForAnnotation(Annotation& annotation, QColor color) const
+{
+ QTextCharFormat format;
+ format.setForeground(color);
+ m_highlighter->applyFormat(annotation.start, annotation.end, format);
+}
+
void QtCodeArea::createActions()
{
m_setIDECursorPositionAction = new QAction(tr("Set IDE Cursor"), this);
diff --git a/src/lib_gui/qt/element/QtCodeArea.h b/src/lib_gui/qt/element/QtCodeArea.h
index 9edf9441..7ad2cae7 100644
--- a/src/lib_gui/qt/element/QtCodeArea.h
+++ b/src/lib_gui/qt/element/QtCodeArea.h
@@ -130,12 +130,15 @@ private:
bool isActive;
bool isFocused;
+
+ QColor oldTextColor;
};
struct AnnotationColor
{
std::string border;
std::string fill;
+ std::string text;
};
std::vector getNonScopeAnnotationsForPosition(int pos) const;
@@ -156,6 +159,7 @@ private:
std::vector getCursorRectsForAnnotation(const Annotation& annotation) const;
const AnnotationColor& getAnnotationColorForAnnotation(const Annotation& annotation);
+ void setTextColorForAnnotation(Annotation& annotation, QColor color) const;
void createActions();
@@ -183,6 +187,7 @@ private:
bool m_isActiveFile;
bool m_lineNumbersHidden;
+ bool m_wasAnnotated;
};
#endif // QT_CODE_AREA_H
diff --git a/src/lib_gui/qt/utility/QtHighlighter.cpp b/src/lib_gui/qt/utility/QtHighlighter.cpp
index 3fdcb7d3..311e87e9 100644
--- a/src/lib_gui/qt/utility/QtHighlighter.cpp
+++ b/src/lib_gui/qt/utility/QtHighlighter.cpp
@@ -5,8 +5,11 @@
#include "settings/ColorScheme.h"
-QtHighlighter::QtHighlighter(QTextDocument *parent)
- : QSyntaxHighlighter(parent)
+QVector QtHighlighter::s_highlightingRules;
+QtHighlighter::HighlightingRule QtHighlighter::s_quotationRule;
+QtHighlighter::HighlightingRule QtHighlighter::s_commentRule;
+
+void QtHighlighter::createHighlightingRules()
{
QStringList keywordPatterns;
keywordPatterns
@@ -41,47 +44,60 @@ QtHighlighter::QtHighlighter(QTextDocument *parent)
QColor quotationColor(scheme->getSyntaxColor("quotation").c_str());
QColor commentColor = scheme->getSyntaxColor("comment").c_str();
+ s_highlightingRules.clear();
+
foreach (const QString &pattern, keywordPatterns)
{
- addHighlightingRule(keywordColor, QRegExp("\\b" + pattern + "\\b"));
+ s_highlightingRules.append(HighlightingRule(keywordColor, QRegExp("\\b" + pattern + "\\b")));
}
foreach (const QString &pattern, typePatterns)
{
- addHighlightingRule(typeColor, QRegExp("\\b" + pattern + "\\b"));
+ s_highlightingRules.append(HighlightingRule(typeColor, QRegExp("\\b" + pattern + "\\b")));
}
- addHighlightingRule(directiveColor, directiveRegExp);
- addHighlightingRule(numberColor, numberRegExp);
- addHighlightingRule(functionColor, functionRegExp);
- addHighlightingRule(quotationColor, quotation2RegExp);
+ s_highlightingRules.append(HighlightingRule(directiveColor, directiveRegExp));
+ s_highlightingRules.append(HighlightingRule(numberColor, numberRegExp));
+ s_highlightingRules.append(HighlightingRule(functionColor, functionRegExp));
+ s_highlightingRules.append(HighlightingRule(quotationColor, quotation2RegExp));
- m_quotationRule = HighlightingRule(quotationColor, quotationRegExp);
- m_commentRule = HighlightingRule(commentColor, commentRegExp);
+ s_quotationRule = HighlightingRule(quotationColor, quotationRegExp);
+ s_commentRule = HighlightingRule(commentColor, commentRegExp);
+}
+
+void QtHighlighter::clearHighlightingRules()
+{
+ s_highlightingRules.clear();
+}
+
+QtHighlighter::QtHighlighter(QTextDocument *parent)
+ : QSyntaxHighlighter(parent)
+{
}
void QtHighlighter::highlightBlock(const QString& text)
{
- if (currentBlock().blockNumber() == 0)
- {
- highlightDocument();
- }
}
void QtHighlighter::highlightDocument()
{
+ if (!s_highlightingRules.size())
+ {
+ createHighlightingRules();
+ }
+
QTextDocument* doc = document();
std::vector> ranges;
for (QTextBlock it = doc->begin(); it != doc->end(); it = it.next())
{
- formatBlock(it, m_quotationRule, &ranges, true);
+ formatBlock(it, s_quotationRule, &ranges, true);
}
for (QTextBlock it = doc->begin(); it != doc->end(); it = it.next())
{
- foreach (const HighlightingRule &rule, m_highlightingRules)
+ foreach (const HighlightingRule &rule, s_highlightingRules)
{
formatBlock(it, rule, &ranges, false);
}
@@ -91,7 +107,7 @@ void QtHighlighter::highlightDocument()
for (QTextBlock it = doc->begin(); it != doc->end(); it = it.next())
{
- formatBlock(it, m_commentRule, &ranges, true);
+ formatBlock(it, s_commentRule, &ranges, true);
}
}
@@ -128,7 +144,7 @@ void QtHighlighter::highlightMultiLineComments(std::vector>*
break;
}
- applyFormat(cursorStart.selectionStart(), cursorEnd.position(), m_commentRule.format);
+ applyFormat(cursorStart.selectionStart(), cursorEnd.position(), s_commentRule.format);
ranges->push_back(std::pair(cursorStart.selectionStart(), cursorEnd.position()));
cursorStart = cursorEnd;
@@ -145,11 +161,6 @@ QtHighlighter::HighlightingRule::HighlightingRule(const QColor& color, const QRe
pattern = regExp;
}
-void QtHighlighter::addHighlightingRule(const QColor& color, const QRegExp& regExp)
-{
- m_highlightingRules.append(HighlightingRule(color, regExp));
-}
-
bool QtHighlighter::isInRange(int pos, const std::vector>& ranges) const
{
for (const std::pair p : ranges)
@@ -197,3 +208,10 @@ void QtHighlighter::applyFormat(int startPosition, int endPosition, const QTextC
cursor.setPosition(endPosition, QTextCursor::KeepAnchor);
cursor.setCharFormat(format);
}
+
+QTextCharFormat QtHighlighter::getFormat(int startPosition, int endPosition) const
+{
+ QTextCursor cursor(document());
+ cursor.setPosition(endPosition);
+ return cursor.charFormat();
+}
diff --git a/src/lib_gui/qt/utility/QtHighlighter.h b/src/lib_gui/qt/utility/QtHighlighter.h
index 82ebd7cb..6eb329b0 100644
--- a/src/lib_gui/qt/utility/QtHighlighter.h
+++ b/src/lib_gui/qt/utility/QtHighlighter.h
@@ -12,7 +12,14 @@ class QtHighlighter
Q_OBJECT
public:
+ static void createHighlightingRules();
+ static void clearHighlightingRules();
+
QtHighlighter(QTextDocument *parent = 0);
+ void highlightDocument();
+
+ void applyFormat(int startPosition, int endPosition, const QTextCharFormat& format);
+ QTextCharFormat getFormat(int startPosition, int endPosition) const;
protected:
void highlightBlock(const QString& text);
@@ -27,18 +34,14 @@ private:
QTextCharFormat format;
};
- void highlightDocument();
void highlightMultiLineComments(std::vector>* ranges);
- void addHighlightingRule(const QColor& color, const QRegExp& regExp);
-
bool isInRange(int index, const std::vector>& ranges) const;
void formatBlock(const QTextBlock& block, const HighlightingRule& rule, std::vector>* ranges, bool saveRange);
- void applyFormat(int startPosition, int endPosition, const QTextCharFormat& format);
- QVector m_highlightingRules;
- HighlightingRule m_quotationRule;
- HighlightingRule m_commentRule;
+ static QVector s_highlightingRules;
+ static HighlightingRule s_quotationRule;
+ static HighlightingRule s_commentRule;
};
#endif // QT_HIGHLIGHTER_H
diff --git a/src/lib_gui/qt/view/QtCodeView.cpp b/src/lib_gui/qt/view/QtCodeView.cpp
index 7d786518..831c9a3e 100644
--- a/src/lib_gui/qt/view/QtCodeView.cpp
+++ b/src/lib_gui/qt/view/QtCodeView.cpp
@@ -6,6 +6,7 @@
#include "qt/element/QtCodeArea.h"
#include "qt/element/QtCodeFileList.h"
+#include "qt/utility/QtHighlighter.h"
#include "qt/view/QtViewWidgetWrapper.h"
#include "settings/ColorScheme.h"
@@ -121,7 +122,9 @@ void QtCodeView::doRefreshView()
{
setStyleSheet();
m_widget->clearCodeSnippets();
+
QtCodeArea::clearAnnotationColors();
+ QtHighlighter::clearHighlightingRules();
}
void QtCodeView::doClear()