ui/logic/data: show parse errors in CodeView
This change saves the errors while parsing in the Storage and displays them in the CodeView. The error messages can be read in the tooltip on hovering. The error count is visible in the status bar.
This commit is contained in:
@@ -3,13 +3,14 @@
|
||||
#include <QLabel>
|
||||
#include <QVBoxLayout>
|
||||
|
||||
#include "qt/element/QtCodeFileList.h"
|
||||
#include "qt/element/QtCodeSnippet.h"
|
||||
#include "utility/FileSystem.h"
|
||||
|
||||
QtCodeFile::QtCodeFile(const std::string& filePath, QWidget *parent)
|
||||
QtCodeFile::QtCodeFile(const std::string& filePath, QtCodeFileList* parent)
|
||||
: QWidget(parent)
|
||||
, m_parent(parent)
|
||||
, m_filePath(filePath)
|
||||
, m_showMaximizeButton(true)
|
||||
{
|
||||
setObjectName("code_file");
|
||||
|
||||
@@ -31,21 +32,35 @@ QtCodeFile::~QtCodeFile()
|
||||
{
|
||||
}
|
||||
|
||||
const std::string& QtCodeFile::getFilePath() const
|
||||
{
|
||||
return m_filePath;
|
||||
}
|
||||
|
||||
std::string QtCodeFile::getFileName() const
|
||||
{
|
||||
return FileSystem::fileName(m_filePath);
|
||||
}
|
||||
|
||||
const std::vector<Id>& QtCodeFile::getActiveTokenIds() const
|
||||
{
|
||||
return m_parent->getActiveTokenIds();
|
||||
}
|
||||
|
||||
const std::vector<std::string>& QtCodeFile::getErrorMessages() const
|
||||
{
|
||||
return m_parent->getErrorMessages();
|
||||
}
|
||||
|
||||
void QtCodeFile::addCodeSnippet(
|
||||
uint startLineNumber,
|
||||
const std::string& code,
|
||||
const TokenLocationFile& locationFile,
|
||||
const std::vector<Id>& activeTokenIds
|
||||
const TokenLocationFile& locationFile
|
||||
){
|
||||
std::shared_ptr<QtCodeSnippet> snippet(
|
||||
new QtCodeSnippet(startLineNumber, code, locationFile, activeTokenIds, this));
|
||||
new QtCodeSnippet(startLineNumber, code, locationFile, this));
|
||||
|
||||
if (m_showMaximizeButton)
|
||||
if (m_parent->getShowMaximizeButton())
|
||||
{
|
||||
snippet->addMaximizeButton();
|
||||
}
|
||||
@@ -65,15 +80,10 @@ void QtCodeFile::addCodeSnippet(
|
||||
}
|
||||
}
|
||||
|
||||
void QtCodeFile::setActiveTokenIds(const std::vector<Id>& activeTokenIds)
|
||||
void QtCodeFile::update()
|
||||
{
|
||||
for (std::shared_ptr<QtCodeSnippet> snippet : m_snippets)
|
||||
{
|
||||
snippet->setActiveTokenIds(activeTokenIds);
|
||||
snippet->update();
|
||||
}
|
||||
}
|
||||
|
||||
void QtCodeFile::setShowMaximizeButton(bool show)
|
||||
{
|
||||
m_showMaximizeButton = show;
|
||||
}
|
||||
|
||||
@@ -9,31 +9,34 @@
|
||||
|
||||
#include "utility/types.h"
|
||||
|
||||
class QtCodeFileList;
|
||||
class QtCodeSnippet;
|
||||
class TokenLocationFile;
|
||||
|
||||
class QtCodeFile : public QWidget
|
||||
{
|
||||
public:
|
||||
QtCodeFile(const std::string& filePath, QWidget *parent = 0);
|
||||
QtCodeFile(const std::string& filePath, QtCodeFileList* parent);
|
||||
virtual ~QtCodeFile();
|
||||
|
||||
const std::string& getFilePath() const;
|
||||
std::string getFileName() const;
|
||||
const std::vector<Id>& getActiveTokenIds() const;
|
||||
const std::vector<std::string>& getErrorMessages() const;
|
||||
|
||||
void addCodeSnippet(
|
||||
uint startLineNumber,
|
||||
const std::string& code,
|
||||
const TokenLocationFile& locationFile,
|
||||
const std::vector<Id>& activeTokenIds
|
||||
const TokenLocationFile& locationFile
|
||||
);
|
||||
|
||||
void setActiveTokenIds(const std::vector<Id>& activeTokenIds);
|
||||
void setShowMaximizeButton(bool show);
|
||||
void update();
|
||||
|
||||
private:
|
||||
std::vector<std::shared_ptr<QtCodeSnippet> > m_snippets;
|
||||
QtCodeFileList* m_parent;
|
||||
|
||||
std::vector<std::shared_ptr<QtCodeSnippet>> m_snippets;
|
||||
const std::string m_filePath;
|
||||
bool m_showMaximizeButton;
|
||||
};
|
||||
|
||||
#endif // QT_CODE_FILE_H
|
||||
|
||||
@@ -36,8 +36,7 @@ QSize QtCodeFileList::sizeHint() const
|
||||
void QtCodeFileList::addCodeSnippet(
|
||||
uint startLineNumber,
|
||||
const std::string& code,
|
||||
const TokenLocationFile& locationFile,
|
||||
const std::vector<Id>& activeTokenIds
|
||||
const TokenLocationFile& locationFile
|
||||
){
|
||||
std::string fileName = FileSystem::fileName(locationFile.getFilePath());
|
||||
QtCodeFile* file = nullptr;
|
||||
@@ -58,11 +57,9 @@ void QtCodeFileList::addCodeSnippet(
|
||||
|
||||
file = filePtr.get();
|
||||
m_frame->layout()->addWidget(file);
|
||||
|
||||
file->setShowMaximizeButton(m_showMaximizeButton);
|
||||
}
|
||||
|
||||
file->addCodeSnippet(startLineNumber, code, locationFile, activeTokenIds);
|
||||
file->addCodeSnippet(startLineNumber, code, locationFile);
|
||||
}
|
||||
|
||||
void QtCodeFileList::clearCodeSnippets()
|
||||
@@ -70,15 +67,43 @@ void QtCodeFileList::clearCodeSnippets()
|
||||
m_files.clear();
|
||||
}
|
||||
|
||||
const std::vector<Id>& QtCodeFileList::getActiveTokenIds() const
|
||||
{
|
||||
return m_activeTokenIds;
|
||||
}
|
||||
|
||||
void QtCodeFileList::setActiveTokenIds(const std::vector<Id>& activeTokenIds)
|
||||
{
|
||||
for (std::shared_ptr<QtCodeFile> file: m_files)
|
||||
{
|
||||
file->setActiveTokenIds(activeTokenIds);
|
||||
}
|
||||
m_activeTokenIds = activeTokenIds;
|
||||
updateFiles();
|
||||
}
|
||||
|
||||
const std::vector<std::string>& QtCodeFileList::getErrorMessages() const
|
||||
{
|
||||
return m_errorMessages;
|
||||
}
|
||||
|
||||
void QtCodeFileList::setErrorMessages(const std::vector<std::string>& errorMessages)
|
||||
{
|
||||
m_errorMessages = errorMessages;
|
||||
updateFiles();
|
||||
}
|
||||
|
||||
bool QtCodeFileList::getShowMaximizeButton() const
|
||||
{
|
||||
return m_showMaximizeButton;
|
||||
}
|
||||
|
||||
void QtCodeFileList::setShowMaximizeButton(bool show)
|
||||
{
|
||||
m_showMaximizeButton = show;
|
||||
updateFiles();
|
||||
}
|
||||
|
||||
void QtCodeFileList::updateFiles()
|
||||
{
|
||||
for (std::shared_ptr<QtCodeFile> file: m_files)
|
||||
{
|
||||
file->update();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,19 +25,28 @@ public:
|
||||
void addCodeSnippet(
|
||||
uint startLineNumber,
|
||||
const std::string& code,
|
||||
const TokenLocationFile& locationFile,
|
||||
const std::vector<Id>& activeTokenIds
|
||||
const TokenLocationFile& locationFile
|
||||
);
|
||||
|
||||
void clearCodeSnippets();
|
||||
|
||||
const std::vector<Id>& getActiveTokenIds() const;
|
||||
void setActiveTokenIds(const std::vector<Id>& activeTokenIds);
|
||||
|
||||
const std::vector<std::string>& getErrorMessages() const;
|
||||
void setErrorMessages(const std::vector<std::string>& errorMessages);
|
||||
|
||||
bool getShowMaximizeButton() const;
|
||||
void setShowMaximizeButton(bool show);
|
||||
|
||||
private:
|
||||
std::shared_ptr<QFrame> m_frame;
|
||||
std::vector<std::shared_ptr<QtCodeFile> > m_files;
|
||||
void updateFiles();
|
||||
|
||||
std::shared_ptr<QFrame> m_frame;
|
||||
std::vector<std::shared_ptr<QtCodeFile>> m_files;
|
||||
|
||||
std::vector<Id> m_activeTokenIds;
|
||||
std::vector<std::string> m_errorMessages;
|
||||
bool m_showMaximizeButton;
|
||||
};
|
||||
|
||||
|
||||
@@ -4,10 +4,12 @@
|
||||
#include <QHBoxLayout>
|
||||
#include <QPainter>
|
||||
#include <QPushButton>
|
||||
#include <QToolTip>
|
||||
|
||||
#include "ApplicationSettings.h"
|
||||
#include "data/location/TokenLocation.h"
|
||||
#include "data/location/TokenLocationFile.h"
|
||||
#include "qt/element/QtCodeFile.h"
|
||||
#include "qt/utility/QtHighlighter.h"
|
||||
#include "utility/messaging/type/MessageActivateTokenLocation.h"
|
||||
#include "utility/messaging/type/MessageShowFile.h"
|
||||
@@ -38,14 +40,13 @@ QtCodeSnippet::QtCodeSnippet(
|
||||
uint startLineNumber,
|
||||
const std::string& code,
|
||||
const TokenLocationFile& locationFile,
|
||||
const std::vector<Id>& activeTokenIds,
|
||||
QWidget *parent
|
||||
QtCodeFile* parent
|
||||
)
|
||||
: QPlainTextEdit(parent)
|
||||
, m_parent(parent)
|
||||
, m_maximizeButton(nullptr)
|
||||
, m_startLineNumber(startLineNumber)
|
||||
, m_filePath(locationFile.getFilePath())
|
||||
, m_activeTokenIds(activeTokenIds)
|
||||
, m_hoveredAnnotation(nullptr)
|
||||
, m_digits(0)
|
||||
{
|
||||
setObjectName("code_snippet");
|
||||
@@ -73,8 +74,9 @@ QtCodeSnippet::QtCodeSnippet(
|
||||
|
||||
connect(this, SIGNAL(blockCountChanged(int)), this, SLOT(updateLineNumberAreaWidth(int)));
|
||||
connect(this, SIGNAL(updateRequest(QRect,int)), this, SLOT(updateLineNumberArea(QRect,int)));
|
||||
connect(this, SIGNAL(cursorPositionChanged()), this, SLOT(clickedTokenLocation()));
|
||||
connect(this, SIGNAL(selectionChanged()), this, SLOT(clearSelection()));
|
||||
|
||||
this->setMouseTracking(true);
|
||||
}
|
||||
|
||||
QtCodeSnippet::~QtCodeSnippet()
|
||||
@@ -154,9 +156,8 @@ void QtCodeSnippet::updateLineNumberAreaWidthForDigits(int digits)
|
||||
updateLineNumberAreaWidth(0);
|
||||
}
|
||||
|
||||
void QtCodeSnippet::setActiveTokenIds(const std::vector<Id>& activeTokenIds)
|
||||
void QtCodeSnippet::update()
|
||||
{
|
||||
m_activeTokenIds = activeTokenIds;
|
||||
annotateText();
|
||||
}
|
||||
|
||||
@@ -192,14 +193,52 @@ void QtCodeSnippet::leaveEvent(QEvent* event)
|
||||
}
|
||||
}
|
||||
|
||||
void QtCodeSnippet::mouseReleaseEvent(QMouseEvent* event)
|
||||
{
|
||||
if (event->button() == Qt::LeftButton)
|
||||
{
|
||||
QTextCursor cursor = this->cursorForPosition(event->pos());
|
||||
const Annotation* annotation = findAnnotationForPosition(cursor.position());
|
||||
|
||||
if (annotation)
|
||||
{
|
||||
MessageActivateTokenLocation(annotation->locationId).dispatch();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void QtCodeSnippet::mouseDoubleClickEvent(QMouseEvent* event)
|
||||
{
|
||||
if (m_maximizeButton)
|
||||
if (event->button() == Qt::LeftButton && m_maximizeButton)
|
||||
{
|
||||
clickedMaximizeButton();
|
||||
}
|
||||
}
|
||||
|
||||
void QtCodeSnippet::mouseMoveEvent(QMouseEvent* event)
|
||||
{
|
||||
QTextCursor cursor = this->cursorForPosition(event->pos());
|
||||
const Annotation* annotation = findAnnotationForPosition(cursor.position());
|
||||
|
||||
if (annotation != nullptr ? annotation != m_hoveredAnnotation && !annotation->isScope : m_hoveredAnnotation != nullptr)
|
||||
{
|
||||
m_hoveredAnnotation = annotation;
|
||||
|
||||
const std::vector<std::string>& errorMessages = m_parent->getErrorMessages();
|
||||
|
||||
if (annotation && errorMessages.size() > annotation->tokenId)
|
||||
{
|
||||
QToolTip::showText(event->globalPos(), QString::fromStdString(m_parent->getErrorMessages()[annotation->tokenId]));
|
||||
}
|
||||
else
|
||||
{
|
||||
QToolTip::hideText();
|
||||
}
|
||||
|
||||
annotateText();
|
||||
}
|
||||
}
|
||||
|
||||
void QtCodeSnippet::updateLineNumberAreaWidth(int /* newBlockCount */)
|
||||
{
|
||||
setViewportMargins(lineNumberAreaWidth(), 0, 0, 0);
|
||||
@@ -222,34 +261,9 @@ void QtCodeSnippet::updateLineNumberArea(const QRect &rect, int dy)
|
||||
}
|
||||
}
|
||||
|
||||
void QtCodeSnippet::clickedTokenLocation()
|
||||
{
|
||||
int clickPosition = textCursor().position();
|
||||
int diff = endTextEditPosition() + 1;
|
||||
Id locationId = 0;
|
||||
|
||||
for (Annotation annotation : m_annotations)
|
||||
{
|
||||
if (clickPosition >= annotation.start && clickPosition <= annotation.end)
|
||||
{
|
||||
int d = annotation.end - annotation.start;
|
||||
if (d < diff)
|
||||
{
|
||||
diff = d;
|
||||
locationId = annotation.locationId;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (locationId)
|
||||
{
|
||||
MessageActivateTokenLocation(locationId).dispatch();
|
||||
}
|
||||
}
|
||||
|
||||
void QtCodeSnippet::clickedMaximizeButton()
|
||||
{
|
||||
MessageShowFile(m_filePath, m_startLineNumber, m_startLineNumber + document()->blockCount() - 1).dispatch();
|
||||
MessageShowFile(m_parent->getFilePath(), m_startLineNumber, m_startLineNumber + blockCount() - 1).dispatch();
|
||||
}
|
||||
|
||||
void QtCodeSnippet::clearSelection()
|
||||
@@ -259,12 +273,33 @@ void QtCodeSnippet::clearSelection()
|
||||
setTextCursor(cursor);
|
||||
}
|
||||
|
||||
const QtCodeSnippet::Annotation* QtCodeSnippet::findAnnotationForPosition(int pos) const
|
||||
{
|
||||
const Annotation* annotationPtr = nullptr;
|
||||
int diff = endTextEditPosition() + 1;
|
||||
|
||||
for (const Annotation& annotation : m_annotations)
|
||||
{
|
||||
if (pos >= annotation.start && pos <= annotation.end)
|
||||
{
|
||||
int d = annotation.end - annotation.start;
|
||||
if (d < diff)
|
||||
{
|
||||
diff = d;
|
||||
annotationPtr = &annotation;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return annotationPtr;
|
||||
}
|
||||
|
||||
void QtCodeSnippet::createAnnotations(const TokenLocationFile& locationFile)
|
||||
{
|
||||
locationFile.forEachTokenLocation(
|
||||
[&](TokenLocation* location)
|
||||
{
|
||||
if (location->isEndTokenLocation() && location->getStartTokenLocation())
|
||||
if (!locationBelongsToSnippet(location))
|
||||
{
|
||||
return;
|
||||
}
|
||||
@@ -301,14 +336,27 @@ void QtCodeSnippet::createAnnotations(const TokenLocationFile& locationFile)
|
||||
void QtCodeSnippet::annotateText()
|
||||
{
|
||||
Colori color;
|
||||
const std::vector<Id>& ids = m_activeTokenIds;
|
||||
const std::vector<Id>& ids = m_parent->getActiveTokenIds();
|
||||
const std::vector<std::string>& errorMessages = m_parent->getErrorMessages();
|
||||
QList<QTextEdit::ExtraSelection> extraSelections;
|
||||
|
||||
for (const Annotation& annotation: m_annotations)
|
||||
{
|
||||
bool isActive = std::find(ids.begin(), ids.end(), annotation.tokenId) != ids.end();
|
||||
|
||||
if (isActive)
|
||||
if (&annotation == m_hoveredAnnotation && errorMessages.size())
|
||||
{
|
||||
color = Colori(255, 0, 0, 128);
|
||||
}
|
||||
else if (&annotation == m_hoveredAnnotation)
|
||||
{
|
||||
color = ApplicationSettings::getInstance()->getCodeActiveLinkColor();
|
||||
}
|
||||
else if (errorMessages.size())
|
||||
{
|
||||
color = Colori(255, 0, 0, 255);
|
||||
}
|
||||
else if (isActive)
|
||||
{
|
||||
color = ApplicationSettings::getInstance()->getCodeActiveLinkColor();
|
||||
}
|
||||
@@ -335,6 +383,43 @@ void QtCodeSnippet::annotateText()
|
||||
setExtraSelections(extraSelections);
|
||||
}
|
||||
|
||||
bool QtCodeSnippet::locationBelongsToSnippet(TokenLocation* location) const
|
||||
{
|
||||
uint lineNumber = location->getLineNumber();
|
||||
|
||||
if (location->isEndTokenLocation())
|
||||
{
|
||||
if (location->getStartTokenLocation() ||
|
||||
lineNumber < m_startLineNumber || lineNumber >= m_startLineNumber + blockCount())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
if (lineNumber >= m_startLineNumber + blockCount())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (lineNumber >= m_startLineNumber)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
TokenLocation* endLocation = location->getEndTokenLocation();
|
||||
|
||||
if (endLocation && endLocation->getLineNumber() < m_startLineNumber)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
int QtCodeSnippet::toTextEditPosition(int lineNumber, int columnNumber) const
|
||||
{
|
||||
lineNumber -= m_startLineNumber - 1;
|
||||
|
||||
@@ -11,8 +11,10 @@ class QPaintEvent;
|
||||
class QPushButton;
|
||||
class QResizeEvent;
|
||||
class QSize;
|
||||
class QtCodeFile;
|
||||
class QtHighlighter;
|
||||
class QWidget;
|
||||
class TokenLocation;
|
||||
class TokenLocationFile;
|
||||
|
||||
class QtCodeSnippet: public QPlainTextEdit
|
||||
@@ -39,8 +41,7 @@ public:
|
||||
uint startLineNumber,
|
||||
const std::string& code,
|
||||
const TokenLocationFile& locationFile,
|
||||
const std::vector<Id>& activeTokenIds,
|
||||
QWidget *parent = 0
|
||||
QtCodeFile* parent
|
||||
);
|
||||
virtual ~QtCodeSnippet();
|
||||
|
||||
@@ -53,19 +54,20 @@ public:
|
||||
int lineNumberAreaWidth() const;
|
||||
void updateLineNumberAreaWidthForDigits(int digits);
|
||||
|
||||
void setActiveTokenIds(const std::vector<Id>& activeTokenIds);
|
||||
void update();
|
||||
|
||||
protected:
|
||||
virtual void resizeEvent(QResizeEvent *event);
|
||||
virtual void showEvent(QShowEvent* event);
|
||||
virtual void enterEvent(QEvent* event);
|
||||
virtual void leaveEvent(QEvent* event);
|
||||
virtual void mouseReleaseEvent(QMouseEvent* event);
|
||||
virtual void mouseDoubleClickEvent(QMouseEvent* event);
|
||||
virtual void mouseMoveEvent(QMouseEvent* event);
|
||||
|
||||
private slots:
|
||||
void updateLineNumberAreaWidth(int newBlockCount);
|
||||
void updateLineNumberArea(const QRect &, int);
|
||||
void clickedTokenLocation();
|
||||
void clickedMaximizeButton();
|
||||
void clearSelection();
|
||||
|
||||
@@ -79,24 +81,28 @@ private:
|
||||
bool isScope;
|
||||
};
|
||||
|
||||
const Annotation* findAnnotationForPosition(int pos) const;
|
||||
void createAnnotations(const TokenLocationFile& locationFile);
|
||||
void annotateText();
|
||||
|
||||
bool locationBelongsToSnippet(TokenLocation* location) const;
|
||||
|
||||
int toTextEditPosition(int lineNumber, int columnNumber) const;
|
||||
int startTextEditPosition() const;
|
||||
int endTextEditPosition() const;
|
||||
|
||||
QtCodeFile* m_parent;
|
||||
|
||||
QWidget* m_lineNumberArea;
|
||||
QtHighlighter* m_highlighter;
|
||||
|
||||
QPushButton* m_maximizeButton;
|
||||
bool m_showMaximizeButton;
|
||||
|
||||
const uint m_startLineNumber;
|
||||
const std::string m_filePath;
|
||||
std::vector<Id> m_activeTokenIds;
|
||||
|
||||
std::vector<Annotation> m_annotations;
|
||||
const Annotation* m_hoveredAnnotation;
|
||||
|
||||
int m_digits;
|
||||
};
|
||||
|
||||
|
||||
@@ -17,5 +17,10 @@ void QtStatusBar::setText(const std::string& text, bool isError)
|
||||
{
|
||||
m_text.setStyleSheet("QLabel { color: red }");
|
||||
}
|
||||
else
|
||||
{
|
||||
m_text.setStyleSheet("");
|
||||
}
|
||||
|
||||
m_text.setText(text.c_str());
|
||||
}
|
||||
|
||||
@@ -10,7 +10,6 @@
|
||||
QtCodeView::QtCodeView(ViewLayout* viewLayout)
|
||||
: CodeView(viewLayout)
|
||||
, m_refreshViewFunctor(std::bind(&QtCodeView::doRefreshView, this))
|
||||
, m_clearCodeSnippetsFunctor(std::bind(&QtCodeView::doClearCodeSnippets, this))
|
||||
, m_showCodeSnippetsFunctor(std::bind(&QtCodeView::doShowCodeSnippets, this, std::placeholders::_1))
|
||||
, m_showCodeFileFunctor(std::bind(&QtCodeView::doShowCodeFile, this, std::placeholders::_1))
|
||||
{
|
||||
@@ -35,16 +34,16 @@ void QtCodeView::refreshView()
|
||||
m_refreshViewFunctor();
|
||||
}
|
||||
|
||||
void QtCodeView::clearCodeSnippets()
|
||||
{
|
||||
m_clearCodeSnippetsFunctor();
|
||||
}
|
||||
|
||||
void QtCodeView::setActiveTokenIds(const std::vector<Id>& activeTokenIds)
|
||||
{
|
||||
m_activeTokenIds = activeTokenIds;
|
||||
}
|
||||
|
||||
void QtCodeView::setErrorMessages(const std::vector<std::string>& errorMessages)
|
||||
{
|
||||
m_errorMessages = errorMessages;
|
||||
}
|
||||
|
||||
void QtCodeView::showCodeSnippets(const std::vector<CodeSnippetParams>& snippets)
|
||||
{
|
||||
m_showCodeSnippetsFunctor(snippets);
|
||||
@@ -66,24 +65,31 @@ void QtCodeView::doRefreshView()
|
||||
}
|
||||
}
|
||||
|
||||
void QtCodeView::doClearCodeSnippets()
|
||||
{
|
||||
m_widget->clearCodeSnippets();
|
||||
}
|
||||
|
||||
void QtCodeView::doShowCodeSnippets(const std::vector<CodeSnippetParams>& snippets)
|
||||
{
|
||||
doClearCodeSnippets();
|
||||
m_widget->clearCodeSnippets();
|
||||
|
||||
clearClosedWindows();
|
||||
for (std::shared_ptr<QtCodeFileList> window: m_windows)
|
||||
{
|
||||
window->setActiveTokenIds(m_activeTokenIds);
|
||||
if (m_errorMessages.size())
|
||||
{
|
||||
window->close();
|
||||
}
|
||||
else
|
||||
{
|
||||
window->setActiveTokenIds(m_activeTokenIds);
|
||||
window->setErrorMessages(m_errorMessages);
|
||||
}
|
||||
}
|
||||
|
||||
m_widget->setActiveTokenIds(m_activeTokenIds);
|
||||
m_widget->setErrorMessages(m_errorMessages);
|
||||
m_widget->setShowMaximizeButton(m_errorMessages.size() == 0);
|
||||
|
||||
for (const CodeSnippetParams& params : snippets)
|
||||
{
|
||||
m_widget->addCodeSnippet(params.startLineNumber, params.code, params.locationFile, m_activeTokenIds);
|
||||
m_widget->addCodeSnippet(params.startLineNumber, params.code, params.locationFile);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -93,7 +99,9 @@ void QtCodeView::doShowCodeFile(const CodeSnippetParams& params)
|
||||
m_windows.push_back(ptr);
|
||||
|
||||
ptr->setShowMaximizeButton(false);
|
||||
ptr->addCodeSnippet(1, params.code, params.locationFile, m_activeTokenIds);
|
||||
ptr->setActiveTokenIds(m_activeTokenIds);
|
||||
ptr->setErrorMessages(m_errorMessages);
|
||||
ptr->addCodeSnippet(1, params.code, params.locationFile);
|
||||
|
||||
ptr->setWindowTitle(FileSystem::fileName(params.locationFile.getFilePath()).c_str());
|
||||
ptr->show();
|
||||
|
||||
@@ -24,14 +24,14 @@ public:
|
||||
virtual void refreshView();
|
||||
|
||||
// CodeView implementation
|
||||
virtual void clearCodeSnippets();
|
||||
virtual void setActiveTokenIds(const std::vector<Id>& activeTokenIds);
|
||||
virtual void setErrorMessages(const std::vector<std::string>& errorMessages);
|
||||
|
||||
virtual void showCodeSnippets(const std::vector<CodeSnippetParams>& snippets);
|
||||
virtual void showCodeFile(const CodeSnippetParams& params);
|
||||
|
||||
private:
|
||||
void doRefreshView();
|
||||
void doClearCodeSnippets();
|
||||
void doShowCodeSnippets(const std::vector<CodeSnippetParams>& snippets);
|
||||
void doShowCodeFile(const CodeSnippetParams& params);
|
||||
|
||||
@@ -41,13 +41,14 @@ private:
|
||||
void clearClosedWindows();
|
||||
|
||||
QtThreadedFunctor<> m_refreshViewFunctor;
|
||||
QtThreadedFunctor<> m_clearCodeSnippetsFunctor;
|
||||
QtThreadedFunctor<const std::vector<CodeSnippetParams>&> m_showCodeSnippetsFunctor;
|
||||
QtThreadedFunctor<const CodeSnippetParams&> m_showCodeFileFunctor;
|
||||
|
||||
std::shared_ptr<QtCodeFileList> m_widget;
|
||||
std::vector<std::shared_ptr<QtCodeFileList>> m_windows;
|
||||
|
||||
std::vector<Id> m_activeTokenIds;
|
||||
std::vector<std::string> m_errorMessages;
|
||||
};
|
||||
|
||||
# endif // QT_CODE_VIEW_H
|
||||
|
||||
Reference in New Issue
Block a user