ui: precollapse files in code view
This change shows the files in the code view minimized, if more than 5. This greatly improves performance, because code and annotations won't get loaded until needed. Files including declarations or definitions of the active symbol are still expanded. The number of references in each file is now shown in it's title bar. Clicking the title bar allows for expanding and collapsing as well now.
This commit is contained in:
@@ -54,6 +54,11 @@
|
||||
<press>#626262</press>
|
||||
<icon>black</icon>
|
||||
</title>
|
||||
|
||||
<ref_count>
|
||||
<text>black</text>
|
||||
<background>white</background>
|
||||
</ref_count>
|
||||
</file>
|
||||
|
||||
<snippet>
|
||||
|
||||
@@ -54,6 +54,11 @@
|
||||
<press>#444444</press>
|
||||
<icon>white</icon>
|
||||
</title>
|
||||
|
||||
<ref_count>
|
||||
<text>#F7F7F7</text>
|
||||
<background>#272728</background>
|
||||
</ref_count>
|
||||
</file>
|
||||
|
||||
<snippet>
|
||||
|
||||
@@ -36,6 +36,16 @@
|
||||
background-color: <color:code/file/title/press>;
|
||||
}
|
||||
|
||||
#code_file #references_label {
|
||||
background-color: <color:code/file/ref_count/background>;
|
||||
border: none;
|
||||
border-radius: 10px;
|
||||
color: <color:code/file/ref_count/text>;
|
||||
font-size: <setting:font_size-2>pt;
|
||||
padding: 0px 3px;
|
||||
margin: 4px 0px 4px;
|
||||
}
|
||||
|
||||
#code_file #code_snippet {
|
||||
background-color: <color:code/snippet/background>;
|
||||
border-top: 2px solid <color:code/file/background>;
|
||||
|
||||
@@ -1,3 +1,7 @@
|
||||
QGraphicsView, QGraphicsScene {
|
||||
background-color: <color:graph/background>;
|
||||
}
|
||||
|
||||
QToolTip {
|
||||
background-color: <color:tool_tip/background>;
|
||||
color: <color:tool_tip/text>;
|
||||
|
||||
@@ -1,11 +1,14 @@
|
||||
#include "qt/element/QtCodeFile.h"
|
||||
|
||||
#include <QLabel>
|
||||
#include <QPushButton>
|
||||
#include <QVBoxLayout>
|
||||
|
||||
#include "utility/messaging/type/MessageActivateFile.h"
|
||||
#include "utility/messaging/type/MessageShowFile.h"
|
||||
#include "utility/messaging/type/MessageShowSnippets.h"
|
||||
|
||||
#include "data/location/TokenLocation.h"
|
||||
#include "data/location/TokenLocationFile.h"
|
||||
#include "qt/element/QtCodeFileList.h"
|
||||
#include "qt/element/QtCodeSnippet.h"
|
||||
@@ -25,7 +28,7 @@ QtCodeFile::QtCodeFile(const FilePath& filePath, QtCodeFileList* parent)
|
||||
layout->setAlignment(Qt::AlignTop);
|
||||
setLayout(layout);
|
||||
|
||||
QFrame* titleWidget = new QFrame(this);
|
||||
QPushButton* titleWidget = new QPushButton(this);
|
||||
titleWidget->setObjectName("title_widget");
|
||||
layout->addWidget(titleWidget);
|
||||
|
||||
@@ -53,6 +56,11 @@ QtCodeFile::QtCodeFile(const FilePath& filePath, QtCodeFileList* parent)
|
||||
|
||||
titleWidget->setMinimumHeight(m_title->height() + 4);
|
||||
|
||||
m_referenceCount = new QLabel(this);
|
||||
m_referenceCount->setObjectName("references_label");
|
||||
m_referenceCount->hide();
|
||||
titleLayout->addWidget(m_referenceCount);
|
||||
|
||||
titleLayout->addStretch(3);
|
||||
|
||||
m_minimizeButton = new QPushButton(this);
|
||||
@@ -77,6 +85,7 @@ QtCodeFile::QtCodeFile(const FilePath& filePath, QtCodeFileList* parent)
|
||||
m_snippetButton->setEnabled(false);
|
||||
m_maximizeButton->setEnabled(false);
|
||||
|
||||
connect(titleWidget, SIGNAL(clicked()), this, SLOT(clickedTitleBar()));
|
||||
connect(m_title, SIGNAL(clicked()), this, SLOT(clickedTitle()));
|
||||
connect(m_minimizeButton, SIGNAL(clicked()), this, SLOT(clickedMinimizeButton()));
|
||||
connect(m_snippetButton, SIGNAL(clicked()), this, SLOT(clickedSnippetButton()));
|
||||
@@ -126,8 +135,11 @@ void QtCodeFile::addCodeSnippet(
|
||||
const std::string& title,
|
||||
Id titleId,
|
||||
const std::string& code,
|
||||
std::shared_ptr<TokenLocationFile> locationFile
|
||||
std::shared_ptr<TokenLocationFile> locationFile,
|
||||
uint refCount
|
||||
){
|
||||
m_locationFile.reset();
|
||||
|
||||
std::shared_ptr<QtCodeSnippet> snippet(
|
||||
new QtCodeSnippet(startLineNumber, title, titleId, code, locationFile, this));
|
||||
|
||||
@@ -137,14 +149,18 @@ void QtCodeFile::addCodeSnippet(
|
||||
{
|
||||
snippet->setProperty("isFirst", true);
|
||||
snippet->setProperty("isLast", true);
|
||||
|
||||
m_fileSnippet = snippet;
|
||||
|
||||
clickedMaximizeButton();
|
||||
updateRefCount(0);
|
||||
return;
|
||||
}
|
||||
|
||||
m_snippets.push_back(snippet);
|
||||
|
||||
updateSnippets();
|
||||
updateRefCount(refCount);
|
||||
}
|
||||
|
||||
QWidget* QtCodeFile::insertCodeSnippet(
|
||||
@@ -152,8 +168,11 @@ QWidget* QtCodeFile::insertCodeSnippet(
|
||||
const std::string& title,
|
||||
Id titleId,
|
||||
const std::string& code,
|
||||
std::shared_ptr<TokenLocationFile> locationFile
|
||||
std::shared_ptr<TokenLocationFile> locationFile,
|
||||
uint refCount
|
||||
){
|
||||
m_locationFile.reset();
|
||||
|
||||
std::shared_ptr<QtCodeSnippet> snippet(
|
||||
new QtCodeSnippet(startLineNumber, title, titleId, code, locationFile, this));
|
||||
|
||||
@@ -189,12 +208,18 @@ QWidget* QtCodeFile::insertCodeSnippet(
|
||||
m_snippets.insert(m_snippets.begin() + i, snippet);
|
||||
|
||||
updateSnippets();
|
||||
updateRefCount(refCount);
|
||||
|
||||
return snippet.get();
|
||||
}
|
||||
|
||||
QWidget* QtCodeFile::findFirstActiveSnippet() const
|
||||
{
|
||||
if (m_locationFile)
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
for (std::shared_ptr<QtCodeSnippet> snippet : m_snippets)
|
||||
{
|
||||
if (snippet->isActive())
|
||||
@@ -206,6 +231,33 @@ QWidget* QtCodeFile::findFirstActiveSnippet() const
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
bool QtCodeFile::openCollapsedActiveSnippet() const
|
||||
{
|
||||
if (m_locationFile)
|
||||
{
|
||||
std::vector<Id> ids = getActiveTokenIds();
|
||||
|
||||
bool isActiveFile = false;
|
||||
m_locationFile->forEachTokenLocation(
|
||||
[&](TokenLocation* location)
|
||||
{
|
||||
if (std::find(ids.begin(), ids.end(), location->getTokenId()) != ids.end())
|
||||
{
|
||||
isActiveFile = true;
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
if (isActiveFile)
|
||||
{
|
||||
MessageShowSnippets(m_locationFile).dispatch();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void QtCodeFile::updateContent()
|
||||
{
|
||||
for (std::shared_ptr<QtCodeSnippet> snippet : m_snippets)
|
||||
@@ -219,6 +271,30 @@ void QtCodeFile::updateContent()
|
||||
}
|
||||
}
|
||||
|
||||
void QtCodeFile::setLocationFile(std::shared_ptr<TokenLocationFile> locationFile, uint refCount)
|
||||
{
|
||||
m_locationFile = locationFile;
|
||||
clickedMinimizeButton();
|
||||
|
||||
updateRefCount(refCount);
|
||||
}
|
||||
|
||||
void QtCodeFile::clickedTitleBar()
|
||||
{
|
||||
if (m_minimizeButton->isEnabled())
|
||||
{
|
||||
clickedMinimizeButton();
|
||||
}
|
||||
else if (m_snippetButton->isEnabled())
|
||||
{
|
||||
clickedSnippetButton();
|
||||
}
|
||||
else
|
||||
{
|
||||
clickedMaximizeButton();
|
||||
}
|
||||
}
|
||||
|
||||
void QtCodeFile::clickedTitle()
|
||||
{
|
||||
MessageActivateFile(m_filePath).dispatch();
|
||||
@@ -237,7 +313,7 @@ void QtCodeFile::clickedMinimizeButton()
|
||||
}
|
||||
|
||||
m_minimizeButton->setEnabled(false);
|
||||
if (m_snippets.size())
|
||||
if (m_snippets.size() || m_locationFile)
|
||||
{
|
||||
m_snippetButton->setEnabled(true);
|
||||
}
|
||||
@@ -248,6 +324,12 @@ void QtCodeFile::clickedMinimizeButton()
|
||||
|
||||
void QtCodeFile::clickedSnippetButton()
|
||||
{
|
||||
if (m_locationFile)
|
||||
{
|
||||
MessageShowSnippets(m_locationFile).dispatch();
|
||||
return;
|
||||
}
|
||||
|
||||
for (std::shared_ptr<QtCodeSnippet> snippet : m_snippets)
|
||||
{
|
||||
snippet->show();
|
||||
@@ -312,3 +394,16 @@ void QtCodeFile::updateSnippets()
|
||||
|
||||
clickedSnippetButton();
|
||||
}
|
||||
|
||||
void QtCodeFile::updateRefCount(uint refCount)
|
||||
{
|
||||
if (refCount > 0)
|
||||
{
|
||||
m_referenceCount->setText(QString::fromStdString(std::to_string(refCount) + (refCount == 1 ? " reference" : " references")));
|
||||
m_referenceCount->show();
|
||||
}
|
||||
else
|
||||
{
|
||||
m_referenceCount->hide();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
#include "utility/file/FilePath.h"
|
||||
#include "utility/types.h"
|
||||
|
||||
class QLabel;
|
||||
class QPushButton;
|
||||
class QtCodeFileList;
|
||||
class QtCodeSnippet;
|
||||
@@ -36,7 +37,8 @@ public:
|
||||
const std::string& title,
|
||||
Id titleId,
|
||||
const std::string& code,
|
||||
std::shared_ptr<TokenLocationFile> locationFile
|
||||
std::shared_ptr<TokenLocationFile> locationFile,
|
||||
uint refCount
|
||||
);
|
||||
|
||||
QWidget* insertCodeSnippet(
|
||||
@@ -44,27 +46,35 @@ public:
|
||||
const std::string& title,
|
||||
Id titleId,
|
||||
const std::string& code,
|
||||
std::shared_ptr<TokenLocationFile> locationFile
|
||||
std::shared_ptr<TokenLocationFile> locationFile,
|
||||
uint refCount
|
||||
);
|
||||
|
||||
QWidget* findFirstActiveSnippet() const;
|
||||
bool openCollapsedActiveSnippet() const;
|
||||
|
||||
void updateContent();
|
||||
|
||||
void setLocationFile(std::shared_ptr<TokenLocationFile> locationFile, uint refCount);
|
||||
|
||||
public slots:
|
||||
void clickedSnippetButton();
|
||||
|
||||
private slots:
|
||||
void clickedTitleBar();
|
||||
void clickedTitle();
|
||||
void clickedMinimizeButton();
|
||||
void clickedMaximizeButton();
|
||||
|
||||
private:
|
||||
void updateSnippets();
|
||||
void updateRefCount(uint refCount);
|
||||
|
||||
QtCodeFileList* m_parent;
|
||||
|
||||
QPushButton* m_title;
|
||||
QLabel* m_referenceCount;
|
||||
|
||||
QPushButton* m_minimizeButton;
|
||||
QPushButton* m_snippetButton;
|
||||
QPushButton* m_maximizeButton;
|
||||
@@ -75,6 +85,7 @@ private:
|
||||
QWidget* m_minimizePlaceholder;
|
||||
|
||||
const FilePath m_filePath;
|
||||
std::shared_ptr<TokenLocationFile> m_locationFile;
|
||||
};
|
||||
|
||||
#endif // QT_CODE_FILE_H
|
||||
|
||||
@@ -46,40 +46,28 @@ void QtCodeFileList::addCodeSnippet(
|
||||
Id titleId,
|
||||
const std::string& code,
|
||||
std::shared_ptr<TokenLocationFile> locationFile,
|
||||
uint refCount,
|
||||
bool insert
|
||||
){
|
||||
FilePath filePath = locationFile->getFilePath();
|
||||
QtCodeFile* file = nullptr;
|
||||
|
||||
for (std::shared_ptr<QtCodeFile> filePtr : m_files)
|
||||
{
|
||||
if (filePtr->getFilePath() == filePath)
|
||||
{
|
||||
file = filePtr.get();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!file)
|
||||
{
|
||||
std::shared_ptr<QtCodeFile> filePtr = std::make_shared<QtCodeFile>(locationFile->getFilePath(), this);
|
||||
m_files.push_back(filePtr);
|
||||
|
||||
file = filePtr.get();
|
||||
m_frame->layout()->addWidget(file);
|
||||
}
|
||||
QtCodeFile* file = getFile(locationFile);
|
||||
|
||||
if (insert)
|
||||
{
|
||||
QWidget* snippet = file->insertCodeSnippet(startLineNumber, title, titleId, code, locationFile);
|
||||
QWidget* snippet = file->insertCodeSnippet(startLineNumber, title, titleId, code, locationFile, refCount);
|
||||
emit shouldScrollToSnippet(snippet);
|
||||
}
|
||||
else
|
||||
{
|
||||
file->addCodeSnippet(startLineNumber, title, titleId, code, locationFile);
|
||||
file->addCodeSnippet(startLineNumber, title, titleId, code, locationFile, refCount);
|
||||
}
|
||||
}
|
||||
|
||||
void QtCodeFileList::addFile(std::shared_ptr<TokenLocationFile> locationFile, uint refCount)
|
||||
{
|
||||
QtCodeFile* file = getFile(locationFile);
|
||||
file->setLocationFile(locationFile, refCount);
|
||||
}
|
||||
|
||||
void QtCodeFileList::clearCodeSnippets()
|
||||
{
|
||||
m_files.clear();
|
||||
@@ -111,7 +99,7 @@ void QtCodeFileList::setErrorMessages(const std::vector<std::string>& errorMessa
|
||||
m_errorMessages = errorMessages;
|
||||
}
|
||||
|
||||
void QtCodeFileList::scrollToFirstActiveSnippet()
|
||||
bool QtCodeFileList::scrollToFirstActiveSnippet()
|
||||
{
|
||||
updateFiles();
|
||||
|
||||
@@ -127,6 +115,19 @@ void QtCodeFileList::scrollToFirstActiveSnippet()
|
||||
}
|
||||
|
||||
emit shouldScrollToSnippet(widget);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void QtCodeFileList::expandActiveSnippetFile()
|
||||
{
|
||||
for (std::shared_ptr<QtCodeFile> file: m_files)
|
||||
{
|
||||
if (file->openCollapsedActiveSnippet())
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -149,6 +150,32 @@ void QtCodeFileList::scrollToSnippet(QWidget* widget)
|
||||
this->ensureWidgetVisibleAnimated(widget);
|
||||
}
|
||||
|
||||
QtCodeFile* QtCodeFileList::getFile(std::shared_ptr<TokenLocationFile> locationFile)
|
||||
{
|
||||
FilePath filePath = locationFile->getFilePath();
|
||||
QtCodeFile* file = nullptr;
|
||||
|
||||
for (std::shared_ptr<QtCodeFile> filePtr : m_files)
|
||||
{
|
||||
if (filePtr->getFilePath() == filePath)
|
||||
{
|
||||
file = filePtr.get();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!file)
|
||||
{
|
||||
std::shared_ptr<QtCodeFile> filePtr = std::make_shared<QtCodeFile>(locationFile->getFilePath(), this);
|
||||
m_files.push_back(filePtr);
|
||||
|
||||
file = filePtr.get();
|
||||
m_frame->layout()->addWidget(file);
|
||||
}
|
||||
|
||||
return file;
|
||||
}
|
||||
|
||||
void QtCodeFileList::updateFiles()
|
||||
{
|
||||
for (std::shared_ptr<QtCodeFile> file: m_files)
|
||||
@@ -216,10 +243,10 @@ void QtCodeFileList::ensureWidgetVisibleAnimated(QWidget *childWidget, int xmarg
|
||||
if (scrollBar)
|
||||
{
|
||||
QPropertyAnimation* anim = new QPropertyAnimation(scrollBar, "value");
|
||||
anim->setDuration(std::abs(scrollBar->value() - value));
|
||||
anim->setDuration(500);
|
||||
anim->setStartValue(scrollBar->value());
|
||||
anim->setEndValue(value);
|
||||
anim->setEasingCurve(QEasingCurve::OutQuad);
|
||||
anim->setEasingCurve(QEasingCurve::InOutQuad);
|
||||
anim->start();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -32,9 +32,12 @@ public:
|
||||
Id titleId,
|
||||
const std::string& code,
|
||||
std::shared_ptr<TokenLocationFile> locationFile,
|
||||
uint refCount,
|
||||
bool insert = false
|
||||
);
|
||||
|
||||
void addFile(std::shared_ptr<TokenLocationFile> locationFile, uint refCount);
|
||||
|
||||
void clearCodeSnippets();
|
||||
|
||||
Id getFocusedTokenId() const;
|
||||
@@ -45,7 +48,8 @@ public:
|
||||
const std::vector<std::string>& getErrorMessages() const;
|
||||
void setErrorMessages(const std::vector<std::string>& errorMessages);
|
||||
|
||||
void scrollToFirstActiveSnippet();
|
||||
bool scrollToFirstActiveSnippet();
|
||||
void expandActiveSnippetFile();
|
||||
|
||||
void focusToken(Id tokenId);
|
||||
void defocusToken();
|
||||
@@ -54,6 +58,8 @@ private slots:
|
||||
void scrollToSnippet(QWidget* widget);
|
||||
|
||||
private:
|
||||
QtCodeFile* getFile(std::shared_ptr<TokenLocationFile> locationFile);
|
||||
|
||||
void updateFiles();
|
||||
|
||||
void ensureWidgetVisibleAnimated(QWidget *childWidget, int xmargin = 50, int ymargin = 50);
|
||||
|
||||
@@ -90,6 +90,10 @@ namespace utility
|
||||
{
|
||||
val = std::to_string(ApplicationSettings::getInstance()->getFontSize() + 2);
|
||||
}
|
||||
else if (val == "font_size-2")
|
||||
{
|
||||
val = std::to_string(ApplicationSettings::getInstance()->getFontSize() - 2);
|
||||
}
|
||||
else if (val == "font_name")
|
||||
{
|
||||
val = ApplicationSettings::getInstance()->getFontName();
|
||||
|
||||
@@ -11,9 +11,9 @@ QtCodeView::QtCodeView(ViewLayout* viewLayout)
|
||||
: CodeView(viewLayout)
|
||||
, m_refreshViewFunctor(std::bind(&QtCodeView::doRefreshView, this))
|
||||
, m_showCodeSnippetsFunctor(std::bind(&QtCodeView::doShowCodeSnippets, this, std::placeholders::_1))
|
||||
, m_addCodeSnippetFunctor(std::bind(&QtCodeView::doAddCodeSnippet, this, std::placeholders::_1))
|
||||
, m_addCodeSnippetsFunctor(std::bind(&QtCodeView::doAddCodeSnippets, this, std::placeholders::_1))
|
||||
, m_showCodeFileFunctor(std::bind(&QtCodeView::doShowCodeFile, this, std::placeholders::_1))
|
||||
, m_doScrollToFirstActiveSnippetFunctor(std::bind(&QtCodeView::doScrollToFirstActiveSnippet, this))
|
||||
, m_doShowFirstActiveSnippetFunctor(std::bind(&QtCodeView::doShowFirstActiveSnippet, this))
|
||||
, m_focusTokenFunctor(std::bind(&QtCodeView::doFocusToken, this, std::placeholders::_1))
|
||||
, m_defocusTokenFunctor(std::bind(&QtCodeView::doDefocusToken, this))
|
||||
{
|
||||
@@ -54,9 +54,9 @@ void QtCodeView::showCodeSnippets(const std::vector<CodeSnippetParams>& snippets
|
||||
m_showCodeSnippetsFunctor(snippets);
|
||||
}
|
||||
|
||||
void QtCodeView::addCodeSnippet(const CodeSnippetParams& snippet)
|
||||
void QtCodeView::addCodeSnippets(const std::vector<CodeSnippetParams>& snippets)
|
||||
{
|
||||
m_addCodeSnippetFunctor(snippet);
|
||||
m_addCodeSnippetsFunctor(snippets);
|
||||
}
|
||||
|
||||
void QtCodeView::showCodeFile(const CodeSnippetParams& params)
|
||||
@@ -64,9 +64,9 @@ void QtCodeView::showCodeFile(const CodeSnippetParams& params)
|
||||
m_showCodeFileFunctor(params);
|
||||
}
|
||||
|
||||
void QtCodeView::scrollToFirstActiveSnippet()
|
||||
void QtCodeView::showFirstActiveSnippet()
|
||||
{
|
||||
m_doScrollToFirstActiveSnippetFunctor();
|
||||
m_doShowFirstActiveSnippetFunctor();
|
||||
}
|
||||
|
||||
void QtCodeView::focusToken(const Id tokenId)
|
||||
@@ -94,28 +94,57 @@ void QtCodeView::doShowCodeSnippets(const std::vector<CodeSnippetParams>& snippe
|
||||
|
||||
for (const CodeSnippetParams& params : snippets)
|
||||
{
|
||||
m_widget->addCodeSnippet(params.startLineNumber, params.title, params.titleId, params.code, params.locationFile);
|
||||
if (params.isCollapsed)
|
||||
{
|
||||
m_widget->addFile(params.locationFile, params.refCount);
|
||||
}
|
||||
else
|
||||
{
|
||||
m_widget->addCodeSnippet(
|
||||
params.startLineNumber,
|
||||
params.title,
|
||||
params.titleId,
|
||||
params.code,
|
||||
params.locationFile,
|
||||
params.refCount
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
setStyleSheet(); // so property "isLast" of QtCodeSnippet is computed correctly
|
||||
}
|
||||
|
||||
void QtCodeView::doAddCodeSnippet(const CodeSnippetParams& snippet)
|
||||
void QtCodeView::doAddCodeSnippets(const std::vector<CodeSnippetParams>& snippets)
|
||||
{
|
||||
m_widget->addCodeSnippet(snippet.startLineNumber, snippet.title, snippet.titleId, snippet.code, snippet.locationFile, true);
|
||||
for (const CodeSnippetParams& snippet : snippets)
|
||||
{
|
||||
m_widget->addCodeSnippet(
|
||||
snippet.startLineNumber,
|
||||
snippet.title,
|
||||
snippet.titleId,
|
||||
snippet.code,
|
||||
snippet.locationFile,
|
||||
snippet.refCount,
|
||||
true
|
||||
);
|
||||
}
|
||||
|
||||
setStyleSheet(); // so property "isLast" of QtCodeSnippet is computed correctly
|
||||
}
|
||||
|
||||
void QtCodeView::doShowCodeFile(const CodeSnippetParams& params)
|
||||
{
|
||||
m_widget->addCodeSnippet(1, params.title, 0, params.code, params.locationFile);
|
||||
m_widget->addCodeSnippet(1, params.title, 0, params.code, params.locationFile, params.refCount);
|
||||
}
|
||||
|
||||
void QtCodeView::doScrollToFirstActiveSnippet()
|
||||
void QtCodeView::doShowFirstActiveSnippet()
|
||||
{
|
||||
m_widget->setActiveTokenIds(m_activeTokenIds);
|
||||
m_widget->scrollToFirstActiveSnippet();
|
||||
|
||||
if (!m_widget->scrollToFirstActiveSnippet())
|
||||
{
|
||||
m_widget->expandActiveSnippetFile();
|
||||
}
|
||||
}
|
||||
|
||||
void QtCodeView::doFocusToken(const Id tokenId)
|
||||
|
||||
@@ -30,10 +30,10 @@ public:
|
||||
virtual void setErrorMessages(const std::vector<std::string>& errorMessages);
|
||||
|
||||
virtual void showCodeSnippets(const std::vector<CodeSnippetParams>& snippets);
|
||||
virtual void addCodeSnippet(const CodeSnippetParams& snippet);
|
||||
virtual void addCodeSnippets(const std::vector<CodeSnippetParams>& snippets);
|
||||
virtual void showCodeFile(const CodeSnippetParams& params);
|
||||
|
||||
virtual void scrollToFirstActiveSnippet();
|
||||
virtual void showFirstActiveSnippet();
|
||||
|
||||
virtual void focusToken(const Id tokenId);
|
||||
virtual void defocusToken();
|
||||
@@ -42,10 +42,10 @@ private:
|
||||
void doRefreshView();
|
||||
|
||||
void doShowCodeSnippets(const std::vector<CodeSnippetParams>& snippets);
|
||||
void doAddCodeSnippet(const CodeSnippetParams& snippet);
|
||||
void doAddCodeSnippets(const std::vector<CodeSnippetParams>& snippets);
|
||||
void doShowCodeFile(const CodeSnippetParams& params);
|
||||
|
||||
void doScrollToFirstActiveSnippet();
|
||||
void doShowFirstActiveSnippet();
|
||||
|
||||
void doFocusToken(const Id tokenId);
|
||||
void doDefocusToken();
|
||||
@@ -54,9 +54,9 @@ private:
|
||||
|
||||
QtThreadedFunctor<> m_refreshViewFunctor;
|
||||
QtThreadedFunctor<const std::vector<CodeSnippetParams>&> m_showCodeSnippetsFunctor;
|
||||
QtThreadedFunctor<const CodeSnippetParams&> m_addCodeSnippetFunctor;
|
||||
QtThreadedFunctor<const std::vector<CodeSnippetParams>&> m_addCodeSnippetsFunctor;
|
||||
QtThreadedFunctor<const CodeSnippetParams&> m_showCodeFileFunctor;
|
||||
QtThreadedFunctor<> m_doScrollToFirstActiveSnippetFunctor;
|
||||
QtThreadedFunctor<> m_doShowFirstActiveSnippetFunctor;
|
||||
QtThreadedFunctor<const Id&> m_focusTokenFunctor;
|
||||
QtThreadedFunctor<> m_defocusTokenFunctor;
|
||||
|
||||
|
||||
@@ -242,11 +242,6 @@ void QtGraphView::doRefreshView()
|
||||
doClear();
|
||||
doResize();
|
||||
|
||||
std::string backgroundColor = ColorScheme::getInstance()->getColor("graph/background");
|
||||
|
||||
utility::setWidgetBackgroundColor(QtViewWidgetWrapper::getWidgetOfView(this), backgroundColor);
|
||||
utility::setWidgetBackgroundColor(getView(), backgroundColor);
|
||||
|
||||
std::string css = utility::getStyleSheet("data/gui/graph_view/graph_view.css");
|
||||
getView()->setStyleSheet(css.c_str());
|
||||
}
|
||||
|
||||
@@ -254,6 +254,7 @@ add_files(
|
||||
utility/messaging/type/MessageSearchAutocomplete.h
|
||||
utility/messaging/type/MessageShowFile.h
|
||||
utility/messaging/type/MessageShowScope.h
|
||||
utility/messaging/type/MessageShowSnippets.h
|
||||
utility/messaging/type/MessageStatus.h
|
||||
utility/messaging/type/MessageSwitchColorScheme.h
|
||||
utility/messaging/type/MessageUndo.h
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
|
||||
#include "utility/messaging/type/MessageStatus.h"
|
||||
#include "utility/text/TextAccess.h"
|
||||
#include "utility/utility.h"
|
||||
|
||||
#include "data/access/StorageAccess.h"
|
||||
#include "data/location/TokenLocation.h"
|
||||
@@ -45,7 +46,7 @@ void CodeController::handleMessage(MessageActivateTokens* message)
|
||||
|
||||
if (message->isEdge)
|
||||
{
|
||||
view->scrollToFirstActiveSnippet();
|
||||
view->showFirstActiveSnippet();
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -141,7 +142,12 @@ void CodeController::handleMessage(MessageShowScope* message)
|
||||
return;
|
||||
}
|
||||
|
||||
getView()->addCodeSnippet(snippets[0]);
|
||||
getView()->addCodeSnippets(snippets);
|
||||
}
|
||||
|
||||
void CodeController::handleMessage(MessageShowSnippets* message)
|
||||
{
|
||||
getView()->addCodeSnippets(getSnippetsForActiveTokenLocationsInFile(message->locationFile));
|
||||
}
|
||||
|
||||
CodeView* CodeController::getView()
|
||||
@@ -157,40 +163,37 @@ std::vector<CodeView::CodeSnippetParams> CodeController::getSnippetsForActiveTok
|
||||
collection->forEachTokenLocationFile(
|
||||
[&](std::shared_ptr<TokenLocationFile> file) -> void
|
||||
{
|
||||
std::vector<CodeView::CodeSnippetParams> fileSnippets = getSnippetsForFile(file);
|
||||
|
||||
if (!file->isWholeCopy)
|
||||
{
|
||||
for (CodeView::CodeSnippetParams& params : fileSnippets)
|
||||
bool isDeclarationFile = false;
|
||||
file->forEachTokenLocation(
|
||||
[&](TokenLocation* location)
|
||||
{
|
||||
params.locationFile = m_storageAccess->getTokenLocationsForLinesInFile(
|
||||
file->getFilePath().str(), params.startLineNumber, params.endLineNumber);
|
||||
if (location->getTokenId() == declarationId)
|
||||
{
|
||||
isDeclarationFile = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
if (declarationId != 0)
|
||||
if (isDeclarationFile || collection->getTokenLocationFileCount() < 5)
|
||||
{
|
||||
bool isDeclarationFile = false;
|
||||
for (const CodeView::CodeSnippetParams& snippet : fileSnippets)
|
||||
{
|
||||
snippet.locationFile->forEachTokenLocation(
|
||||
[&](TokenLocation* location)
|
||||
{
|
||||
if (location->getTokenId() == declarationId)
|
||||
{
|
||||
isDeclarationFile = true;
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
std::vector<CodeView::CodeSnippetParams> fileSnippets = getSnippetsForActiveTokenLocationsInFile(file);
|
||||
|
||||
for (CodeView::CodeSnippetParams& snippet : fileSnippets)
|
||||
{
|
||||
snippet.isDeclaration = isDeclarationFile;
|
||||
}
|
||||
}
|
||||
|
||||
snippets.insert(snippets.end(), fileSnippets.begin(), fileSnippets.end());
|
||||
utility::append(snippets, fileSnippets);
|
||||
}
|
||||
else
|
||||
{
|
||||
CodeView::CodeSnippetParams params;
|
||||
params.locationFile = file;
|
||||
params.refCount = file->getUnscopedStartTokenLocationCount();
|
||||
|
||||
params.isCollapsed = true;
|
||||
snippets.push_back(params);
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
@@ -199,6 +202,23 @@ std::vector<CodeView::CodeSnippetParams> CodeController::getSnippetsForActiveTok
|
||||
return snippets;
|
||||
}
|
||||
|
||||
std::vector<CodeView::CodeSnippetParams> CodeController::getSnippetsForActiveTokenLocationsInFile(
|
||||
std::shared_ptr<TokenLocationFile> file
|
||||
) const {
|
||||
std::vector<CodeView::CodeSnippetParams> fileSnippets = getSnippetsForFile(file);
|
||||
|
||||
if (!file->isWholeCopy)
|
||||
{
|
||||
for (CodeView::CodeSnippetParams& params : fileSnippets)
|
||||
{
|
||||
params.locationFile = m_storageAccess->getTokenLocationsForLinesInFile(
|
||||
file->getFilePath().str(), params.startLineNumber, params.endLineNumber);
|
||||
}
|
||||
}
|
||||
|
||||
return fileSnippets;
|
||||
}
|
||||
|
||||
std::vector<CodeView::CodeSnippetParams> CodeController::getSnippetsForFile(std::shared_ptr<TokenLocationFile> file) const
|
||||
{
|
||||
std::shared_ptr<TextAccess> textAccess = TextAccess::createFromFile(file->getFilePath().str());
|
||||
@@ -232,6 +252,7 @@ std::vector<CodeView::CodeSnippetParams> CodeController::getSnippetsForFile(std:
|
||||
{
|
||||
CodeView::CodeSnippetParams params;
|
||||
params.locationFile = file;
|
||||
params.refCount = file->getUnscopedStartTokenLocationCount();
|
||||
params.startLineNumber = std::max<int>(1, range.start.row - (range.start.strong ? 0 : snippetExpandRange));
|
||||
params.endLineNumber = std::min<int>(textAccess->getLineCount(), range.end.row + (range.end.strong ? 0 : snippetExpandRange));
|
||||
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
#include "utility/messaging/type/MessageFocusOut.h"
|
||||
#include "utility/messaging/type/MessageShowFile.h"
|
||||
#include "utility/messaging/type/MessageShowScope.h"
|
||||
#include "utility/messaging/type/MessageShowSnippets.h"
|
||||
#include "utility/types.h"
|
||||
|
||||
#include "component/controller/helper/SnippetMerger.h"
|
||||
@@ -29,6 +30,7 @@ class CodeController
|
||||
, public MessageListener<MessageFocusOut>
|
||||
, public MessageListener<MessageShowFile>
|
||||
, public MessageListener<MessageShowScope>
|
||||
, public MessageListener<MessageShowSnippets>
|
||||
{
|
||||
public:
|
||||
CodeController(StorageAccess* storageAccess);
|
||||
@@ -43,11 +45,14 @@ private:
|
||||
virtual void handleMessage(MessageFocusOut* message);
|
||||
virtual void handleMessage(MessageShowFile* message);
|
||||
virtual void handleMessage(MessageShowScope* message);
|
||||
virtual void handleMessage(MessageShowSnippets* message);
|
||||
|
||||
CodeView* getView();
|
||||
|
||||
std::vector<CodeView::CodeSnippetParams> getSnippetsForActiveTokenLocations(
|
||||
const TokenLocationCollection* collection, Id declarationId) const;
|
||||
std::vector<CodeView::CodeSnippetParams> getSnippetsForActiveTokenLocationsInFile(
|
||||
std::shared_ptr<TokenLocationFile>) const;
|
||||
std::vector<CodeView::CodeSnippetParams> getSnippetsForFile(std::shared_ptr<TokenLocationFile> file) const;
|
||||
std::shared_ptr<SnippetMerger> buildMergerHierarchy(
|
||||
TokenLocation* location, SnippetMerger& fileScopedMerger, std::map<int, std::shared_ptr<SnippetMerger>>& mergers) const;
|
||||
|
||||
@@ -7,9 +7,11 @@ CodeView::CodeSnippetParams::CodeSnippetParams()
|
||||
: startLineNumber(0)
|
||||
, endLineNumber(0)
|
||||
, titleId(0)
|
||||
, locationFile(std::make_shared<TokenLocationFile>(""))
|
||||
, locationFile()
|
||||
, refCount(0)
|
||||
, isActive(false)
|
||||
, isDeclaration(false)
|
||||
, isCollapsed(false)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -59,7 +61,7 @@ bool CodeView::CodeSnippetParams::sort(const CodeSnippetParams& a, const CodeSni
|
||||
// alphabetical filepath without extension
|
||||
else
|
||||
{
|
||||
return aFilePath.withoutExtension() < bFilePath.withoutExtension();
|
||||
return aFilePath.withoutExtension().fileName() < bFilePath.withoutExtension().fileName();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -29,8 +29,11 @@ public:
|
||||
|
||||
std::shared_ptr<TokenLocationFile> locationFile;
|
||||
|
||||
uint refCount;
|
||||
|
||||
bool isActive;
|
||||
bool isDeclaration;
|
||||
bool isCollapsed;
|
||||
};
|
||||
|
||||
CodeView(ViewLayout* viewLayout);
|
||||
@@ -42,10 +45,10 @@ public:
|
||||
virtual void setErrorMessages(const std::vector<std::string>& errorMessages) = 0;
|
||||
|
||||
virtual void showCodeSnippets(const std::vector<CodeSnippetParams>& snippets) = 0;
|
||||
virtual void addCodeSnippet(const CodeSnippetParams& snippet) = 0;
|
||||
virtual void addCodeSnippets(const std::vector<CodeSnippetParams>& snippets) = 0;
|
||||
virtual void showCodeFile(const CodeSnippetParams& params) = 0;
|
||||
|
||||
virtual void scrollToFirstActiveSnippet() = 0;
|
||||
virtual void showFirstActiveSnippet() = 0;
|
||||
|
||||
virtual void focusToken(const Id tokenId) = 0;
|
||||
virtual void defocusToken() = 0;
|
||||
|
||||
@@ -25,6 +25,24 @@ size_t TokenLocationFile::getTokenLocationLineCount() const
|
||||
return m_lines.size();
|
||||
}
|
||||
|
||||
size_t TokenLocationFile::getUnscopedStartTokenLocationCount() const
|
||||
{
|
||||
size_t count = 0;
|
||||
for (const TokenLocationLinePairType& line : m_lines)
|
||||
{
|
||||
line.second->forEachStartTokenLocation(
|
||||
[&count](TokenLocation* location)
|
||||
{
|
||||
if (!location->isScopeTokenLocation())
|
||||
{
|
||||
count++;
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
const FilePath& TokenLocationFile::getFilePath() const
|
||||
{
|
||||
return m_filePath;
|
||||
|
||||
@@ -24,6 +24,7 @@ public:
|
||||
|
||||
const TokenLocationLineMapType& getTokenLocationLines() const;
|
||||
size_t getTokenLocationLineCount() const;
|
||||
size_t getUnscopedStartTokenLocationCount() const;
|
||||
|
||||
const FilePath& getFilePath() const;
|
||||
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
#ifndef MESSAGE_SHOW_SNIPPETS_H
|
||||
#define MESSAGE_SHOW_SNIPPETS_H
|
||||
|
||||
#include "utility/messaging/Message.h"
|
||||
#include "utility/types.h"
|
||||
|
||||
class TokenLocationFile;
|
||||
|
||||
class MessageShowSnippets
|
||||
: public Message<MessageShowSnippets>
|
||||
{
|
||||
public:
|
||||
MessageShowSnippets(std::shared_ptr<TokenLocationFile> locationFile)
|
||||
: locationFile(locationFile)
|
||||
{
|
||||
}
|
||||
|
||||
static const std::string getStaticType()
|
||||
{
|
||||
return "MessageShowSnippets";
|
||||
}
|
||||
|
||||
std::shared_ptr<TokenLocationFile> locationFile;
|
||||
};
|
||||
|
||||
#endif // MESSAGE_SHOW_SNIPPETS_H
|
||||
Reference in New Issue
Block a user