ui: Added on-demand local reference navigation to code view navigation bar (issue #453, #538)

* show local reference navigation for local symbols and multiple edge references
* shortcut Ctrl/Cmd + T
* iterate with consecutive edge clicks
This commit is contained in:
Eberhard Graether
2018-07-23 03:13:41 +02:00
parent 1df330ff2c
commit 95ebfff19c
24 changed files with 511 additions and 99 deletions
+1 -1
View File
@@ -184,7 +184,7 @@
<text>#262626</text>
</focus>
<active>
<border>transparent</border>
<border>white</border>
<fill>#A5DEFF</fill>
<text>#262626</text>
</active>
+1 -1
View File
@@ -183,7 +183,7 @@
<fill>#C6EAFF</fill>
</focus>
<active>
<border>transparent</border>
<border>#136391</border>
<fill>#C6EAFF</fill>
</active>
</local_symbol>
+1 -1
View File
@@ -184,7 +184,7 @@
<text>#191919</text>
</focus>
<active>
<border>transparent</border>
<border>white</border>
<fill>#969696</fill>
<text>#272728</text>
</active>
+29 -1
View File
@@ -24,7 +24,7 @@
border: none;
}
#code_navigation * {
#code_navigation QLabel {
color: <color:code/file/title/text>;
font-size: <setting:font_size>px;
}
@@ -50,11 +50,39 @@
}
#code_navigation #reference_button_previous {
/*width: 20px;*/
padding-bottom: 2px;
border-bottom-left-radius: 11px;
border-top-left-radius: 11px;
}
#code_navigation #reference_button_next {
/*width: 20px;*/
padding-top: 3px;
border-bottom-right-radius: 11px;
border-top-right-radius: 11px;
}
#code_navigation #file_button_previous, #code_navigation #file_button_next {
width: 22px;
}
#code_navigation #file_button_previous, #code_navigation #local_reference_button_previous {
border-bottom-left-radius: 11px;
border-top-left-radius: 11px;
}
#code_navigation #local_reference_button_previous {
padding-bottom: 2px;
}
#code_navigation #local_reference_button_next {
padding-top: 3px;
}
#code_navigation #file_button_next, #code_navigation #local_reference_button_next {
border-bottom-right-radius: 11px;
border-top-right-radius: 11px;
}
Binary file not shown.

After

Width:  |  Height:  |  Size: 939 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 922 B

@@ -13,8 +13,9 @@ public:
REFERENCE_NEXT
};
MessageCodeReference(ReferenceType type)
MessageCodeReference(ReferenceType type, bool localReference)
: type(type)
, localReference(localReference)
{
}
@@ -33,9 +34,15 @@ public:
{
os << L"next";
}
if (localReference)
{
os << L" local";
}
}
const ReferenceType type;
bool localReference;
};
#endif // MESSAGE_CODE_REFERENCE_H
+22 -8
View File
@@ -151,8 +151,8 @@ void QtCodeArea::lineNumberAreaPaintEvent(QPaintEvent *event)
std::set<int> activeLineNumbers;
std::set<int> focusedLineNumbers;
std::set<Id> activeSymbolIds = m_navigator->getActiveTokenIds();
std::set<Id> activeLocationIds = m_navigator->getCurrentActiveLocationIds();
const std::set<Id>& activeSymbolIds = m_navigator->getActiveTokenIds();
const std::set<Id>& activeLocalTokenIds = m_navigator->getActiveLocalTokenIds();
for (const Annotation& annotation : m_annotations)
{
@@ -183,7 +183,7 @@ void QtCodeArea::lineNumberAreaPaintEvent(QPaintEvent *event)
case LOCATION_TOKEN:
case LOCATION_SCOPE:
if (annotation.isActive && activeLocationIds.size())
if (annotation.isActive && activeLocalTokenIds.size())
{
focus = true;
break;
@@ -388,6 +388,19 @@ Id QtCodeArea::getLocationIdOfFirstHighlightedLocation() const
return 0;
}
std::vector<Id> QtCodeArea::getLocationIdsForTokenIds(const std::set<Id>& tokenIds) const
{
std::vector<Id> locationIds;
for (const Annotation& annotation : m_annotations)
{
if (utility::shareElement(annotation.tokenIds, tokenIds))
{
locationIds.push_back(annotation.locationId);
}
}
return locationIds;
}
size_t QtCodeArea::getActiveLocationCount() const
{
uint count = 0;
@@ -636,7 +649,7 @@ void QtCodeArea::mouseReleaseEvent(QMouseEvent* event)
activateAnnotations(annotations);
}
}
else if (m_navigator->getActiveLocalSymbolIds().size())
else if (m_navigator->getActiveLocalTokenIds().size())
{
MessageActivateLocalSymbols(std::vector<Id>()).dispatch();
}
@@ -816,12 +829,13 @@ void QtCodeArea::activateErrors(const std::vector<const Annotation*>& annotation
void QtCodeArea::annotateText()
{
std::set<Id> activeSymbolIds = m_navigator->getCurrentActiveTokenIds();
utility::append(activeSymbolIds, m_navigator->getActiveLocalSymbolIds());
const std::set<Id>& activeLocationIds = m_navigator->getCurrentActiveLocationIds();
const std::set<Id>& activeSymbolIds = m_navigator->getCurrentActiveTokenIds();
const std::set<Id>& activeLocationIds =
utility::concat(m_navigator->getCurrentActiveLocationIds(), m_navigator->getCurrentActiveLocalLocationIds());
std::set<Id> focusedSymbolIds = m_navigator->getActiveTokenIds();
utility::append(focusedSymbolIds, m_navigator->getActiveLocalTokenIds());
for (Id currentActiveId : activeSymbolIds)
{
focusedSymbolIds.erase(currentActiveId);
+2
View File
@@ -81,6 +81,8 @@ public:
Id getLocationIdOfFirstActiveScopeLocation(Id tokenId) const;
Id getLocationIdOfFirstHighlightedLocation() const;
std::vector<Id> getLocationIdsForTokenIds(const std::set<Id>& tokenIds) const;
size_t getActiveLocationCount() const;
QRectF getLineRectForLineNumber(uint lineNumber) const;
+13
View File
@@ -390,6 +390,19 @@ void QtCodeFile::findScreenMatches(const std::wstring& query, std::vector<std::p
}
}
std::vector<std::pair<FilePath, Id>> QtCodeFile::getLocationIdsForTokenIds(const std::set<Id>& tokenIds) const
{
std::vector<std::pair<FilePath, Id>> locationIds;
for (QtCodeSnippet* snippet : m_snippets)
{
for (Id locationId : snippet->getLocationIdsForTokenIds(tokenIds))
{
locationIds.push_back(std::make_pair(m_filePath, locationId));
}
}
return locationIds;
}
void QtCodeFile::clickedMinimizeButton()
{
MessageChangeFileView(
+3
View File
@@ -2,6 +2,7 @@
#define QT_CODE_FILE_H
#include <memory>
#include <set>
#include <string>
#include <vector>
@@ -63,6 +64,8 @@ public:
void findScreenMatches(const std::wstring& query, std::vector<std::pair<QtCodeArea*, Id>>* screenMatches);
std::vector<std::pair<FilePath, Id>> getLocationIdsForTokenIds(const std::set<Id>& tokenIds) const;
public slots:
void clickedMinimizeButton();
void clickedSnippetButton();
+11 -4
View File
@@ -7,6 +7,7 @@
#include "utility/file/FilePath.h"
#include "utility/ResourcePaths.h"
#include "utility/utilityApp.h"
#include "utility/utility.h"
#include "data/location/SourceLocationFile.h"
#include "qt/element/QtCodeFile.h"
@@ -69,10 +70,6 @@ QtCodeFileList::QtCodeFileList(QtCodeNavigator* navigator)
connect(m_scrollArea->verticalScrollBar(), &QScrollBar::valueChanged, m_navigator, &QtCodeNavigator::scrolled);
}
QtCodeFileList::~QtCodeFileList()
{
}
void QtCodeFileList::clear()
{
for (QtCodeFile* file : m_files)
@@ -275,6 +272,16 @@ void QtCodeFileList::findScreenMatches(const std::wstring& query, std::vector<st
}
}
std::vector<std::pair<FilePath, Id>> QtCodeFileList::getLocationIdsForTokenIds(const std::set<Id>& tokenIds) const
{
std::vector<std::pair<FilePath, Id>> locationIds;
for (QtCodeFile* file : m_files)
{
utility::append(locationIds, file->getLocationIdsForTokenIds(tokenIds));
}
return locationIds;
}
void QtCodeFileList::setFileMinimized(const FilePath path)
{
if (path.empty())
+13 -11
View File
@@ -23,7 +23,7 @@ class QtCodeFileList
public:
QtCodeFileList(QtCodeNavigator* navigator);
virtual ~QtCodeFileList();
virtual ~QtCodeFileList() = default;
void clear();
void clearSnippetTitleAndScrollBar();
@@ -32,20 +32,22 @@ public:
void addFile(std::shared_ptr<SourceLocationFile> locationFile, int refCount, TimeStamp modificationTime);
// QtCodeNaviatebale implementation
virtual QScrollArea* getScrollArea();
QScrollArea* getScrollArea() override;
virtual void addCodeSnippet(const CodeSnippetParams& params);
virtual void updateCodeSnippet(const CodeSnippetParams& params);
void addCodeSnippet(const CodeSnippetParams& params) override;
void updateCodeSnippet(const CodeSnippetParams& params) override;
virtual void requestFileContent(const FilePath& filePath);
virtual bool requestScroll(const FilePath& filePath, uint lineNumber, Id locationId, bool animated, ScrollTarget target);
void requestFileContent(const FilePath& filePath) override;
bool requestScroll(const FilePath& filePath, uint lineNumber, Id locationId, bool animated, ScrollTarget target) override;
virtual void updateFiles();
virtual void showContents();
void updateFiles() override;
void showContents() override;
virtual void onWindowFocus();
void onWindowFocus() override;
virtual void findScreenMatches(const std::wstring& query, std::vector<std::pair<QtCodeArea*, Id>>* screenMatches);
void findScreenMatches(const std::wstring& query, std::vector<std::pair<QtCodeArea*, Id>>* screenMatches) override;
std::vector<std::pair<FilePath, Id>> getLocationIdsForTokenIds(const std::set<Id>& tokenIds) const override;
void setFileMinimized(const FilePath path);
void setFileSnippets(const FilePath path);
@@ -57,7 +59,7 @@ public:
std::pair<QtCodeSnippet*, Id> getFirstSnippetWithActiveLocationId(Id tokenId) const;
protected:
virtual void resizeEvent(QResizeEvent* event);
void resizeEvent(QResizeEvent* event) override;
private slots:
void updateSnippetTitleAndScrollBarSlot();
+15 -4
View File
@@ -44,10 +44,6 @@ QtCodeFileSingle::QtCodeFileSingle(QtCodeNavigator* navigator, QWidget* parent)
layout()->addWidget(m_areaWrapper);
}
QtCodeFileSingle::~QtCodeFileSingle()
{
}
QAbstractScrollArea* QtCodeFileSingle::getScrollArea()
{
return m_area;
@@ -234,6 +230,21 @@ void QtCodeFileSingle::findScreenMatches(const std::wstring& query, std::vector<
}
}
std::vector<std::pair<FilePath, Id>> QtCodeFileSingle::getLocationIdsForTokenIds(const std::set<Id>& tokenIds) const
{
if (m_area)
{
std::vector<std::pair<FilePath, Id>> locationIds;
for (Id locationId : m_area->getLocationIdsForTokenIds(tokenIds))
{
locationIds.push_back(std::make_pair(getCurrentFilePath(), locationId));
}
return locationIds;
}
return { };
}
const FilePath& QtCodeFileSingle::getCurrentFilePath() const
{
return m_currentFilePath;
+12 -10
View File
@@ -25,29 +25,31 @@ class QtCodeFileSingle
public:
QtCodeFileSingle(QtCodeNavigator* navigator, QWidget* parent = nullptr);
virtual ~QtCodeFileSingle();
virtual ~QtCodeFileSingle() = default;
void clearFile();
void clearCache();
// QtCodeNavigateable implementation
virtual QAbstractScrollArea* getScrollArea() override;
QAbstractScrollArea* getScrollArea() override;
virtual void addCodeSnippet(const CodeSnippetParams& params) override;
virtual void updateCodeSnippet(const CodeSnippetParams& params) override;
void addCodeSnippet(const CodeSnippetParams& params) override;
void updateCodeSnippet(const CodeSnippetParams& params) override;
virtual void requestFileContent(const FilePath& filePath) override;
virtual bool requestScroll(
void requestFileContent(const FilePath& filePath) override;
bool requestScroll(
const FilePath& filePath, uint lineNumber, Id locationId, bool animated, ScrollTarget target) override;
virtual void updateFiles() override;
virtual void showContents() override;
void updateFiles() override;
void showContents() override;
virtual void onWindowFocus() override;
void onWindowFocus() override;
virtual void findScreenMatches(
void findScreenMatches(
const std::wstring& query, std::vector<std::pair<QtCodeArea*, Id>>* screenMatches) override;
std::vector<std::pair<FilePath, Id>> getLocationIdsForTokenIds(const std::set<Id>& tokenIds) const override;
const FilePath& getCurrentFilePath() const;
bool hasFileCached(const FilePath& filePath) const;
@@ -41,6 +41,8 @@ public:
virtual void findScreenMatches(const std::wstring& query, std::vector<std::pair<QtCodeArea*, Id>>* screenMatches) = 0;
virtual std::vector<std::pair<FilePath, Id>> getLocationIdsForTokenIds(const std::set<Id>& tokenIds) const = 0;
protected:
void ensureWidgetVisibleAnimated(const QWidget* parentWidget, const QWidget *childWidget, QRectF rect, bool animated, ScrollTarget target);
void ensurePercentVisibleAnimated(double percentA, double percentB, bool animated, ScrollTarget target);
+321 -46
View File
@@ -10,6 +10,7 @@
#include "utility/messaging/type/error/MessageShowError.h"
#include "utility/messaging/type/MessageScrollCode.h"
#include "utility/ResourcePaths.h"
#include "utility/utility.h"
#include "data/location/SourceLocation.h"
#include "data/location/SourceLocationCollection.h"
@@ -18,6 +19,7 @@
#include "qt/element/QtCodeFile.h"
#include "qt/element/QtCodeSnippet.h"
#include "qt/element/QtSearchBarButton.h"
#include "qt/utility/utilityQt.h"
#include "settings/ApplicationSettings.h"
QtCodeNavigator::QtCodeNavigator(QWidget* parent)
@@ -44,32 +46,87 @@ QtCodeNavigator::QtCodeNavigator(QWidget* parent)
navLayout->setSpacing(2);
navLayout->setContentsMargins(7, 7, 7, 6);
{
m_prevFileButton =
new QtSearchBarButton(ResourcePaths::getGuiPath().concatenate(L"code_view/images/arrow_left.png"), true);
m_nextFileButton =
new QtSearchBarButton(ResourcePaths::getGuiPath().concatenate(L"code_view/images/arrow_right.png"), true);
m_prevReferenceButton =
new QtSearchBarButton(ResourcePaths::getGuiPath().concatenate(L"code_view/images/arrow_up.png"), true);
m_nextReferenceButton =
new QtSearchBarButton(ResourcePaths::getGuiPath().concatenate(L"code_view/images/arrow_down.png"), true);
m_prevButton = new QtSearchBarButton(ResourcePaths::getGuiPath().concatenate(L"code_view/images/arrow_left.png"), true);
m_nextButton = new QtSearchBarButton(ResourcePaths::getGuiPath().concatenate(L"code_view/images/arrow_right.png"), true);
m_prevFileButton->setObjectName("file_button_previous");
m_nextFileButton->setObjectName("file_button_next");
m_prevReferenceButton->setObjectName("reference_button_previous");
m_nextReferenceButton->setObjectName("reference_button_next");
m_prevButton->setObjectName("reference_button_previous");
m_nextButton->setObjectName("reference_button_next");
m_prevFileButton->setToolTip("previous file");
m_nextFileButton->setToolTip("next file");
m_prevReferenceButton->setToolTip("previous reference");
m_nextReferenceButton->setToolTip("next reference");
m_prevButton->setToolTip("previous reference");
m_nextButton->setToolTip("next reference");
m_prevFileButton->setIconSize(QSize(12, 12));
m_nextFileButton->setIconSize(QSize(12, 12));
m_prevReferenceButton->setIconSize(QSize(12, 12));
m_nextReferenceButton->setIconSize(QSize(12, 12));
m_prevButton->setIconSize(QSize(12, 12));
m_nextButton->setIconSize(QSize(12, 12));
m_prevFileButton->hide();
m_nextFileButton->hide();
navLayout->addWidget(m_prevButton);
navLayout->addWidget(m_nextButton);
navLayout->addWidget(m_prevFileButton);
navLayout->addWidget(m_prevReferenceButton);
navLayout->addWidget(m_nextReferenceButton);
navLayout->addWidget(m_nextFileButton);
connect(m_prevButton, &QPushButton::clicked, this, &QtCodeNavigator::previousReference);
connect(m_nextButton, &QPushButton::clicked, this, &QtCodeNavigator::nextReference);
connect(m_prevFileButton, &QPushButton::clicked, this, &QtCodeNavigator::previousFile);
connect(m_nextFileButton, &QPushButton::clicked, this, &QtCodeNavigator::nextFile);
connect(m_prevReferenceButton, &QPushButton::clicked, this, &QtCodeNavigator::previousReference);
connect(m_nextReferenceButton, &QPushButton::clicked, this, &QtCodeNavigator::nextReference);
// m_refLabel = new QLabel("0 files | 0 references");
m_refLabel = new QLabel("0 references");
m_refLabel->setObjectName("references_label");
navLayout->addWidget(m_refLabel);
m_refLabel = new QLabel("0/0 references");
m_refLabel->setObjectName("references_label");
navLayout->addWidget(m_refLabel);
navLayout->addStretch();
}
navLayout->addStretch();
{
m_prevLocalReferenceButton =
new QtSearchBarButton(ResourcePaths::getGuiPath().concatenate(L"code_view/images/arrow_up.png"), true);
m_nextLocalReferenceButton =
new QtSearchBarButton(ResourcePaths::getGuiPath().concatenate(L"code_view/images/arrow_down.png"), true);
m_prevLocalReferenceButton->setObjectName("local_reference_button_previous");
m_nextLocalReferenceButton->setObjectName("local_reference_button_next");
m_prevLocalReferenceButton->setToolTip("previous local reference");
m_nextLocalReferenceButton->setToolTip("next local reference");
m_prevLocalReferenceButton->setIconSize(QSize(12, 12));
m_nextLocalReferenceButton->setIconSize(QSize(12, 12));
navLayout->addWidget(m_prevLocalReferenceButton);
navLayout->addWidget(m_nextLocalReferenceButton);
connect(m_prevLocalReferenceButton, &QPushButton::clicked, this, &QtCodeNavigator::previousLocalReference);
connect(m_nextLocalReferenceButton, &QPushButton::clicked, this, &QtCodeNavigator::nextLocalReference);
m_localRefLabel = new QLabel("0/0 local references");
m_localRefLabel->setObjectName("references_label");
navLayout->addWidget(m_localRefLabel);
navLayout->addStretch();
utility::setWidgetRetainsSpaceWhenHidden(m_prevLocalReferenceButton);
utility::setWidgetRetainsSpaceWhenHidden(m_nextLocalReferenceButton);
utility::setWidgetRetainsSpaceWhenHidden(m_localRefLabel);
m_prevLocalReferenceButton->hide();
m_nextLocalReferenceButton->hide();
m_localRefLabel->hide();
}
m_listButton = new QtSearchBarButton(ResourcePaths::getGuiPath().concatenate(L"code_view/images/list.png"), true);
m_fileButton = new QtSearchBarButton(ResourcePaths::getGuiPath().concatenate(L"code_view/images/file.png"), true);
@@ -139,6 +196,12 @@ void QtCodeNavigator::addCodeSnippet(const CodeSnippetParams& params)
{
m_singleHasNewFile = true;
}
// refresh local reference count when visible code changes
if (m_localReferences.size() && m_localReferences[0].locationType == LOCATION_LOCAL_SYMBOL)
{
setActiveLocalTokenIds(utility::toVector(m_activeLocalTokenIds), LOCATION_LOCAL_SYMBOL);
}
}
void QtCodeNavigator::updateCodeSnippet(const CodeSnippetParams& params)
@@ -205,14 +268,16 @@ void QtCodeNavigator::addedFiles()
if (m_refIndex == 0)
{
updateRefLabel();
updateRefLabels();
}
}
void QtCodeNavigator::clear()
{
clearCodeSnippets(false);
updateRefLabel();
clearCaches();
updateRefLabels();
}
void QtCodeNavigator::clearCodeSnippets(bool useSingleFileCache)
@@ -221,7 +286,7 @@ void QtCodeNavigator::clearCodeSnippets(bool useSingleFileCache)
m_currentActiveTokenIds.clear();
m_activeTokenIds.clear();
m_activeLocalSymbolIds.clear();
m_activeLocalTokenIds.clear();
m_focusedTokenIds.clear();
m_errorInfos.clear();
@@ -246,7 +311,7 @@ void QtCodeNavigator::clearFile()
{
m_single->clearFile();
updateRefLabel();
updateRefLabels();
}
void QtCodeNavigator::clearCaches()
@@ -291,10 +356,22 @@ const std::set<Id>& QtCodeNavigator::getCurrentActiveLocationIds() const
void QtCodeNavigator::setCurrentActiveLocationIds(const std::vector<Id>& currentActiveLocationIds)
{
setActiveLocalTokenIds({ }, LOCATION_TOKEN);
m_currentActiveLocationIds = std::set<Id>(currentActiveLocationIds.begin(), currentActiveLocationIds.end());
m_currentActiveTokenIds.clear();
}
const std::set<Id>& QtCodeNavigator::getCurrentActiveLocalLocationIds() const
{
return m_currentActiveLocalLocationIds;
}
void QtCodeNavigator::setCurrentActiveLocalLocationIds(const std::vector<Id>& currentActiveLocalLocationIds)
{
m_currentActiveLocalLocationIds = std::set<Id>(currentActiveLocalLocationIds.begin(), currentActiveLocalLocationIds.end());
}
const std::set<Id>& QtCodeNavigator::getActiveTokenIds() const
{
return m_activeTokenIds;
@@ -302,22 +379,40 @@ const std::set<Id>& QtCodeNavigator::getActiveTokenIds() const
void QtCodeNavigator::setActiveTokenIds(const std::vector<Id>& activeTokenIds)
{
setActiveLocalTokenIds({ }, LOCATION_TOKEN);
setCurrentActiveTokenIds(activeTokenIds);
m_activeTokenIds = std::set<Id>(activeTokenIds.begin(), activeTokenIds.end());
m_activeTokenId = activeTokenIds.size() ? activeTokenIds[0] : 0;
m_activeLocalSymbolIds.clear();
}
const std::set<Id>& QtCodeNavigator::getActiveLocalSymbolIds() const
const std::set<Id>& QtCodeNavigator::getActiveLocalTokenIds() const
{
return m_activeLocalSymbolIds;
return m_activeLocalTokenIds;
}
void QtCodeNavigator::setActiveLocalSymbolIds(const std::vector<Id>& activeLocalSymbolIds)
void QtCodeNavigator::setActiveLocalTokenIds(const std::vector<Id>& activeLocalTokenIds, LocationType locationType)
{
m_activeLocalSymbolIds = std::set<Id>(activeLocalSymbolIds.begin(), activeLocalSymbolIds.end());
setCurrentActiveTokenIds(locationType == LOCATION_TOKEN ? activeLocalTokenIds : std::vector<Id>());
setCurrentActiveLocalLocationIds({ });
m_activeLocalTokenIds.clear();
m_activeLocalTokenIds.insert(activeLocalTokenIds.begin(), activeLocalTokenIds.end());
m_localReferences.clear();
m_localRefIndex = 0;
if (m_activeLocalTokenIds.size())
{
for (std::pair<FilePath, Id> p : m_current->getLocationIdsForTokenIds(m_activeLocalTokenIds))
{
Reference ref;
ref.filePath = p.first;
ref.locationId = p.second;
ref.locationType = locationType;
m_localReferences.push_back(ref);
}
}
}
const std::set<Id>& QtCodeNavigator::getFocusedTokenIds() const
@@ -393,6 +488,13 @@ void QtCodeNavigator::showActiveSnippet(
m_activeReference = Reference();
Id tokenId = activeTokenIds[0];
// iterate local references when same tokenId get reactivated (consecutive edge clicks)
if (m_activeLocalTokenIds.size() == 1 && *m_activeLocalTokenIds.begin() == tokenId && m_localReferences.size())
{
nextLocalReference();
return;
}
std::vector<Id> locationIds;
size_t refIndex = 0;
Reference firstReference;
@@ -450,7 +552,7 @@ void QtCodeNavigator::showActiveSnippet(
);
}
setCurrentActiveLocationIds(locationIds);
setActiveLocalTokenIds({ tokenId }, LOCATION_TOKEN);
updateFiles();
if (m_mode == MODE_LIST)
@@ -474,7 +576,7 @@ void QtCodeNavigator::showActiveSnippet(
}
m_refIndex = refIndex;
updateRefLabel();
updateRefLabels();
if (!refIndex)
{
@@ -522,7 +624,7 @@ void QtCodeNavigator::setFileMaximized(const FilePath path)
void QtCodeNavigator::updateFiles()
{
m_current->updateFiles();
updateRefLabel();
updateRefLabels();
}
void QtCodeNavigator::showContents()
@@ -637,7 +739,7 @@ void QtCodeNavigator::scrollToDefinition(bool animated, bool ignoreActiveReferen
{
m_activeReference = Reference();
m_refIndex = 0;
updateRefLabel();
updateRefLabels();
}
if (m_activeReference.tokenId)
@@ -650,7 +752,7 @@ void QtCodeNavigator::scrollToDefinition(bool animated, bool ignoreActiveReferen
requestScroll(m_activeReference.filePath, 0, m_activeReference.locationId, true, QtCodeNavigateable::SCROLL_CENTER);
emit scrollRequest();
updateRefLabel();
updateRefLabels();
return;
}
@@ -772,6 +874,66 @@ void QtCodeNavigator::setValue()
}
}
void QtCodeNavigator::previousFile(bool fromUI)
{
if (!m_references.size())
{
return;
}
if (m_refIndex == 0)
{
m_refIndex = m_references.size();
}
else
{
const Reference& ref = m_references[m_refIndex - 1];
do
{
m_refIndex--;
if (m_refIndex == 0)
{
m_refIndex = m_references.size();
}
}
while (&ref != &m_references[m_refIndex - 1] && ref.filePath == m_references[m_refIndex - 1].filePath);
}
m_activeReference = Reference();
showCurrentReference(fromUI);
}
void QtCodeNavigator::nextFile(bool fromUI)
{
if (!m_references.size())
{
return;
}
if (m_refIndex == 0)
{
m_refIndex++;
}
else
{
const Reference& ref = m_references[m_refIndex - 1];
do
{
if (m_refIndex == m_references.size())
{
m_refIndex = 0;
}
m_refIndex++;
}
while (&ref != &m_references[m_refIndex - 1] && ref.filePath == m_references[m_refIndex - 1].filePath);
}
m_activeReference = Reference();
showCurrentReference(fromUI);
}
void QtCodeNavigator::previousReference(bool fromUI)
{
if (!m_references.size())
@@ -812,6 +974,42 @@ void QtCodeNavigator::nextReference(bool fromUI)
showCurrentReference(fromUI);
}
void QtCodeNavigator::previousLocalReference(bool fromUI)
{
if (!m_localReferences.size())
{
return;
}
if (m_localRefIndex < 2)
{
m_localRefIndex = m_localReferences.size();
}
else
{
m_localRefIndex--;
}
showCurrentLocalReference();
}
void QtCodeNavigator::nextLocalReference(bool fromUI)
{
if (!m_localReferences.size())
{
return;
}
m_localRefIndex++;
if (m_localRefIndex == m_localReferences.size() + 1)
{
m_localRefIndex = 1;
}
showCurrentLocalReference();
}
void QtCodeNavigator::setModeList()
{
if (m_mode == MODE_LIST)
@@ -846,39 +1044,116 @@ void QtCodeNavigator::showCurrentReference(bool fromUI)
MessageShowReference(m_refIndex, ref.tokenId, ref.locationId, fromUI).dispatch();
}
void QtCodeNavigator::updateRefLabel()
{
size_t n = m_references.size();
size_t t = m_refIndex;
if (t)
void QtCodeNavigator::showCurrentLocalReference()
{
if (m_localRefIndex > 0)
{
m_refLabel->setText(QString::number(t) + "/" + QString::number(n) + " references");
const Reference& ref = m_localReferences[m_localRefIndex - 1];
setCurrentActiveLocalLocationIds({ ref.locationId });
if (ref.locationType == LOCATION_TOKEN)
{
setCurrentActiveTokenIds({ });
// synchronise reference navigation with local reference navigation
for (size_t i = 0; i < m_references.size(); i++)
{
if (m_references[i].locationId == ref.locationId)
{
m_refIndex = i + 1;
}
}
}
updateFiles();
requestScroll(ref.filePath, 0, ref.locationId, true, QtCodeNavigateable::SCROLL_CENTER);
emit scrollRequest();
}
}
void QtCodeNavigator::updateRefLabels()
{
size_t refCount = m_references.size();
// std::set<FilePath> files;
// size_t fileIndex = 0;
// for (size_t i = 0; i < m_references.size(); i++)
// {
// const Reference& ref = m_references[i];
// files.insert(ref.filePath);
// if (i == m_refIndex - 1)
// {
// fileIndex = files.size();
// }
// }
if (m_refIndex)
{
m_refLabel->setText(QString::number(m_refIndex) + "/" + QString::number(refCount) + " references");
// m_refLabel->setText(
// QString::number(fileIndex) + "/" + QString::number(files.size()) + " files | " +
// QString::number(m_refIndex) + "/" + QString::number(refCount) + " references"
// );
}
else
{
m_refLabel->setText(QString::number(n) + " references");
m_refLabel->setText(QString::number(refCount) + " references");
// m_refLabel->setText(QString::number(files.size()) + " files | " + QString::number(refCount) + " references");
}
m_prevButton->setEnabled(n > 1);
m_nextButton->setEnabled(n > 1);
m_refLabel->setMinimumWidth(
m_refLabel->fontMetrics().width(QString(QString::number(refCount).size() * 2, 'a') + "/ references") + 30);
m_prevFileButton->setEnabled(refCount > 1);
m_nextFileButton->setEnabled(refCount > 1);
m_prevReferenceButton->setEnabled(refCount > 1);
m_nextReferenceButton->setEnabled(refCount > 1);
size_t localRefCount = m_localReferences.size();
if (m_localRefIndex)
{
m_localRefLabel->setText(QString::number(m_localRefIndex) + "/" + QString::number(localRefCount) + " local references");
}
else
{
m_localRefLabel->setText(QString::number(localRefCount) + " local references");
}
m_localRefLabel->setMinimumWidth(
m_localRefLabel->fontMetrics().width(QString(QString::number(localRefCount).size() * 2, 'a') + "/ local references") + 30);
m_nextLocalReferenceButton->setVisible(localRefCount > 1);
m_prevLocalReferenceButton->setVisible(localRefCount > 1);
m_localRefLabel->setVisible(localRefCount > 1);
}
void QtCodeNavigator::handleMessage(MessageCodeReference* message)
{
MessageCodeReference::ReferenceType type = message->type;
bool next = (message->type == MessageCodeReference::REFERENCE_NEXT);
bool local = message->localReference;
m_onQtThread(
[=]()
{
if (type == MessageCodeReference::REFERENCE_PREVIOUS)
if (next && local)
{
previousReference();
nextLocalReference();
}
else if (type == MessageCodeReference::REFERENCE_NEXT)
else if (next)
{
nextReference();
}
else if (local)
{
previousLocalReference();
}
else
{
previousReference();
}
}
);
}
@@ -906,7 +1181,7 @@ void QtCodeNavigator::handleMessage(MessageShowReference* message)
if (m_refIndex > 0)
{
const Reference& ref = m_references[m_refIndex - 1];
setCurrentActiveLocationIds(std::vector<Id>(1, ref.locationId));
setCurrentActiveLocationIds({ ref.locationId });
if (!replayed)
{
@@ -924,7 +1199,7 @@ void QtCodeNavigator::handleMessage(MessageShowReference* message)
if (!replayed)
{
updateRefLabel();
updateRefLabels();
}
}
);
+29 -8
View File
@@ -62,11 +62,14 @@ public:
const std::set<Id>& getCurrentActiveLocationIds() const;
void setCurrentActiveLocationIds(const std::vector<Id>& currentActiveLocationIds);
const std::set<Id>& getCurrentActiveLocalLocationIds() const;
void setCurrentActiveLocalLocationIds(const std::vector<Id>& currentActiveLocalLocationIds);
const std::set<Id>& getActiveTokenIds() const;
void setActiveTokenIds(const std::vector<Id>& activeTokenIds);
const std::set<Id>& getActiveLocalSymbolIds() const;
void setActiveLocalSymbolIds(const std::vector<Id>& activeLocalSymbolIds);
const std::set<Id>& getActiveLocalTokenIds() const;
void setActiveLocalTokenIds(const std::vector<Id>& activeLocalTokenIds, LocationType locationType);
const std::set<Id>& getFocusedTokenIds() const;
void setFocusedTokenIds(const std::vector<Id>& focusedTokenIds);
@@ -119,9 +122,15 @@ private slots:
void handleScrollRequest();
void setValue();
void previousFile(bool fromUI = true);
void nextFile(bool fromUI = true);
void previousReference(bool fromUI = true);
void nextReference(bool fromUI = true);
void previousLocalReference(bool fromUI = true);
void nextLocalReference(bool fromUI = true);
void setModeList();
void setModeSingle();
@@ -142,7 +151,8 @@ private:
};
void showCurrentReference(bool fromUI);
void updateRefLabel();
void showCurrentLocalReference();
void updateRefLabels();
struct ScrollRequest
{
@@ -179,9 +189,10 @@ private:
std::set<Id> m_currentActiveTokenIds;
std::set<Id> m_currentActiveLocationIds;
std::set<Id> m_currentActiveLocalLocationIds;
std::set<Id> m_activeTokenIds;
std::set<Id> m_activeLocalSymbolIds;
std::set<Id> m_activeLocalTokenIds;
std::set<Id> m_focusedTokenIds;
std::map<Id, ErrorInfo> m_errorInfos;
@@ -189,18 +200,28 @@ private:
int m_value;
QtSearchBarButton* m_listButton;
QtSearchBarButton* m_fileButton;
QtSearchBarButton* m_prevFileButton;
QtSearchBarButton* m_nextFileButton;
QtSearchBarButton* m_prevReferenceButton;
QtSearchBarButton* m_nextReferenceButton;
QLabel* m_refLabel;
QtSearchBarButton* m_prevButton;
QtSearchBarButton* m_nextButton;
QtSearchBarButton* m_prevLocalReferenceButton;
QtSearchBarButton* m_nextLocalReferenceButton;
QLabel* m_localRefLabel;
QtSearchBarButton* m_listButton;
QtSearchBarButton* m_fileButton;
QFrame* m_separatorLine;
std::vector<Reference> m_references;
Reference m_activeReference;
size_t m_refIndex;
std::vector<Reference> m_localReferences;
size_t m_localRefIndex;
ScrollRequest m_scrollRequest;
bool m_singleHasNewFile;
bool m_useSingleFileCache;
+5
View File
@@ -199,6 +199,11 @@ void QtCodeSnippet::findScreenMatches(const std::wstring& query, std::vector<std
m_codeArea->findScreenMatches(query, screenMatches);
}
std::vector<Id> QtCodeSnippet::getLocationIdsForTokenIds(const std::set<Id>& tokenIds) const
{
return m_codeArea->getLocationIdsForTokenIds(tokenIds);
}
void QtCodeSnippet::ensureLocationIdVisible(Id locationId, bool animated)
{
m_codeArea->ensureLocationIdVisible(locationId, width(), animated);
+2
View File
@@ -54,6 +54,8 @@ public:
void findScreenMatches(const std::wstring& query, std::vector<std::pair<QtCodeArea*, Id>>* screenMatches);
std::vector<Id> getLocationIdsForTokenIds(const std::set<Id>& tokenIds) const;
void ensureLocationIdVisible(Id locationId, bool animated);
private slots:
@@ -6,6 +6,7 @@ QtSearchBarButton::QtSearchBarButton(const FilePath& iconPath, bool small, QWidg
: QtSelfRefreshIconButton("", iconPath, "search/button", parent)
, m_small(small)
{
refresh();
}
void QtSearchBarButton::refresh()
+1 -1
View File
@@ -216,7 +216,7 @@ void QtCodeView::showActiveLocalSymbolIds(const std::vector<Id>& activeLocalSymb
{
m_onQtThread([=]()
{
m_widget->setActiveLocalSymbolIds(activeLocalSymbolIds);
m_widget->setActiveLocalTokenIds(activeLocalSymbolIds, LOCATION_LOCAL_SYMBOL);
m_widget->updateFiles();
});
}
+17 -2
View File
@@ -617,12 +617,22 @@ void QtMainWindow::findOnScreen()
void QtMainWindow::codeReferencePrevious()
{
MessageCodeReference(MessageCodeReference::REFERENCE_PREVIOUS).dispatch();
MessageCodeReference(MessageCodeReference::REFERENCE_PREVIOUS, false).dispatch();
}
void QtMainWindow::codeReferenceNext()
{
MessageCodeReference(MessageCodeReference::REFERENCE_NEXT).dispatch();
MessageCodeReference(MessageCodeReference::REFERENCE_NEXT, false).dispatch();
}
void QtMainWindow::codeLocalReferencePrevious()
{
MessageCodeReference(MessageCodeReference::REFERENCE_PREVIOUS, true).dispatch();
}
void QtMainWindow::codeLocalReferenceNext()
{
MessageCodeReference(MessageCodeReference::REFERENCE_NEXT, true).dispatch();
}
void QtMainWindow::overview()
@@ -828,6 +838,11 @@ void QtMainWindow::setupEditMenu()
menu->addAction(tr("Code Reference Previous"), this,
&QtMainWindow::codeReferencePrevious, QKeySequence(Qt::SHIFT + Qt::CTRL + Qt::Key_G));
menu->addAction(tr("Code Local Reference Next"), this,
&QtMainWindow::codeLocalReferenceNext, QKeySequence(Qt::CTRL + Qt::Key_T));
menu->addAction(tr("Code Local Reference Previous"), this,
&QtMainWindow::codeLocalReferencePrevious, QKeySequence(Qt::SHIFT + Qt::CTRL + Qt::Key_T));
menu->addSeparator();
menu->addAction(tr("&To overview"), this, &QtMainWindow::overview, QKeySequence::MoveToStartOfDocument);
+2
View File
@@ -124,6 +124,8 @@ public slots:
void findOnScreen();
void codeReferencePrevious();
void codeReferenceNext();
void codeLocalReferencePrevious();
void codeLocalReferenceNext();
void overview();
void closeWindow();