diff --git a/src/lib_gui/qt/element/QtCodeFile.cpp b/src/lib_gui/qt/element/QtCodeFile.cpp index 8610f1ee..558b42c4 100644 --- a/src/lib_gui/qt/element/QtCodeFile.cpp +++ b/src/lib_gui/qt/element/QtCodeFile.cpp @@ -250,10 +250,11 @@ bool QtCodeFile::isCollapsed() const return m_isCollapsed; } -void QtCodeFile::requestContent() const +void QtCodeFile::requestContent() { if (!isCollapsed() || m_contentRequested) { + updateContent(); return; } diff --git a/src/lib_gui/qt/element/QtCodeFile.h b/src/lib_gui/qt/element/QtCodeFile.h index ce73b4ec..4f3a9c17 100644 --- a/src/lib_gui/qt/element/QtCodeFile.h +++ b/src/lib_gui/qt/element/QtCodeFile.h @@ -43,7 +43,7 @@ public: bool isCollapsed() const; - void requestContent() const; + void requestContent(); void updateContent(); void setWholeFile(bool isWholeFile, int refCount); diff --git a/src/lib_gui/qt/element/QtCodeFileSingle.cpp b/src/lib_gui/qt/element/QtCodeFileSingle.cpp index cb62ed65..09176ed3 100644 --- a/src/lib_gui/qt/element/QtCodeFileSingle.cpp +++ b/src/lib_gui/qt/element/QtCodeFileSingle.cpp @@ -237,6 +237,7 @@ void QtCodeFileSingle::setFileData(const FileData& file) if (m_area) { updateRefCount(m_area->getActiveLocationCount()); + m_area->updateContent(); } return; } diff --git a/src/lib_gui/qt/element/QtCodeNavigator.cpp b/src/lib_gui/qt/element/QtCodeNavigator.cpp index 11a701e6..ab660642 100644 --- a/src/lib_gui/qt/element/QtCodeNavigator.cpp +++ b/src/lib_gui/qt/element/QtCodeNavigator.cpp @@ -208,6 +208,7 @@ void QtCodeNavigator::clearCodeSnippets() } m_references.clear(); + m_activeReference = Reference(); m_refIndex = 0; m_singleHasNewFile = false; @@ -323,17 +324,18 @@ void QtCodeNavigator::showActiveSnippet( return; } + m_activeReference = Reference(); Id tokenId = activeTokenIds[0]; std::vector locationIds; - + size_t refIndex = 0; Reference firstReference; - std::set filePathsToExpand; std::map filePathOrder; - for (const Reference& ref : m_references) + for (size_t i = 0; i < m_references.size(); i++) { + const Reference& ref = m_references[i]; if (ref.tokenId == tokenId) { locationIds.push_back(ref.locationId); @@ -341,12 +343,14 @@ void QtCodeNavigator::showActiveSnippet( if (!firstReference.tokenId) { firstReference = ref; + refIndex = i + 1; } } filePathOrder.emplace(ref.filePath, filePathOrder.size()); } + std::set filePathsToExpand; if (!locationIds.size()) { collection->forEachTokenLocation( @@ -386,8 +390,13 @@ void QtCodeNavigator::showActiveSnippet( requestScroll(firstReference.filePath, 0, firstReference.locationId, true, false); emit scrollRequest(); - m_refIndex = 0; + m_refIndex = refIndex; updateRefLabel(); + + if (!refIndex) + { + m_activeReference = firstReference; + } } } @@ -439,13 +448,16 @@ void QtCodeNavigator::setupFiles() if (filePathsToExpand.size()) { - MessageCodeViewExpandedInitialFiles(m_refIndex != 0).dispatch(); + MessageCodeViewExpandedInitialFiles(m_refIndex != 0 || m_activeReference.tokenId).dispatch(); } } else if (m_references.size()) { m_singleHasNewFile = (m_single->getCurrentFilePath() != m_references.front().filePath); - m_single->requestFileContent(m_references.front().filePath); + if (!m_refIndex || !m_activeReference.tokenId) + { + m_single->requestFileContent(m_references.front().filePath); + } MessageCodeViewExpandedInitialFiles(true).dispatch(); } @@ -516,6 +528,20 @@ void QtCodeNavigator::scrollToLine(const FilePath& filePath, unsigned int line) void QtCodeNavigator::scrollToDefinition() { + if (m_activeReference.tokenId) + { + if (m_mode == MODE_LIST) + { + m_list->requestFileContent(m_activeReference.filePath); + } + + requestScroll(m_activeReference.filePath, 0, m_activeReference.locationId, true, false); + emit scrollRequest(); + + updateRefLabel(); + return; + } + if (m_refIndex != 0) { showCurrentReference(false); @@ -641,6 +667,8 @@ void QtCodeNavigator::previousReference(bool fromUI) m_refIndex--; } + m_activeReference = Reference(); + showCurrentReference(fromUI); } @@ -658,6 +686,8 @@ void QtCodeNavigator::nextReference(bool fromUI) m_refIndex = 1; } + m_activeReference = Reference(); + showCurrentReference(fromUI); } @@ -673,6 +703,9 @@ void QtCodeNavigator::setModeSingle() void QtCodeNavigator::setMode(Mode mode) { + m_listButton->setChecked(mode == MODE_LIST); + m_fileButton->setChecked(mode == MODE_SINGLE); + if (m_mode == mode) { return; @@ -680,9 +713,6 @@ void QtCodeNavigator::setMode(Mode mode) m_mode = mode; - m_listButton->setChecked(mode == MODE_LIST); - m_fileButton->setChecked(mode == MODE_SINGLE); - switch (mode) { case MODE_SINGLE: diff --git a/src/lib_gui/qt/element/QtCodeNavigator.h b/src/lib_gui/qt/element/QtCodeNavigator.h index 7a8e5fa9..727e1a87 100644 --- a/src/lib_gui/qt/element/QtCodeNavigator.h +++ b/src/lib_gui/qt/element/QtCodeNavigator.h @@ -175,6 +175,7 @@ private: QFrame* m_separatorLine; std::vector m_references; + Reference m_activeReference; size_t m_refIndex; ScrollRequest m_scrollRequest;