src: Refactored TokenLocation classes to SourceLocation classes
* Removed TokenLocationLine * decoupled TokenLocationFile from TokenLocationCollection * save vector of Token ids to SourceLocation * refactored SourceLocationFile::getFilteredByLines() * refactored snippet creation
This commit is contained in:
@@ -12,7 +12,7 @@
|
||||
#include <QToolTip>
|
||||
|
||||
#include "utility/messaging/type/MessageActivateLocalSymbols.h"
|
||||
#include "utility/messaging/type/MessageActivateTokenLocations.h"
|
||||
#include "utility/messaging/type/MessageActivateSourceLocations.h"
|
||||
#include "utility/messaging/type/MessageActivateTokenIds.h"
|
||||
#include "utility/messaging/type/MessageFocusIn.h"
|
||||
#include "utility/messaging/type/MessageFocusOut.h"
|
||||
@@ -20,8 +20,8 @@
|
||||
#include "utility/messaging/type/MessageShowErrors.h"
|
||||
#include "utility/utility.h"
|
||||
|
||||
#include "data/location/TokenLocation.h"
|
||||
#include "data/location/TokenLocationFile.h"
|
||||
#include "data/location/SourceLocation.h"
|
||||
#include "data/location/SourceLocationFile.h"
|
||||
#include "qt/element/QtCodeNavigator.h"
|
||||
#include "qt/utility/QtContextMenu.h"
|
||||
#include "qt/utility/QtHighlighter.h"
|
||||
@@ -83,7 +83,7 @@ void QtCodeArea::clearAnnotationColors()
|
||||
QtCodeArea::QtCodeArea(
|
||||
uint startLineNumber,
|
||||
const std::string& code,
|
||||
std::shared_ptr<TokenLocationFile> locationFile,
|
||||
std::shared_ptr<SourceLocationFile> locationFile,
|
||||
QtCodeNavigator* navigator,
|
||||
QWidget* parent
|
||||
)
|
||||
@@ -197,7 +197,7 @@ uint QtCodeArea::getEndLineNumber() const
|
||||
return m_startLineNumber + blockCount() - 1;
|
||||
}
|
||||
|
||||
std::shared_ptr<TokenLocationFile> QtCodeArea::getTokenLocationFile() const
|
||||
std::shared_ptr<SourceLocationFile> QtCodeArea::getSourceLocationFile() const
|
||||
{
|
||||
return m_locationFile;
|
||||
}
|
||||
@@ -301,7 +301,7 @@ uint QtCodeArea::getStartLineNumberOfFirstActiveLocationOfTokenId(Id tokenId) co
|
||||
{
|
||||
if (annotation.locationType == LocationType::LOCATION_TOKEN && annotation.isActive)
|
||||
{
|
||||
if (annotation.tokenId == tokenId)
|
||||
if (annotation.tokenIds.find(tokenId) != annotation.tokenIds.end())
|
||||
{
|
||||
if (!firstActiveLine || firstActiveLine == annotation.startLine)
|
||||
{
|
||||
@@ -326,12 +326,10 @@ Id QtCodeArea::getLocationIdOfFirstActiveLocationOfTokenId(Id tokenId) const
|
||||
{
|
||||
for (const Annotation& annotation : m_annotations)
|
||||
{
|
||||
if (annotation.locationType == LocationType::LOCATION_TOKEN && annotation.isActive)
|
||||
if (annotation.locationType == LocationType::LOCATION_TOKEN && annotation.isActive &&
|
||||
annotation.tokenIds.find(tokenId) != annotation.tokenIds.end())
|
||||
{
|
||||
if (annotation.tokenId == tokenId)
|
||||
{
|
||||
return annotation.locationId;
|
||||
}
|
||||
return annotation.locationId;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -525,7 +523,7 @@ void QtCodeArea::mouseReleaseEvent(QMouseEvent* event)
|
||||
}
|
||||
else
|
||||
{
|
||||
activateTokenLocations(annotations);
|
||||
activateSourceLocations(annotations);
|
||||
activateLocalSymbols(annotations);
|
||||
}
|
||||
}
|
||||
@@ -577,9 +575,9 @@ void QtCodeArea::mouseMoveEvent(QMouseEvent* event)
|
||||
|
||||
setHoveredAnnotations(annotations);
|
||||
|
||||
if (m_navigator->hasErrors() && annotations.size() == 1)
|
||||
if (m_navigator->hasErrors() && annotations.size() == 1 && annotations[0]->tokenIds.size())
|
||||
{
|
||||
std::string errorMessage = m_navigator->getErrorMessageForId(annotations[0]->tokenId);
|
||||
std::string errorMessage = m_navigator->getErrorMessageForId(*annotations[0]->tokenIds.begin());
|
||||
QToolTip::showText(event->globalPos(), QString::fromStdString(errorMessage));
|
||||
}
|
||||
}
|
||||
@@ -681,9 +679,9 @@ std::vector<const QtCodeArea::Annotation*> QtCodeArea::getInteractiveAnnotations
|
||||
return annotations;
|
||||
}
|
||||
|
||||
void QtCodeArea::activateTokenLocations(const std::vector<const Annotation*>& annotations)
|
||||
void QtCodeArea::activateSourceLocations(const std::vector<const Annotation*>& annotations)
|
||||
{
|
||||
std::vector<Id> tokenLocationIds;
|
||||
std::vector<Id> locationIds;
|
||||
std::set<Id> tokenIds;
|
||||
|
||||
bool allActive = true;
|
||||
@@ -698,20 +696,21 @@ void QtCodeArea::activateTokenLocations(const std::vector<const Annotation*>& an
|
||||
|
||||
if (annotation->locationId > 0)
|
||||
{
|
||||
tokenLocationIds.push_back(annotation->locationId);
|
||||
locationIds.push_back(annotation->locationId);
|
||||
}
|
||||
if (annotation->tokenId > 0)
|
||||
|
||||
if (annotation->tokenIds.size())
|
||||
{
|
||||
tokenIds.insert(annotation->tokenId);
|
||||
tokenIds.insert(annotation->tokenIds.begin(), annotation->tokenIds.end());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!allActive)
|
||||
{
|
||||
if (tokenLocationIds.size())
|
||||
if (locationIds.size())
|
||||
{
|
||||
MessageActivateTokenLocations(tokenLocationIds).dispatch();
|
||||
MessageActivateSourceLocations(locationIds).dispatch();
|
||||
}
|
||||
else if (tokenIds.size()) // fallback for links in project description
|
||||
{
|
||||
@@ -734,9 +733,9 @@ void QtCodeArea::activateLocalSymbols(const std::vector<const Annotation*>& anno
|
||||
allActive = false;
|
||||
}
|
||||
|
||||
if (annotation->tokenId > 0)
|
||||
if (annotation->tokenIds.size())
|
||||
{
|
||||
localSymbolIds.push_back(annotation->tokenId);
|
||||
localSymbolIds.insert(localSymbolIds.end(), annotation->tokenIds.begin(), annotation->tokenIds.end());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -752,9 +751,9 @@ void QtCodeArea::activateErrors(const std::vector<const Annotation*>& annotation
|
||||
std::vector<Id> errorIds;
|
||||
for (const Annotation* annotation : annotations)
|
||||
{
|
||||
if (annotation->locationType == LOCATION_ERROR && annotation->tokenId > 0)
|
||||
if (annotation->locationType == LOCATION_ERROR && annotation->tokenIds.size())
|
||||
{
|
||||
errorIds.push_back(annotation->tokenId);
|
||||
errorIds.insert(errorIds.end(), annotation->tokenIds.begin(), annotation->tokenIds.end());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -764,58 +763,61 @@ void QtCodeArea::activateErrors(const std::vector<const Annotation*>& annotation
|
||||
}
|
||||
}
|
||||
|
||||
void QtCodeArea::createAnnotations(std::shared_ptr<TokenLocationFile> locationFile)
|
||||
void QtCodeArea::createAnnotations(std::shared_ptr<SourceLocationFile> locationFile)
|
||||
{
|
||||
locationFile->forEachStartTokenLocation(
|
||||
[&](TokenLocation* startLocation)
|
||||
uint endLineNumber = getEndLineNumber();
|
||||
std::set<Id> locationIds;
|
||||
|
||||
locationFile->forEachSourceLocation(
|
||||
[&](const SourceLocation* location)
|
||||
{
|
||||
if (locationIds.find(location->getLocationId()) != locationIds.end())
|
||||
{
|
||||
return;
|
||||
}
|
||||
locationIds.insert(location->getLocationId());
|
||||
|
||||
Annotation annotation;
|
||||
uint endLineNumber = getEndLineNumber();
|
||||
if (startLocation->getLineNumber() <= endLineNumber)
|
||||
|
||||
const SourceLocation* startLocation = location->getStartLocation();
|
||||
if (!startLocation || startLocation->getLineNumber() < m_startLineNumber)
|
||||
{
|
||||
if (startLocation->getLineNumber() < m_startLineNumber)
|
||||
{
|
||||
annotation.start = startTextEditPosition();
|
||||
annotation.startLine = m_startLineNumber;
|
||||
annotation.startCol = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
annotation.start = toTextEditPosition(startLocation->getLineNumber(), startLocation->getColumnNumber() - 1);
|
||||
annotation.startLine = startLocation->getLineNumber();
|
||||
annotation.startCol = startLocation->getColumnNumber() - 1;
|
||||
}
|
||||
annotation.start = startTextEditPosition();
|
||||
annotation.startLine = m_startLineNumber;
|
||||
annotation.startCol = 0;
|
||||
}
|
||||
else if (startLocation->getLineNumber() <= endLineNumber)
|
||||
{
|
||||
annotation.start = toTextEditPosition(startLocation->getLineNumber(), startLocation->getColumnNumber() - 1);
|
||||
annotation.startLine = startLocation->getLineNumber();
|
||||
annotation.startCol = startLocation->getColumnNumber() - 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
TokenLocation* endLocation = startLocation->getEndTokenLocation();
|
||||
if (endLocation->getLineNumber() >= m_startLineNumber)
|
||||
const SourceLocation* endLocation = location->getEndLocation();
|
||||
if (!endLocation || endLocation->getLineNumber() > endLineNumber)
|
||||
{
|
||||
if (endLocation->getLineNumber() > endLineNumber)
|
||||
{
|
||||
annotation.end = endTextEditPosition();
|
||||
annotation.endLine = endLineNumber;
|
||||
annotation.endCol = m_lineLengths[document()->blockCount() - 1];
|
||||
}
|
||||
else
|
||||
{
|
||||
annotation.end = toTextEditPosition(endLocation->getLineNumber(), endLocation->getColumnNumber());
|
||||
annotation.endLine = endLocation->getLineNumber();
|
||||
annotation.endCol = endLocation->getColumnNumber();
|
||||
}
|
||||
annotation.end = endTextEditPosition();
|
||||
annotation.endLine = endLineNumber;
|
||||
annotation.endCol = m_lineLengths[document()->blockCount() - 1];
|
||||
}
|
||||
else if (endLocation->getLineNumber() >= m_startLineNumber)
|
||||
{
|
||||
annotation.end = toTextEditPosition(endLocation->getLineNumber(), endLocation->getColumnNumber());
|
||||
annotation.endLine = endLocation->getLineNumber();
|
||||
annotation.endCol = endLocation->getColumnNumber();
|
||||
}
|
||||
else
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
annotation.tokenId = startLocation->getTokenId();
|
||||
annotation.locationId = startLocation->getId();
|
||||
|
||||
annotation.locationType = startLocation->getType();
|
||||
annotation.tokenIds.insert(location->getTokenIds().begin(), location->getTokenIds().end());
|
||||
annotation.locationId = location->getLocationId();
|
||||
annotation.locationType = location->getType();
|
||||
|
||||
annotation.isActive = false;
|
||||
annotation.isFocused = false;
|
||||
@@ -827,12 +829,12 @@ void QtCodeArea::createAnnotations(std::shared_ptr<TokenLocationFile> locationFi
|
||||
|
||||
void QtCodeArea::annotateText()
|
||||
{
|
||||
const std::vector<Id>& currentActiveTokenIds = m_navigator->getCurrentActiveTokenIds();
|
||||
const std::vector<Id>& currentActiveLocationIds = m_navigator->getCurrentActiveLocationIds();
|
||||
const std::set<Id>& currentActiveTokenIds = m_navigator->getCurrentActiveTokenIds();
|
||||
const std::set<Id>& currentActiveLocationIds = m_navigator->getCurrentActiveLocationIds();
|
||||
|
||||
const std::vector<Id>& activeTokenIds = m_navigator->getActiveTokenIds();
|
||||
const std::vector<Id>& activeLocalSymbolIds = m_navigator->getActiveLocalSymbolIds();
|
||||
const std::vector<Id>& focusIds = m_navigator->getFocusedTokenIds();
|
||||
const std::set<Id>& activeTokenIds = m_navigator->getActiveTokenIds();
|
||||
const std::set<Id>& activeLocalSymbolIds = m_navigator->getActiveLocalSymbolIds();
|
||||
const std::set<Id>& focusIds = m_navigator->getFocusedTokenIds();
|
||||
|
||||
bool needsUpdate = false;
|
||||
for (Annotation& annotation: m_annotations)
|
||||
@@ -842,15 +844,16 @@ void QtCodeArea::annotateText()
|
||||
const AnnotationColor& oldColor = getAnnotationColorForAnnotation(annotation);
|
||||
|
||||
annotation.isActive = (
|
||||
std::find(currentActiveTokenIds.begin(), currentActiveTokenIds.end(), annotation.tokenId) != currentActiveTokenIds.end() ||
|
||||
std::find(currentActiveLocationIds.begin(), currentActiveLocationIds.end(), annotation.locationId) != currentActiveLocationIds.end() ||
|
||||
std::find(activeLocalSymbolIds.begin(), activeLocalSymbolIds.end(), annotation.tokenId) != activeLocalSymbolIds.end()
|
||||
utility::shareElement(currentActiveTokenIds, annotation.tokenIds) ||
|
||||
utility::shareElement(activeLocalSymbolIds, annotation.tokenIds) ||
|
||||
currentActiveLocationIds.find(annotation.locationId) != currentActiveLocationIds.end()
|
||||
);
|
||||
|
||||
if (!annotation.isActive)
|
||||
{
|
||||
annotation.isFocused = (
|
||||
std::find(focusIds.begin(), focusIds.end(), annotation.tokenId) != focusIds.end() ||
|
||||
std::find(activeTokenIds.begin(), activeTokenIds.end(), annotation.tokenId) != activeTokenIds.end()
|
||||
utility::shareElement(focusIds, annotation.tokenIds) ||
|
||||
utility::shareElement(activeTokenIds, annotation.tokenIds)
|
||||
);
|
||||
}
|
||||
|
||||
@@ -862,7 +865,7 @@ void QtCodeArea::annotateText()
|
||||
bool isDuplicateAnnotation = false;
|
||||
for (Annotation* a : m_colorChangedAnnotations)
|
||||
{
|
||||
if (a->start == annotation.start && a->end == annotation.end && a->tokenId != annotation.tokenId)
|
||||
if (a->start == annotation.start && a->end == annotation.end && a->locationId != annotation.locationId)
|
||||
{
|
||||
isDuplicateAnnotation = true;
|
||||
break;
|
||||
@@ -909,7 +912,7 @@ void QtCodeArea::setHoveredAnnotations(const std::vector<const Annotation*>& ann
|
||||
std::vector<Id> tokenIds;
|
||||
for (const Annotation* annotation : m_hoveredAnnotations)
|
||||
{
|
||||
tokenIds.push_back(annotation->tokenId);
|
||||
tokenIds.insert(tokenIds.end(), annotation->tokenIds.begin(), annotation->tokenIds.end());
|
||||
}
|
||||
|
||||
MessageFocusOut(tokenIds).dispatch();
|
||||
@@ -922,7 +925,7 @@ void QtCodeArea::setHoveredAnnotations(const std::vector<const Annotation*>& ann
|
||||
std::vector<Id> tokenIds;
|
||||
for (const Annotation* annotation : annotations)
|
||||
{
|
||||
tokenIds.push_back(annotation->tokenId);
|
||||
tokenIds.insert(tokenIds.end(), annotation->tokenIds.begin(), annotation->tokenIds.end());
|
||||
}
|
||||
|
||||
MessageFocusIn(tokenIds).dispatch();
|
||||
|
||||
@@ -18,8 +18,8 @@ class QSize;
|
||||
class QtCodeNavigator;
|
||||
class QtHighlighter;
|
||||
class QWidget;
|
||||
class TokenLocation;
|
||||
class TokenLocationFile;
|
||||
class SourceLocation;
|
||||
class SourceLocationFile;
|
||||
|
||||
|
||||
class MouseWheelOverScrollbarFilter
|
||||
@@ -62,7 +62,7 @@ public:
|
||||
QtCodeArea(
|
||||
uint startLineNumber,
|
||||
const std::string& code,
|
||||
std::shared_ptr<TokenLocationFile> locationFile,
|
||||
std::shared_ptr<SourceLocationFile> locationFile,
|
||||
QtCodeNavigator* navigator,
|
||||
QWidget* parent = nullptr
|
||||
);
|
||||
@@ -73,7 +73,7 @@ public:
|
||||
uint getStartLineNumber() const;
|
||||
uint getEndLineNumber() const;
|
||||
|
||||
std::shared_ptr<TokenLocationFile> getTokenLocationFile() const;
|
||||
std::shared_ptr<SourceLocationFile> getSourceLocationFile() const;
|
||||
|
||||
void lineNumberAreaPaintEvent(QPaintEvent* event);
|
||||
int lineNumberDigits() const;
|
||||
@@ -127,7 +127,7 @@ private:
|
||||
int start;
|
||||
int end;
|
||||
|
||||
Id tokenId;
|
||||
std::set<Id> tokenIds;
|
||||
Id locationId;
|
||||
|
||||
LocationType locationType;
|
||||
@@ -146,11 +146,11 @@ private:
|
||||
};
|
||||
|
||||
std::vector<const Annotation*> getInteractiveAnnotationsForPosition(int pos) const;
|
||||
void activateTokenLocations(const std::vector<const Annotation*>& annotations);
|
||||
void activateSourceLocations(const std::vector<const Annotation*>& annotations);
|
||||
void activateLocalSymbols(const std::vector<const Annotation*>& annotations);
|
||||
void activateErrors(const std::vector<const Annotation*>& annotations);
|
||||
|
||||
void createAnnotations(std::shared_ptr<TokenLocationFile> locationFile);
|
||||
void createAnnotations(std::shared_ptr<SourceLocationFile> locationFile);
|
||||
void annotateText();
|
||||
|
||||
void setHoveredAnnotations(const std::vector<const Annotation*>& annotations);
|
||||
@@ -180,7 +180,7 @@ private:
|
||||
const uint m_startLineNumber;
|
||||
const std::string m_code;
|
||||
|
||||
std::shared_ptr<TokenLocationFile> m_locationFile;
|
||||
std::shared_ptr<SourceLocationFile> m_locationFile;
|
||||
|
||||
std::vector<Annotation> m_annotations;
|
||||
std::vector<const Annotation*> m_hoveredAnnotations;
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
|
||||
#include "utility/messaging/type/MessageChangeFileView.h"
|
||||
|
||||
#include "data/location/TokenLocationFile.h"
|
||||
#include "data/location/SourceLocationFile.h"
|
||||
#include "qt/element/QtCodeFileTitleButton.h"
|
||||
#include "qt/element/QtCodeNavigator.h"
|
||||
#include "qt/element/QtCodeSnippet.h"
|
||||
@@ -120,7 +120,7 @@ QtCodeSnippet* QtCodeFile::addCodeSnippet(const CodeSnippetParams& params)
|
||||
|
||||
m_snippetLayout->addWidget(snippet.get());
|
||||
|
||||
if (params.locationFile->isWholeCopy)
|
||||
if (params.locationFile->isWhole())
|
||||
{
|
||||
snippet->setProperty("isFirst", true);
|
||||
snippet->setProperty("isLast", true);
|
||||
@@ -186,7 +186,6 @@ QtCodeSnippet* QtCodeFile::insertCodeSnippet(const CodeSnippetParams& params)
|
||||
m_snippets.insert(m_snippets.begin() + i, snippet);
|
||||
|
||||
setSnippets();
|
||||
updateRefCount(params.refCount);
|
||||
|
||||
return snippet.get();
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
|
||||
#include "utility/file/FileSystem.h"
|
||||
|
||||
#include "data/location/TokenLocationFile.h"
|
||||
#include "data/location/SourceLocationFile.h"
|
||||
#include "qt/element/QtCodeFile.h"
|
||||
#include "qt/element/QtCodeNavigator.h"
|
||||
#include "qt/element/QtCodeSnippet.h"
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
#include "utility/messaging/type/MessageChangeFileView.h"
|
||||
#include "utility/ResourcePaths.h"
|
||||
|
||||
#include "data/location/TokenLocationFile.h"
|
||||
#include "data/location/SourceLocationFile.h"
|
||||
#include "qt/element/QtCodeArea.h"
|
||||
#include "qt/element/QtCodeFileTitleButton.h"
|
||||
#include "qt/element/QtCodeNavigator.h"
|
||||
@@ -86,7 +86,7 @@ void QtCodeFileSingle::clearCache()
|
||||
|
||||
void QtCodeFileSingle::addCodeSnippet(const CodeSnippetParams& params, bool insert)
|
||||
{
|
||||
if (!params.locationFile->isWholeCopy)
|
||||
if (!params.locationFile->isWhole())
|
||||
{
|
||||
LOG_ERROR("Snippet params passed are not for whole file.");
|
||||
return;
|
||||
|
||||
@@ -12,9 +12,9 @@
|
||||
#include "utility/messaging/type/MessageScrollCode.h"
|
||||
#include "utility/ResourcePaths.h"
|
||||
|
||||
#include "data/location/TokenLocation.h"
|
||||
#include "data/location/TokenLocationCollection.h"
|
||||
#include "data/location/TokenLocationFile.h"
|
||||
#include "data/location/SourceLocation.h"
|
||||
#include "data/location/SourceLocationCollection.h"
|
||||
#include "data/location/SourceLocationFile.h"
|
||||
#include "qt/element/QtCodeFile.h"
|
||||
#include "qt/element/QtCodeSnippet.h"
|
||||
#include "qt/utility/QtDeviceScaledPixmap.h"
|
||||
@@ -25,6 +25,7 @@
|
||||
QtCodeNavigator::QtCodeNavigator(QWidget* parent)
|
||||
: QWidget(parent)
|
||||
, m_mode(MODE_NONE)
|
||||
, m_activeTokenId(0)
|
||||
, m_value(0)
|
||||
, m_refIndex(0)
|
||||
, m_singleHasNewFile(false)
|
||||
@@ -149,34 +150,33 @@ void QtCodeNavigator::addCodeSnippet(const CodeSnippetParams& params, bool inser
|
||||
}
|
||||
}
|
||||
|
||||
void QtCodeNavigator::addFile(std::shared_ptr<TokenLocationFile> locationFile, int refCount, TimePoint modificationTime)
|
||||
void QtCodeNavigator::addFile(std::shared_ptr<SourceLocationFile> locationFile, int refCount, TimePoint modificationTime)
|
||||
{
|
||||
m_list->addFile(locationFile->getFilePath(), locationFile->isWholeCopy, refCount, modificationTime);
|
||||
m_list->addFile(locationFile->getFilePath(), locationFile->isWhole(), refCount, modificationTime);
|
||||
|
||||
if (locationFile->isWholeCopy)
|
||||
if (locationFile->isWhole())
|
||||
{
|
||||
Reference ref;
|
||||
ref.filePath = locationFile->getFilePath();
|
||||
ref.tokenId = 0;
|
||||
ref.locationId = 0;
|
||||
ref.locationType = LOCATION_TOKEN;
|
||||
|
||||
m_references.push_back(ref);
|
||||
}
|
||||
else
|
||||
{
|
||||
locationFile->forEachStartTokenLocation(
|
||||
[&](TokenLocation* location)
|
||||
locationFile->forEachStartSourceLocation(
|
||||
[&](SourceLocation* location)
|
||||
{
|
||||
if (!location->isScopeTokenLocation())
|
||||
if (!location->isScopeLocation())
|
||||
{
|
||||
Reference ref;
|
||||
ref.filePath = location->getFilePath();
|
||||
ref.tokenId = location->getTokenId();
|
||||
ref.locationId = location->getId();
|
||||
ref.locationType = location->getType();
|
||||
for (Id i : location->getTokenIds())
|
||||
{
|
||||
Reference ref;
|
||||
ref.filePath = location->getFilePath();
|
||||
ref.tokenId = i;
|
||||
ref.locationId = location->getLocationId();
|
||||
ref.locationType = location->getType();
|
||||
|
||||
m_references.push_back(ref);
|
||||
m_references.push_back(ref);
|
||||
}
|
||||
}
|
||||
}
|
||||
);
|
||||
@@ -207,6 +207,8 @@ void QtCodeNavigator::clearCodeSnippets()
|
||||
m_focusedTokenIds.clear();
|
||||
m_errorInfos.clear();
|
||||
|
||||
m_activeTokenId = 0;
|
||||
|
||||
if (m_references.size() && m_references[0].locationType != LOCATION_TOKEN)
|
||||
{
|
||||
clearCaches();
|
||||
@@ -224,29 +226,29 @@ void QtCodeNavigator::clearCaches()
|
||||
m_single->clearCache();
|
||||
}
|
||||
|
||||
const std::vector<Id>& QtCodeNavigator::getCurrentActiveTokenIds() const
|
||||
const std::set<Id>& QtCodeNavigator::getCurrentActiveTokenIds() const
|
||||
{
|
||||
return m_currentActiveTokenIds;
|
||||
}
|
||||
|
||||
void QtCodeNavigator::setCurrentActiveTokenIds(const std::vector<Id>& currentActiveTokenIds)
|
||||
{
|
||||
m_currentActiveTokenIds = currentActiveTokenIds;
|
||||
m_currentActiveTokenIds = std::set<Id>(currentActiveTokenIds.begin(), currentActiveTokenIds.end());
|
||||
m_currentActiveLocationIds.clear();
|
||||
}
|
||||
|
||||
const std::vector<Id>& QtCodeNavigator::getCurrentActiveLocationIds() const
|
||||
const std::set<Id>& QtCodeNavigator::getCurrentActiveLocationIds() const
|
||||
{
|
||||
return m_currentActiveLocationIds;
|
||||
}
|
||||
|
||||
void QtCodeNavigator::setCurrentActiveLocationIds(const std::vector<Id>& currentActiveLocationIds)
|
||||
{
|
||||
m_currentActiveLocationIds = currentActiveLocationIds;
|
||||
m_currentActiveLocationIds = std::set<Id>(currentActiveLocationIds.begin(), currentActiveLocationIds.end());
|
||||
m_currentActiveTokenIds.clear();
|
||||
}
|
||||
|
||||
const std::vector<Id>& QtCodeNavigator::getActiveTokenIds() const
|
||||
const std::set<Id>& QtCodeNavigator::getActiveTokenIds() const
|
||||
{
|
||||
return m_activeTokenIds;
|
||||
}
|
||||
@@ -255,28 +257,30 @@ void QtCodeNavigator::setActiveTokenIds(const std::vector<Id>& activeTokenIds)
|
||||
{
|
||||
setCurrentActiveTokenIds(activeTokenIds);
|
||||
|
||||
m_activeTokenIds = activeTokenIds;
|
||||
m_activeTokenIds = std::set<Id>(activeTokenIds.begin(), activeTokenIds.end());
|
||||
m_activeTokenId = activeTokenIds.size() ? activeTokenIds[0] : 0;
|
||||
|
||||
m_activeLocalSymbolIds.clear();
|
||||
}
|
||||
|
||||
const std::vector<Id>& QtCodeNavigator::getActiveLocalSymbolIds() const
|
||||
const std::set<Id>& QtCodeNavigator::getActiveLocalSymbolIds() const
|
||||
{
|
||||
return m_activeLocalSymbolIds;
|
||||
}
|
||||
|
||||
void QtCodeNavigator::setActiveLocalSymbolIds(const std::vector<Id>& activeLocalSymbolIds)
|
||||
{
|
||||
m_activeLocalSymbolIds = activeLocalSymbolIds;
|
||||
m_activeLocalSymbolIds = std::set<Id>(activeLocalSymbolIds.begin(), activeLocalSymbolIds.end());
|
||||
}
|
||||
|
||||
const std::vector<Id>& QtCodeNavigator::getFocusedTokenIds() const
|
||||
const std::set<Id>& QtCodeNavigator::getFocusedTokenIds() const
|
||||
{
|
||||
return m_focusedTokenIds;
|
||||
}
|
||||
|
||||
void QtCodeNavigator::setFocusedTokenIds(const std::vector<Id>& focusedTokenIds)
|
||||
{
|
||||
m_focusedTokenIds = focusedTokenIds;
|
||||
m_focusedTokenIds = std::set<Id>(focusedTokenIds.begin(), focusedTokenIds.end());
|
||||
}
|
||||
|
||||
std::string QtCodeNavigator::getErrorMessageForId(Id errorId) const
|
||||
@@ -326,7 +330,7 @@ bool QtCodeNavigator::isInListMode() const
|
||||
}
|
||||
|
||||
void QtCodeNavigator::showActiveSnippet(
|
||||
const std::vector<Id>& activeTokenIds, std::shared_ptr<TokenLocationCollection> collection, bool scrollTo)
|
||||
const std::vector<Id>& activeTokenIds, std::shared_ptr<SourceLocationCollection> collection, bool scrollTo)
|
||||
{
|
||||
if (activeTokenIds.size() != 1)
|
||||
{
|
||||
@@ -363,21 +367,31 @@ void QtCodeNavigator::showActiveSnippet(
|
||||
std::set<FilePath> filePathsToExpand;
|
||||
if (!locationIds.size())
|
||||
{
|
||||
collection->forEachTokenLocation(
|
||||
[&](TokenLocation* location)
|
||||
collection->forEachSourceLocation(
|
||||
[&](SourceLocation* location)
|
||||
{
|
||||
if (location->getTokenId() != tokenId)
|
||||
bool foundId = false;
|
||||
for (Id i : location->getTokenIds())
|
||||
{
|
||||
if (i == tokenId)
|
||||
{
|
||||
foundId = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!foundId)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
locationIds.push_back(location->getId());
|
||||
locationIds.push_back(location->getLocationId());
|
||||
filePathsToExpand.insert(location->getFilePath());
|
||||
|
||||
if (!firstReference.tokenId || filePathOrder[location->getFilePath()] < filePathOrder[firstReference.filePath])
|
||||
{
|
||||
firstReference.tokenId = location->getTokenId();
|
||||
firstReference.locationId = location->getId();
|
||||
firstReference.tokenId = tokenId;
|
||||
firstReference.locationId = location->getLocationId();
|
||||
firstReference.filePath = location->getFilePath();
|
||||
}
|
||||
}
|
||||
@@ -534,6 +548,7 @@ void QtCodeNavigator::scrollToValue(int value, bool inListMode)
|
||||
void QtCodeNavigator::scrollToLine(const FilePath& filePath, unsigned int line)
|
||||
{
|
||||
requestScroll(filePath, line, 0, false, false);
|
||||
emit scrollRequest();
|
||||
}
|
||||
|
||||
void QtCodeNavigator::scrollToDefinition(bool ignoreActiveReference)
|
||||
@@ -565,16 +580,14 @@ void QtCodeNavigator::scrollToDefinition(bool ignoreActiveReference)
|
||||
return;
|
||||
}
|
||||
|
||||
if (!m_activeTokenIds.size())
|
||||
if (!m_activeTokenId)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Id tokenId = m_activeTokenIds[0]; // The first active tokenId is the one of the active symbol itself.
|
||||
|
||||
if (m_mode == MODE_LIST)
|
||||
{
|
||||
std::pair<QtCodeSnippet*, uint> result = m_list->getFirstSnippetWithActiveLocation(tokenId);
|
||||
std::pair<QtCodeSnippet*, uint> result = m_list->getFirstSnippetWithActiveLocation(m_activeTokenId);
|
||||
if (result.first != nullptr)
|
||||
{
|
||||
requestScroll(result.first->getFile()->getFilePath(), result.second, 0, false, true);
|
||||
@@ -583,7 +596,7 @@ void QtCodeNavigator::scrollToDefinition(bool ignoreActiveReference)
|
||||
}
|
||||
else
|
||||
{
|
||||
Id locationId = m_single->getLocationIdOfFirstActiveLocationOfTokenId(tokenId);
|
||||
Id locationId = m_single->getLocationIdOfFirstActiveLocationOfTokenId(m_activeTokenId);
|
||||
if (locationId)
|
||||
{
|
||||
for (size_t i = 0; i < m_references.size(); i++)
|
||||
@@ -630,6 +643,9 @@ void QtCodeNavigator::requestScroll(const FilePath& filePath, uint lineNumber, I
|
||||
}
|
||||
}
|
||||
|
||||
// std::cout << "scroll request: " << req.filePath.str() << " " << req.lineNumber << " " << req.locationId;
|
||||
// std::cout << " " << req.animated << " " << req.onTop << std::endl;
|
||||
|
||||
m_scrollRequest = req;
|
||||
|
||||
m_singleHasNewFile = false;
|
||||
|
||||
@@ -17,8 +17,8 @@
|
||||
|
||||
class QLabel;
|
||||
class QPushButton;
|
||||
class TokenLocationCollection;
|
||||
class TokenLocationFile;
|
||||
class SourceLocationCollection;
|
||||
class SourceLocationFile;
|
||||
|
||||
class QtCodeNavigator
|
||||
: public QWidget
|
||||
@@ -35,7 +35,7 @@ public:
|
||||
virtual ~QtCodeNavigator();
|
||||
|
||||
void addCodeSnippet(const CodeSnippetParams& params, bool insert = false);
|
||||
void addFile(std::shared_ptr<TokenLocationFile> locationFile, int refCount, TimePoint modificationTime);
|
||||
void addFile(std::shared_ptr<SourceLocationFile> locationFile, int refCount, TimePoint modificationTime);
|
||||
|
||||
void addedFiles();
|
||||
|
||||
@@ -43,19 +43,19 @@ public:
|
||||
void clearCodeSnippets();
|
||||
void clearCaches();
|
||||
|
||||
const std::vector<Id>& getCurrentActiveTokenIds() const;
|
||||
const std::set<Id>& getCurrentActiveTokenIds() const;
|
||||
void setCurrentActiveTokenIds(const std::vector<Id>& currentActiveTokenIds);
|
||||
|
||||
const std::vector<Id>& getCurrentActiveLocationIds() const;
|
||||
const std::set<Id>& getCurrentActiveLocationIds() const;
|
||||
void setCurrentActiveLocationIds(const std::vector<Id>& currentActiveLocationIds);
|
||||
|
||||
const std::vector<Id>& getActiveTokenIds() const;
|
||||
const std::set<Id>& getActiveTokenIds() const;
|
||||
void setActiveTokenIds(const std::vector<Id>& activeTokenIds);
|
||||
|
||||
const std::vector<Id>& getActiveLocalSymbolIds() const;
|
||||
const std::set<Id>& getActiveLocalSymbolIds() const;
|
||||
void setActiveLocalSymbolIds(const std::vector<Id>& activeLocalSymbolIds);
|
||||
|
||||
const std::vector<Id>& getFocusedTokenIds() const;
|
||||
const std::set<Id>& getFocusedTokenIds() const;
|
||||
void setFocusedTokenIds(const std::vector<Id>& focusedTokenIds);
|
||||
|
||||
std::string getErrorMessageForId(Id errorId) const;
|
||||
@@ -67,7 +67,7 @@ public:
|
||||
bool isInListMode() const;
|
||||
|
||||
void showActiveSnippet(
|
||||
const std::vector<Id>& activeTokenIds, std::shared_ptr<TokenLocationCollection> collection, bool scrollTo);
|
||||
const std::vector<Id>& activeTokenIds, std::shared_ptr<SourceLocationCollection> collection, bool scrollTo);
|
||||
|
||||
void focusTokenIds(const std::vector<Id>& focusedTokenIds);
|
||||
void defocusTokenIds();
|
||||
@@ -119,6 +119,7 @@ private:
|
||||
Reference()
|
||||
: tokenId(0)
|
||||
, locationId(0)
|
||||
, locationType(LOCATION_TOKEN)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -163,14 +164,16 @@ private:
|
||||
|
||||
Mode m_mode;
|
||||
|
||||
std::vector<Id> m_currentActiveTokenIds;
|
||||
std::vector<Id> m_currentActiveLocationIds;
|
||||
std::set<Id> m_currentActiveTokenIds;
|
||||
std::set<Id> m_currentActiveLocationIds;
|
||||
|
||||
std::vector<Id> m_activeTokenIds;
|
||||
std::vector<Id> m_activeLocalSymbolIds;
|
||||
std::vector<Id> m_focusedTokenIds;
|
||||
std::set<Id> m_activeTokenIds;
|
||||
std::set<Id> m_activeLocalSymbolIds;
|
||||
std::set<Id> m_focusedTokenIds;
|
||||
std::map<Id, ErrorInfo> m_errorInfos;
|
||||
|
||||
Id m_activeTokenId;
|
||||
|
||||
int m_value;
|
||||
|
||||
QPushButton* m_listButton;
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
#include "utility/messaging/type/MessageShowScope.h"
|
||||
#include "utility/text/TextAccess.h"
|
||||
|
||||
#include "data/location/TokenLocationFile.h"
|
||||
#include "data/location/SourceLocationFile.h"
|
||||
#include "qt/element/QtCodeNavigator.h"
|
||||
#include "qt/element/QtCodeFile.h"
|
||||
|
||||
@@ -17,22 +17,22 @@ std::shared_ptr<QtCodeSnippet> QtCodeSnippet::merged(
|
||||
QtCodeSnippet* first = a->getStartLineNumber() < b->getStartLineNumber() ? a : b;
|
||||
QtCodeSnippet* second = a->getStartLineNumber() > b->getStartLineNumber() ? a : b;
|
||||
|
||||
TokenLocationFile* aFile = a->m_codeArea->getTokenLocationFile().get();
|
||||
TokenLocationFile* bFile = b->m_codeArea->getTokenLocationFile().get();
|
||||
SourceLocationFile* aFile = a->m_codeArea->getSourceLocationFile().get();
|
||||
SourceLocationFile* bFile = b->m_codeArea->getSourceLocationFile().get();
|
||||
|
||||
std::shared_ptr<TokenLocationFile> locationFile = std::make_shared<TokenLocationFile>(aFile->getFilePath());
|
||||
std::shared_ptr<SourceLocationFile> locationFile = std::make_shared<SourceLocationFile>(aFile->getFilePath(), aFile->isWhole());
|
||||
|
||||
aFile->forEachTokenLocation(
|
||||
[&locationFile](TokenLocation* loc)
|
||||
aFile->forEachSourceLocation(
|
||||
[&locationFile](SourceLocation* loc)
|
||||
{
|
||||
locationFile->addTokenLocationAsPlainCopy(loc);
|
||||
locationFile->addSourceLocationCopy(loc);
|
||||
}
|
||||
);
|
||||
|
||||
bFile->forEachTokenLocation(
|
||||
[&locationFile](TokenLocation* loc)
|
||||
bFile->forEachSourceLocation(
|
||||
[&locationFile](SourceLocation* loc)
|
||||
{
|
||||
locationFile->addTokenLocationAsPlainCopy(loc);
|
||||
locationFile->addSourceLocationCopy(loc);
|
||||
}
|
||||
);
|
||||
|
||||
|
||||
@@ -16,7 +16,7 @@ class QBoxLayout;
|
||||
class QPushButton;
|
||||
class QtCodeFile;
|
||||
class QtCodeNavigator;
|
||||
class TokenLocationFile;
|
||||
class SourceLocationFile;
|
||||
|
||||
class QtCodeSnippet
|
||||
: public QFrame
|
||||
|
||||
@@ -105,7 +105,7 @@ void QtCodeView::setFileState(const FilePath filePath, FileState state)
|
||||
}
|
||||
|
||||
void QtCodeView::showActiveSnippet(
|
||||
const std::vector<Id>& activeTokenIds, std::shared_ptr<TokenLocationCollection> collection, bool scrollTo)
|
||||
const std::vector<Id>& activeTokenIds, std::shared_ptr<SourceLocationCollection> collection, bool scrollTo)
|
||||
{
|
||||
m_doShowActiveSnippetFunctor(activeTokenIds, collection, scrollTo);
|
||||
}
|
||||
@@ -241,7 +241,7 @@ void QtCodeView::doSetFileState(const FilePath filePath, FileState state)
|
||||
}
|
||||
|
||||
void QtCodeView::doShowActiveSnippet(
|
||||
const std::vector<Id>& activeTokenIds, std::shared_ptr<TokenLocationCollection> collection, bool scrollTo)
|
||||
const std::vector<Id>& activeTokenIds, std::shared_ptr<SourceLocationCollection> collection, bool scrollTo)
|
||||
{
|
||||
m_widget->showActiveSnippet(activeTokenIds, collection, scrollTo);
|
||||
}
|
||||
|
||||
@@ -39,7 +39,7 @@ public:
|
||||
virtual void setFileState(const FilePath filePath, FileState state);
|
||||
|
||||
virtual void showActiveSnippet(
|
||||
const std::vector<Id>& activeTokenIds, std::shared_ptr<TokenLocationCollection> collection, bool scrollTo);
|
||||
const std::vector<Id>& activeTokenIds, std::shared_ptr<SourceLocationCollection> collection, bool scrollTo);
|
||||
virtual void showActiveTokenIds(const std::vector<Id>& activeTokenIds);
|
||||
virtual void showActiveLocalSymbolIds(const std::vector<Id>& activeLocalSymbolIds);
|
||||
|
||||
@@ -62,7 +62,7 @@ private:
|
||||
void doSetFileState(const FilePath filePath, FileState state);
|
||||
|
||||
void doShowActiveSnippet(
|
||||
const std::vector<Id>& activeTokenIds, std::shared_ptr<TokenLocationCollection> collection, bool scrollTo);
|
||||
const std::vector<Id>& activeTokenIds, std::shared_ptr<SourceLocationCollection> collection, bool scrollTo);
|
||||
void doShowActiveTokenIds(const std::vector<Id>& activeTokenIds);
|
||||
void doShowActiveLocalSymbolIds(const std::vector<Id>& localSymbolIds);
|
||||
|
||||
@@ -73,7 +73,7 @@ private:
|
||||
QtThreadedFunctor<const std::vector<CodeSnippetParams>&, const std::vector<Id>&, bool> m_showCodeSnippetsFunctor;
|
||||
QtThreadedFunctor<const std::vector<CodeSnippetParams>&, bool> m_addCodeSnippetsFunctor;
|
||||
QtThreadedFunctor<const FilePath, FileState> m_setFileStateFunctor;
|
||||
QtThreadedFunctor<const std::vector<Id>&, std::shared_ptr<TokenLocationCollection>, bool> m_doShowActiveSnippetFunctor;
|
||||
QtThreadedFunctor<const std::vector<Id>&, std::shared_ptr<SourceLocationCollection>, bool> m_doShowActiveSnippetFunctor;
|
||||
QtThreadedFunctor<const std::vector<Id>&> m_doShowActiveTokenIdsFunctor;
|
||||
QtThreadedFunctor<const std::vector<Id>&> m_doShowActiveLocalSymbolIdsFunctor;
|
||||
QtThreadedFunctor<const std::vector<Id>&> m_focusTokenIdsFunctor;
|
||||
|
||||
Reference in New Issue
Block a user