diff --git a/bin/app/data/color_schemes/bright.xml b/bin/app/data/color_schemes/bright.xml index 040d33cd..c01bc606 100644 --- a/bin/app/data/color_schemes/bright.xml +++ b/bin/app/data/color_schemes/bright.xml @@ -54,6 +54,11 @@ #626262 black + + + black + white + diff --git a/bin/app/data/color_schemes/dark.xml b/bin/app/data/color_schemes/dark.xml index 04a2bc55..ebd06370 100644 --- a/bin/app/data/color_schemes/dark.xml +++ b/bin/app/data/color_schemes/dark.xml @@ -54,6 +54,11 @@ #444444 white + + + #F7F7F7 + #272728 + diff --git a/bin/app/data/gui/code_view/code_view.css b/bin/app/data/gui/code_view/code_view.css index 5240c1c0..afbfd254 100644 --- a/bin/app/data/gui/code_view/code_view.css +++ b/bin/app/data/gui/code_view/code_view.css @@ -36,6 +36,16 @@ background-color: ; } +#code_file #references_label { + background-color: ; + border: none; + border-radius: 10px; + color: ; + font-size: pt; + padding: 0px 3px; + margin: 4px 0px 4px; +} + #code_file #code_snippet { background-color: ; border-top: 2px solid ; diff --git a/bin/app/data/gui/graph_view/graph_view.css b/bin/app/data/gui/graph_view/graph_view.css index d9698fbc..1ee653b5 100644 --- a/bin/app/data/gui/graph_view/graph_view.css +++ b/bin/app/data/gui/graph_view/graph_view.css @@ -1,3 +1,7 @@ +QGraphicsView, QGraphicsScene { + background-color: ; +} + QToolTip { background-color: ; color: ; diff --git a/src/app/qt/element/QtCodeFile.cpp b/src/app/qt/element/QtCodeFile.cpp index 683bd79b..2f249f6d 100644 --- a/src/app/qt/element/QtCodeFile.cpp +++ b/src/app/qt/element/QtCodeFile.cpp @@ -1,11 +1,14 @@ #include "qt/element/QtCodeFile.h" +#include #include #include #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 locationFile + std::shared_ptr locationFile, + uint refCount ){ + m_locationFile.reset(); + std::shared_ptr 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 locationFile + std::shared_ptr locationFile, + uint refCount ){ + m_locationFile.reset(); + std::shared_ptr 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 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 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 snippet : m_snippets) @@ -219,6 +271,30 @@ void QtCodeFile::updateContent() } } +void QtCodeFile::setLocationFile(std::shared_ptr 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 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(); + } +} diff --git a/src/app/qt/element/QtCodeFile.h b/src/app/qt/element/QtCodeFile.h index 29eab5ca..94d0f662 100644 --- a/src/app/qt/element/QtCodeFile.h +++ b/src/app/qt/element/QtCodeFile.h @@ -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 locationFile + std::shared_ptr locationFile, + uint refCount ); QWidget* insertCodeSnippet( @@ -44,27 +46,35 @@ public: const std::string& title, Id titleId, const std::string& code, - std::shared_ptr locationFile + std::shared_ptr locationFile, + uint refCount ); QWidget* findFirstActiveSnippet() const; + bool openCollapsedActiveSnippet() const; void updateContent(); + void setLocationFile(std::shared_ptr 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 m_locationFile; }; #endif // QT_CODE_FILE_H diff --git a/src/app/qt/element/QtCodeFileList.cpp b/src/app/qt/element/QtCodeFileList.cpp index e0c4f393..6860d192 100644 --- a/src/app/qt/element/QtCodeFileList.cpp +++ b/src/app/qt/element/QtCodeFileList.cpp @@ -46,40 +46,28 @@ void QtCodeFileList::addCodeSnippet( Id titleId, const std::string& code, std::shared_ptr locationFile, + uint refCount, bool insert ){ - FilePath filePath = locationFile->getFilePath(); - QtCodeFile* file = nullptr; - - for (std::shared_ptr filePtr : m_files) - { - if (filePtr->getFilePath() == filePath) - { - file = filePtr.get(); - break; - } - } - - if (!file) - { - std::shared_ptr filePtr = std::make_shared(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 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& 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 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 locationFile) +{ + FilePath filePath = locationFile->getFilePath(); + QtCodeFile* file = nullptr; + + for (std::shared_ptr filePtr : m_files) + { + if (filePtr->getFilePath() == filePath) + { + file = filePtr.get(); + break; + } + } + + if (!file) + { + std::shared_ptr filePtr = std::make_shared(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 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(); } } diff --git a/src/app/qt/element/QtCodeFileList.h b/src/app/qt/element/QtCodeFileList.h index 090b7b11..586b80bc 100644 --- a/src/app/qt/element/QtCodeFileList.h +++ b/src/app/qt/element/QtCodeFileList.h @@ -32,9 +32,12 @@ public: Id titleId, const std::string& code, std::shared_ptr locationFile, + uint refCount, bool insert = false ); + void addFile(std::shared_ptr locationFile, uint refCount); + void clearCodeSnippets(); Id getFocusedTokenId() const; @@ -45,7 +48,8 @@ public: const std::vector& getErrorMessages() const; void setErrorMessages(const std::vector& 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 locationFile); + void updateFiles(); void ensureWidgetVisibleAnimated(QWidget *childWidget, int xmargin = 50, int ymargin = 50); diff --git a/src/app/qt/utility/utilityQt.cpp b/src/app/qt/utility/utilityQt.cpp index 2ed2305a..af67c26b 100644 --- a/src/app/qt/utility/utilityQt.cpp +++ b/src/app/qt/utility/utilityQt.cpp @@ -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(); diff --git a/src/app/qt/view/QtCodeView.cpp b/src/app/qt/view/QtCodeView.cpp index 5f8d8bbb..719b78c0 100644 --- a/src/app/qt/view/QtCodeView.cpp +++ b/src/app/qt/view/QtCodeView.cpp @@ -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& snippets m_showCodeSnippetsFunctor(snippets); } -void QtCodeView::addCodeSnippet(const CodeSnippetParams& snippet) +void QtCodeView::addCodeSnippets(const std::vector& 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& 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& 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) diff --git a/src/app/qt/view/QtCodeView.h b/src/app/qt/view/QtCodeView.h index f3dfa9c4..d1b5b468 100644 --- a/src/app/qt/view/QtCodeView.h +++ b/src/app/qt/view/QtCodeView.h @@ -30,10 +30,10 @@ public: virtual void setErrorMessages(const std::vector& errorMessages); virtual void showCodeSnippets(const std::vector& snippets); - virtual void addCodeSnippet(const CodeSnippetParams& snippet); + virtual void addCodeSnippets(const std::vector& 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& snippets); - void doAddCodeSnippet(const CodeSnippetParams& snippet); + void doAddCodeSnippets(const std::vector& 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&> m_showCodeSnippetsFunctor; - QtThreadedFunctor m_addCodeSnippetFunctor; + QtThreadedFunctor&> m_addCodeSnippetsFunctor; QtThreadedFunctor m_showCodeFileFunctor; - QtThreadedFunctor<> m_doScrollToFirstActiveSnippetFunctor; + QtThreadedFunctor<> m_doShowFirstActiveSnippetFunctor; QtThreadedFunctor m_focusTokenFunctor; QtThreadedFunctor<> m_defocusTokenFunctor; diff --git a/src/app/qt/view/QtGraphView.cpp b/src/app/qt/view/QtGraphView.cpp index a73974cd..c0336183 100644 --- a/src/app/qt/view/QtGraphView.cpp +++ b/src/app/qt/view/QtGraphView.cpp @@ -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()); } diff --git a/src/lib/CMakeLists.txt b/src/lib/CMakeLists.txt index de372d90..43387777 100644 --- a/src/lib/CMakeLists.txt +++ b/src/lib/CMakeLists.txt @@ -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 diff --git a/src/lib/component/controller/CodeController.cpp b/src/lib/component/controller/CodeController.cpp index 409f5651..ef30137e 100644 --- a/src/lib/component/controller/CodeController.cpp +++ b/src/lib/component/controller/CodeController.cpp @@ -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 CodeController::getSnippetsForActiveTok collection->forEachTokenLocationFile( [&](std::shared_ptr file) -> void { - std::vector 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 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 CodeController::getSnippetsForActiveTok return snippets; } +std::vector CodeController::getSnippetsForActiveTokenLocationsInFile( + std::shared_ptr file +) const { + std::vector 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 CodeController::getSnippetsForFile(std::shared_ptr file) const { std::shared_ptr textAccess = TextAccess::createFromFile(file->getFilePath().str()); @@ -232,6 +252,7 @@ std::vector CodeController::getSnippetsForFile(std: { CodeView::CodeSnippetParams params; params.locationFile = file; + params.refCount = file->getUnscopedStartTokenLocationCount(); params.startLineNumber = std::max(1, range.start.row - (range.start.strong ? 0 : snippetExpandRange)); params.endLineNumber = std::min(textAccess->getLineCount(), range.end.row + (range.end.strong ? 0 : snippetExpandRange)); diff --git a/src/lib/component/controller/CodeController.h b/src/lib/component/controller/CodeController.h index 81ef6165..11256067 100644 --- a/src/lib/component/controller/CodeController.h +++ b/src/lib/component/controller/CodeController.h @@ -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 , public MessageListener , public MessageListener + , public MessageListener { 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 getSnippetsForActiveTokenLocations( const TokenLocationCollection* collection, Id declarationId) const; + std::vector getSnippetsForActiveTokenLocationsInFile( + std::shared_ptr) const; std::vector getSnippetsForFile(std::shared_ptr file) const; std::shared_ptr buildMergerHierarchy( TokenLocation* location, SnippetMerger& fileScopedMerger, std::map>& mergers) const; diff --git a/src/lib/component/view/CodeView.cpp b/src/lib/component/view/CodeView.cpp index 49944f0a..479183d0 100644 --- a/src/lib/component/view/CodeView.cpp +++ b/src/lib/component/view/CodeView.cpp @@ -7,9 +7,11 @@ CodeView::CodeSnippetParams::CodeSnippetParams() : startLineNumber(0) , endLineNumber(0) , titleId(0) - , locationFile(std::make_shared("")) + , 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(); } } diff --git a/src/lib/component/view/CodeView.h b/src/lib/component/view/CodeView.h index f9e0eef5..aa104dee 100644 --- a/src/lib/component/view/CodeView.h +++ b/src/lib/component/view/CodeView.h @@ -29,8 +29,11 @@ public: std::shared_ptr locationFile; + uint refCount; + bool isActive; bool isDeclaration; + bool isCollapsed; }; CodeView(ViewLayout* viewLayout); @@ -42,10 +45,10 @@ public: virtual void setErrorMessages(const std::vector& errorMessages) = 0; virtual void showCodeSnippets(const std::vector& snippets) = 0; - virtual void addCodeSnippet(const CodeSnippetParams& snippet) = 0; + virtual void addCodeSnippets(const std::vector& 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; diff --git a/src/lib/data/location/TokenLocationFile.cpp b/src/lib/data/location/TokenLocationFile.cpp index 2f1a4070..44c5475a 100644 --- a/src/lib/data/location/TokenLocationFile.cpp +++ b/src/lib/data/location/TokenLocationFile.cpp @@ -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; diff --git a/src/lib/data/location/TokenLocationFile.h b/src/lib/data/location/TokenLocationFile.h index 78cd7b33..dbb389aa 100644 --- a/src/lib/data/location/TokenLocationFile.h +++ b/src/lib/data/location/TokenLocationFile.h @@ -24,6 +24,7 @@ public: const TokenLocationLineMapType& getTokenLocationLines() const; size_t getTokenLocationLineCount() const; + size_t getUnscopedStartTokenLocationCount() const; const FilePath& getFilePath() const; diff --git a/src/lib/utility/messaging/type/MessageShowSnippets.h b/src/lib/utility/messaging/type/MessageShowSnippets.h new file mode 100644 index 00000000..be6efc4f --- /dev/null +++ b/src/lib/utility/messaging/type/MessageShowSnippets.h @@ -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 +{ +public: + MessageShowSnippets(std::shared_ptr locationFile) + : locationFile(locationFile) + { + } + + static const std::string getStaticType() + { + return "MessageShowSnippets"; + } + + std::shared_ptr locationFile; +}; + +#endif // MESSAGE_SHOW_SNIPPETS_H