ui: Refactored code component to handle all state changes in controller

This commit is contained in:
Eberhard Graether
2019-11-08 16:20:43 +01:00
parent 9d556599ab
commit 9281c237a7
32 changed files with 1542 additions and 1985 deletions
@@ -13,7 +13,6 @@ TicTacToe::~TicTacToe() {
Reset();
}
bool TicTacToe::Start() {
Reset();
io::stringOut("Tic Tac Toe\n\n[1] Human\n[2] Computer\n[3] Quit\n\n");
+1
View File
@@ -65,6 +65,7 @@ add_files(
component/controller/UndoRedoController.cpp
component/controller/UndoRedoController.h
component/view/helper/CodeScrollParams.h
component/view/helper/CodeSnippetParams.cpp
component/view/helper/CodeSnippetParams.h
component/view/BookmarkButtonsView.cpp
@@ -60,8 +60,7 @@ void ActivationController::handleMessage(MessageActivateFile* message)
message->filePath,
MessageChangeFileView::FILE_MAXIMIZED,
MessageChangeFileView::VIEW_CURRENT,
true,
true
CodeScrollParams::toFile(message->filePath, CodeScrollParams::Target::VISIBLE)
);
msg.setSchedulerId(message->getSchedulerId());
msg.dispatchImmediately();
File diff suppressed because it is too large Load Diff
+55 -10
View File
@@ -5,8 +5,10 @@
#include <string>
#include "FilePath.h"
#include "LocationType.h"
#include "MessageListener.h"
#include "MessageActivateLegend.h"
#include "MessageCodeReference.h"
#include "MessageCodeShowDefinition.h"
#include "MessageActivateErrors.h"
#include "MessageErrorCountClear.h"
@@ -24,6 +26,7 @@
#include "MessageFocusOut.h"
#include "MessageScrollCode.h"
#include "MessageScrollToLine.h"
#include "MessageShowReference.h"
#include "MessageShowScope.h"
#include "types.h"
@@ -47,6 +50,7 @@ class CodeController
, public MessageListener<MessageActivateTrail>
, public MessageListener<MessageActivateTrailEdge>
, public MessageListener<MessageChangeFileView>
, public MessageListener<MessageCodeReference>
, public MessageListener<MessageCodeShowDefinition>
, public MessageListener<MessageDeactivateEdge>
, public MessageListener<MessageErrorCountClear>
@@ -56,6 +60,7 @@ class CodeController
, public MessageListener<MessageScrollCode>
, public MessageListener<MessageScrollToLine>
, public MessageListener<MessageShowError>
, public MessageListener<MessageShowReference>
, public MessageListener<MessageShowScope>
{
public:
@@ -65,6 +70,15 @@ public:
Id getSchedulerId() const override;
private:
struct Reference
{
FilePath filePath;
Id tokenId = 0;
Id locationId = 0;
Id scopeLocationId = 0;
LocationType locationType = LOCATION_TOKEN;
};
void handleMessage(MessageActivateErrors* message) override;
void handleMessage(MessageActivateFullTextSearch* message) override;
void handleMessage(MessageActivateLegend* message) override;
@@ -74,6 +88,7 @@ private:
void handleMessage(MessageActivateTrail* message) override;
void handleMessage(MessageActivateTrailEdge* message) override;
void handleMessage(MessageChangeFileView* message) override;
void handleMessage(MessageCodeReference* message) override;
void handleMessage(MessageCodeShowDefinition* message) override;
void handleMessage(MessageDeactivateEdge* message) override;
void handleMessage(MessageErrorCountClear* message) override;
@@ -83,17 +98,18 @@ private:
void handleMessage(MessageScrollCode* message) override;
void handleMessage(MessageScrollToLine* message) override;
void handleMessage(MessageShowError* message) override;
void handleMessage(MessageShowReference* message) override;
void handleMessage(MessageShowScope* message) override;
CodeView* getView() const;
void clear() override;
std::vector<CodeSnippetParams> getSnippetsForFileWithState(const FilePath& filePath, CodeView::FileState state) const;
std::vector<CodeSnippetParams> getSnippetsForActiveSourceLocations(
std::vector<CodeFileParams> getFilesForActiveSourceLocations(
const SourceLocationCollection* collection, Id declarationId) const;
std::vector<CodeSnippetParams> getSnippetsForCollection(std::shared_ptr<SourceLocationCollection> collection) const;
std::vector<CodeSnippetParams> getSnippetsForFile(std::shared_ptr<SourceLocationFile> file) const;
std::vector<CodeFileParams> getFilesForCollection(std::shared_ptr<SourceLocationCollection> collection) const;
CodeSnippetParams getSnippetParamsForWholeFile(std::shared_ptr<SourceLocationFile> locationFile, bool useSingleFileCache) const;
std::vector<CodeSnippetParams> getSnippetsForFile(std::shared_ptr<SourceLocationFile> activeSourceLocations) const;
std::shared_ptr<SnippetMerger> buildMergerHierarchy(
const SourceLocation* location, const SourceLocationFile* scopeLocations, SnippetMerger& fileScopedMerger,
@@ -103,19 +119,48 @@ private:
std::vector<std::string> getProjectDescription(SourceLocationFile* locationFile) const;
void expandVisibleSnippets(std::vector<CodeSnippetParams>* snippets, bool useSingleFileCache) const;
void addAllSourceLocations(std::vector<CodeSnippetParams>* snippets) const;
void addModificationTimes(std::vector<CodeSnippetParams>* snippets) const;
void clearReferences();
void createReferences();
void clearLocalReferences();
void createLocalReferences(const std::set<Id>& localSymbolIds);
void iterateReference(bool next);
void iterateLocalReference(bool next, bool updateView);
void expandVisibleFiles(bool useSingleFileCache);
CodeFileParams* addSourceLocations(std::shared_ptr<SourceLocationFile> locationFile);
void setFileState(const FilePath& filePath, MessageChangeFileView::FileState state, bool useSingleFileCache);
void setFileState(CodeFileParams& file, MessageChangeFileView::FileState state, bool useSingleFileCache);
bool addAllSourceLocations();
void addModificationTimes();
CodeScrollParams firstReferenceScrollParams() const;
CodeScrollParams definitionReferenceScrollParams(const std::vector<Id>& activeTokenIds) const;
CodeScrollParams toReferenceScrollParams(const Reference& ref) const;
void saveOrRestoreViewMode(MessageBase* message);
void showCodeSnippets(
std::vector<CodeSnippetParams> snippets, const CodeView::CodeParams params, bool addSourceLocations = true);
void showFirstActiveReference(Id tokenId, bool updateView);
void showFiles(CodeView::CodeParams params, CodeScrollParams scrollParams, bool updateView);
StorageAccess* m_storageAccess;
mutable std::shared_ptr<SourceLocationCollection> m_collection;
std::shared_ptr<SourceLocationCollection> m_collection;
std::vector<CodeFileParams> m_files;
FilePath m_currentFilePath;
CodeView::CodeParams m_codeParams;
CodeScrollParams m_scrollParams;
std::map<Id, bool> m_messageIdToViewModeMap;
std::vector<Reference> m_references;
int m_referenceIndex = -1;
std::vector<Reference> m_localReferences;
int m_localReferenceIndex = -1;
};
#endif // CODE_CONTROLLER_H
+22 -44
View File
@@ -4,9 +4,10 @@
#include <memory>
#include "ErrorInfo.h"
#include "ScreenSearchInterfaces.h"
#include "LocationType.h"
#include "CodeScrollParams.h"
#include "CodeSnippetParams.h"
#include "ScreenSearchInterfaces.h"
#include "View.h"
class CodeController;
@@ -30,42 +31,22 @@ public:
struct CodeParams
{
bool clearSnippets = false;
bool showContents = false;
bool useSingleFileCache = true;
size_t referenceCount = 0;
size_t referenceIndex = 0;
size_t localReferenceCount = 0;
size_t localReferenceIndex = 0;
std::vector<Id> activeTokenIds;
std::vector<Id> activeLocationIds;
std::vector<Id> activeLocalSymbolIds;
LocationType activeLocalSymbolType = LOCATION_TOKEN;
std::vector<Id> currentActiveLocalLocationIds;
std::vector<ErrorInfo> errorInfos;
};
struct ScrollParams
{
enum ScrollType
{
SCROLL_NONE,
SCROLL_TO_DEFINITION,
SCROLL_TO_LINE,
SCROLL_TO_VALUE
} type;
ScrollParams(ScrollType type = SCROLL_NONE)
: type(type)
, line(0)
, value(0)
, animated(false)
, ignoreActiveReference(false)
, inListMode(false)
{}
FilePath filePath;
size_t line;
size_t value;
bool animated;
bool ignoreActiveReference;
bool inListMode;
};
CodeView(ViewLayout* viewLayout);
virtual ~CodeView();
@@ -73,24 +54,21 @@ public:
virtual void clear() = 0;
virtual void showCodeSnippets(const std::vector<CodeSnippetParams>& snippets, const CodeParams params) = 0;
virtual void updateCodeSnippets(const std::vector<CodeSnippetParams>& snippets) = 0;
virtual void scrollTo(const ScrollParams params) = 0;
virtual void showSnippets(
const std::vector<CodeFileParams> files, const CodeParams params, const CodeScrollParams scrollParams) = 0;
virtual void showSingleFile(
const CodeFileParams file, const CodeParams params, const CodeScrollParams scrollParams) = 0;
virtual void updateSourceLocations(const std::vector<CodeFileParams> files) = 0;
virtual void scrollTo(const CodeScrollParams params, bool animated) = 0;
virtual bool showsErrors() const = 0;
virtual void setFileState(const FilePath filePath, FileState state) = 0;
virtual void showActiveSnippet(
const std::vector<Id>& activeTokenIds, std::shared_ptr<SourceLocationCollection> collection, bool scrollTo) = 0;
virtual void showActiveTokenIds(const std::vector<Id>& activeTokenIds) = 0;
virtual void showActiveLocalSymbolIds(const std::vector<Id>& activeLocalSymbolIds) = 0;
virtual void focusTokenIds(const std::vector<Id>& focusedTokenIds) = 0;
virtual void defocusTokenIds() = 0;
virtual void showContents() = 0;
virtual bool isInListMode() const = 0;
virtual void setMode(bool listMode) = 0;
@@ -0,0 +1,61 @@
#ifndef CODE_SCROLL_PARAMS_H
#define CODE_SCROLL_PARAMS_H
#include "FilePath.h"
#include "types.h"
struct CodeScrollParams
{
enum class Type
{
NONE,
TO_REFERENCE,
TO_FILE,
TO_LINE,
TO_VALUE
};
enum class Target
{
VISIBLE,
CENTER,
TOP
};
static CodeScrollParams toReference(const FilePath& filePath, Id locationId, Target target)
{
return CodeScrollParams { Type::TO_REFERENCE, target, filePath, locationId, 0, 0, false };
}
static CodeScrollParams toFile(const FilePath& filePath, Target target)
{
return CodeScrollParams { Type::TO_LINE, target, filePath, 0, 0, 0, false };
}
static CodeScrollParams toLine(const FilePath& filePath, size_t line, Target target)
{
return CodeScrollParams { Type::TO_LINE, target, filePath, 0, line, 0, false };
}
static CodeScrollParams toValue(size_t value, bool inListMode)
{
return CodeScrollParams { Type::TO_VALUE, Target::VISIBLE, FilePath(), 0, 0, value, inListMode };
}
Type type = Type::NONE;
Target target = Target::VISIBLE;
FilePath filePath;
// Reference
Id locationId = 0;
// Line
size_t line = 0;
// Value
size_t value = 0;
bool inListMode = false;
};
#endif // CODE_SCROLL_PARAMS_H
@@ -2,21 +2,55 @@
#include "SourceLocationFile.h"
CodeSnippetParams::CodeSnippetParams()
: startLineNumber(0)
, endLineNumber(0)
, titleId(0)
, footerId(0)
, refCount(0)
, isCollapsed(false)
, isDeclaration(false)
, isDefinition(false)
, insertSnippet(false)
, reduced(false)
CodeSnippetParams CodeSnippetParams::merge(const CodeSnippetParams& a, const CodeSnippetParams& b)
{
const CodeSnippetParams* first = a.startLineNumber < b.startLineNumber ? &a : &b;
const CodeSnippetParams* second = a.startLineNumber > b.startLineNumber ? &a : &b;
SourceLocationFile* aFile = a.locationFile.get();
SourceLocationFile* bFile = b.locationFile.get();
std::shared_ptr<SourceLocationFile> locationFile = std::make_shared<SourceLocationFile>(
aFile->getFilePath(), aFile->getLanguage(), aFile->isWhole(), aFile->isComplete(), aFile->isIndexed());
aFile->forEachSourceLocation(
[&locationFile](SourceLocation* loc)
{
locationFile->addSourceLocationCopy(loc);
}
);
bFile->forEachSourceLocation(
[&locationFile](SourceLocation* loc)
{
locationFile->addSourceLocationCopy(loc);
}
);
std::string code = first->code;
std::string secondCode = second->code;
int secondCodeStartIndex = 0;
for (size_t i = second->startLineNumber; i <= first->endLineNumber; i++)
{
secondCodeStartIndex = secondCode.find("\n", secondCodeStartIndex) + 1;
}
code += secondCode.substr(secondCodeStartIndex, secondCode.npos);
CodeSnippetParams params;
params.startLineNumber = first->startLineNumber;
params.endLineNumber = second->endLineNumber;
params.title = first->title;
params.titleId = first->titleId;
params.footer = second->footer;
params.footerId = second->footerId;
params.code = code;
params.locationFile = locationFile;
return params;
}
bool CodeSnippetParams::sort(const CodeSnippetParams& a, const CodeSnippetParams& b)
bool CodeFileParams::sort(const CodeFileParams& a, const CodeFileParams& b)
{
// sort definitions
if (a.isDefinition && !b.isDefinition)
@@ -51,25 +85,19 @@ bool CodeSnippetParams::sort(const CodeSnippetParams& a, const CodeSnippetParams
const FilePath& aFilePath = a.locationFile->getFilePath();
const FilePath& bFilePath = b.locationFile->getFilePath();
// different files
if (aFilePath != bFilePath)
// first header
if (aFilePath.withoutExtension() == bFilePath.withoutExtension())
{
// first header
if (aFilePath.withoutExtension() == bFilePath.withoutExtension())
{
return aFilePath.extension() > bFilePath.extension();
}
// alphabetical filepath without extension
else
{
return aFilePath.withoutExtension() < bFilePath.withoutExtension();
}
return aFilePath.extension() > bFilePath.extension();
}
// alphabetical filepath without extension
else
{
return aFilePath.withoutExtension() < bFilePath.withoutExtension();
}
return a.startLineNumber < b.startLineNumber;
}
bool CodeSnippetParams::sortById(const CodeSnippetParams& a, const CodeSnippetParams& b)
bool CodeFileParams::sortById(const CodeFileParams& a, const CodeFileParams& b)
{
return a.locationFile->getSourceLocations().begin()->get()->getLocationId() <
b.locationFile->getSourceLocations().begin()->get()->getLocationId();
@@ -10,34 +10,38 @@ class SourceLocationFile;
struct CodeSnippetParams
{
CodeSnippetParams();
static CodeSnippetParams merge(const CodeSnippetParams& a, const CodeSnippetParams& b);
// comparefunction for snippetsorting
static bool sort(const CodeSnippetParams& a, const CodeSnippetParams& b);
static bool sortById(const CodeSnippetParams& a, const CodeSnippetParams& b);
size_t startLineNumber;
size_t endLineNumber;
size_t startLineNumber = 0;
size_t endLineNumber = 0;
std::wstring title;
std::wstring footer;
std::string code;
Id titleId;
Id footerId;
TimeStamp modificationTime;
Id titleId = 0;
Id footerId = 0;
std::shared_ptr<SourceLocationFile> locationFile;
bool hasAllSourceLocations = false;
bool isOverview = false;
};
int refCount;
struct CodeFileParams
{
static bool sort(const CodeFileParams& a, const CodeFileParams& b);
static bool sortById(const CodeFileParams& a, const CodeFileParams& b);
bool isCollapsed;
std::shared_ptr<SourceLocationFile> locationFile;
TimeStamp modificationTime;
size_t referenceCount = 0;
bool isDeclaration;
bool isDefinition;
bool isMinimized = true;
bool isDeclaration = false;
bool isDefinition = false;
bool insertSnippet;
bool reduced;
std::vector<CodeSnippetParams> snippetParams;
std::shared_ptr<CodeSnippetParams> fileParams; // TODO: replace with std::optional
};
#endif // CODE_SNIPPET_PARAMS_H
@@ -91,16 +91,21 @@ void SourceLocationCollection::addSourceLocationCopies(const SourceLocationColle
other->forEachSourceLocationFile(
[this](std::shared_ptr<SourceLocationFile> otherFile)
{
SourceLocationFile* file = createSourceLocationFile(
otherFile->getFilePath(), otherFile->getLanguage(), otherFile->isWhole(), otherFile->isComplete(),
otherFile->isIndexed());
addSourceLocationCopies(otherFile.get());
}
);
}
otherFile->forEachSourceLocation(
[file](SourceLocation* otherLocation)
{
file->addSourceLocationCopy(otherLocation);
}
);
void SourceLocationCollection::addSourceLocationCopies(const SourceLocationFile* otherFile)
{
SourceLocationFile* file = createSourceLocationFile(
otherFile->getFilePath(), otherFile->getLanguage(), otherFile->isWhole(), otherFile->isComplete(),
otherFile->isIndexed());
otherFile->forEachSourceLocation(
[file](SourceLocation* otherLocation)
{
file->addSourceLocationCopy(otherLocation);
}
);
}
@@ -35,6 +35,7 @@ public:
SourceLocation* addSourceLocationCopy(const SourceLocation* location);
void addSourceLocationCopies(const SourceLocationCollection* other);
void addSourceLocationCopies(const SourceLocationFile* otherFile);
void addSourceLocationFile(std::shared_ptr<SourceLocationFile> file);
+1 -1
View File
@@ -233,7 +233,7 @@ std::shared_ptr<SourceLocationFile> SourceLocationFile::getFilteredByTypes(const
}
std::shared_ptr<SourceLocationFile> ret =
std::make_shared<SourceLocationFile>(getFilePath(), getLanguage(), false, isComplete(), isIndexed());
std::make_shared<SourceLocationFile>(getFilePath(), getLanguage(), isWhole(), isComplete(), isIndexed());
for (const std::shared_ptr<SourceLocation>& location : m_locations)
{
@@ -1,6 +1,8 @@
#ifndef MESSAGE_CHANGE_FILE_VIEW_H
#define MESSAGE_CHANGE_FILE_VIEW_H
#include "CodeScrollParams.h"
#include "CodeSnippetParams.h"
#include "FilePath.h"
#include "Message.h"
#include "TabId.h"
@@ -27,15 +29,13 @@ public:
const FilePath& filePath,
FileState state,
ViewMode viewMode,
bool needsData,
bool showErrors,
CodeScrollParams scrollParams,
bool switchesViewMode = false
)
: filePath(filePath)
, state(state)
, viewMode(viewMode)
, needsData(needsData)
, showErrors(showErrors)
, scrollParams(scrollParams)
, switchesViewMode(switchesViewMode)
{
setSchedulerId(TabId::currentTab());
@@ -63,18 +63,12 @@ public:
case VIEW_SINGLE: os << L", single"; break;
case VIEW_CURRENT: os << L", current"; break;
}
if (needsData)
{
os << L", needs data";
}
}
const FilePath filePath;
const FileState state;
const ViewMode viewMode;
const bool needsData;
const bool showErrors;
const CodeScrollParams scrollParams;
const bool switchesViewMode;
};
@@ -21,6 +21,11 @@ public:
return "MessageScrollToLine";
}
void print(std::wostream& os) const override
{
os << filePath.wstr() << L":" << line;
}
const FilePath filePath;
size_t line;
};
+32 -48
View File
@@ -388,19 +388,6 @@ 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
{
size_t count = 0;
@@ -639,14 +626,7 @@ void QtCodeArea::mouseReleaseEvent(QMouseEvent* event)
std::vector<const Annotation*> annotations = getInteractiveAnnotationsForPosition(event->pos());
if (annotations.size())
{
if (m_navigator->hasErrors())
{
activateErrors(annotations);
}
else
{
activateAnnotations(annotations);
}
activateAnnotationsOrErrors(annotations);
}
else if (m_navigator->getActiveLocalTokenIds().size())
{
@@ -700,15 +680,25 @@ void QtCodeArea::mouseMoveEvent(QMouseEvent* event)
if (!same)
{
if (m_navigator->hasErrors())
{
for (const Annotation* annotation : annotations)
{
if (annotation->locationType == LOCATION_ERROR && annotation->tokenIds.size())
{
std::wstring errorMessage = m_navigator->getErrorMessageForId(*annotation->tokenIds.begin());
QToolTip::showText(event->globalPos(), QString::fromStdWString(errorMessage), this);
QtCodeField::focusTokenIds({ *annotation->tokenIds.begin() });
viewport()->setCursor(Qt::PointingHandCursor);
return;
}
}
}
QToolTip::hideText();
setHoveredAnnotations(annotations);
if (m_navigator->hasErrors() && annotations.size() == 1 && annotations[0]->tokenIds.size())
{
std::wstring errorMessage = m_navigator->getErrorMessageForId(*annotations[0]->tokenIds.begin());
QToolTip::showText(event->globalPos(), QString::fromStdWString(errorMessage), this);
}
}
}
@@ -748,23 +738,11 @@ void QtCodeArea::contextMenuEvent(QContextMenuEvent* event)
void QtCodeArea::focusTokenIds(const std::vector<Id>& tokenIds)
{
if (m_navigator->hasErrors() && tokenIds.size() == 1)
{
QtCodeField::focusTokenIds(tokenIds);
return;
}
MessageFocusIn(tokenIds, TOOLTIP_ORIGIN_CODE).dispatch();
}
void QtCodeArea::defocusTokenIds(const std::vector<Id>& tokenIds)
{
if (m_navigator->hasErrors() && tokenIds.size() == 1)
{
annotateText();
return;
}
MessageFocusOut(tokenIds).dispatch();
}
@@ -821,21 +799,27 @@ void QtCodeArea::setNewTextCursor(const QTextCursor& cursor)
verticalScrollBar()->setValue(verticalValue);
}
void QtCodeArea::activateErrors(const std::vector<const Annotation*>& annotations)
void QtCodeArea::activateAnnotationsOrErrors(const std::vector<const Annotation*>& annotations)
{
std::vector<Id> errorIds;
for (const Annotation* annotation : annotations)
if (m_navigator->hasErrors())
{
if (annotation->locationType == LOCATION_ERROR && annotation->tokenIds.size())
std::vector<Id> errorIds;
for (const Annotation* annotation : annotations)
{
errorIds.insert(errorIds.end(), annotation->tokenIds.begin(), annotation->tokenIds.end());
if (annotation->locationType == LOCATION_ERROR && annotation->tokenIds.size())
{
errorIds.insert(errorIds.end(), annotation->tokenIds.begin(), annotation->tokenIds.end());
}
}
if (errorIds.size() == 1)
{
MessageShowError(errorIds[0]).dispatch();
return;
}
}
if (errorIds.size() == 1)
{
MessageShowError(errorIds[0]).dispatch();
}
activateAnnotations(annotations);
}
void QtCodeArea::annotateText()
+1 -3
View File
@@ -81,8 +81,6 @@ 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(size_t lineNumber) const;
@@ -114,7 +112,7 @@ private:
void clearSelection();
void setNewTextCursor(const QTextCursor& cursor);
void activateErrors(const std::vector<const Annotation*>& annotations);
void activateAnnotationsOrErrors(const std::vector<const Annotation*>& annotations);
void annotateText();
+37 -149
View File
@@ -15,7 +15,6 @@ QtCodeFile::QtCodeFile(const FilePath& filePath, QtCodeNavigator* navigator, boo
, m_navigator(navigator)
, m_filePath(filePath)
, m_isWholeFile(false)
, m_contentRequested(false)
{
setObjectName("code_file");
setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Fixed);
@@ -43,6 +42,7 @@ QtCodeFile::QtCodeFile(const FilePath& filePath, QtCodeNavigator* navigator, boo
m_snippetLayout->setSpacing(0);
layout->addLayout(m_snippetLayout);
setMinimized();
update();
}
@@ -67,118 +67,30 @@ const QtCodeFileTitleBar* QtCodeFile::getTitleBar() const
QtCodeSnippet* QtCodeFile::addCodeSnippet(const CodeSnippetParams& params)
{
if (m_isWholeFile && m_snippets.size() == 1)
{
return m_snippets[0];
}
for (QtCodeSnippet* snippet : m_snippets)
{
if (snippet->getStartLineNumber() == params.startLineNumber &&
snippet->getEndLineNumber() == params.endLineNumber)
{
return snippet;
}
}
QtCodeSnippet* snippet = new QtCodeSnippet(params, m_navigator, this);
if (params.reduced)
if (params.isOverview)
{
m_titleBar->getTitleButton()->setProject(params.title);
m_isWholeFile = true;
}
if (params.locationFile->isWhole() || m_isWholeFile)
{
m_isWholeFile = true;
snippet->setIsActiveFile(true);
if (params.refCount != -1)
{
updateRefCount(0);
}
for (QtCodeSnippet* oldSnippet : m_snippets)
{
oldSnippet->hide();
}
m_snippets.clear();
}
else
{
updateRefCount(params.refCount);
}
m_snippetLayout->addWidget(snippet);
m_snippets.push_back(snippet);
setSnippets();
return snippet;
}
QtCodeSnippet* QtCodeFile::insertCodeSnippet(const CodeSnippetParams& params)
{
QtCodeSnippet* newSnippet = new QtCodeSnippet(params, m_navigator, this);
size_t i = 0;
while (i < m_snippets.size())
{
size_t start = newSnippet->getStartLineNumber();
size_t end = newSnippet->getEndLineNumber();
QtCodeSnippet* oldSnippet = m_snippets[i];
if (oldSnippet->getEndLineNumber() + 1 < start) // before
{
i++;
continue;
}
else if (oldSnippet->getStartLineNumber() > end + 1) // after
{
break;
}
else if (oldSnippet->getStartLineNumber() <= start && oldSnippet->getEndLineNumber() >= end) // containing
{
newSnippet->deleteLater();
return oldSnippet;
}
else if (oldSnippet->getStartLineNumber() < start || oldSnippet->getEndLineNumber() > end) // overlaping
{
newSnippet = QtCodeSnippet::merged(newSnippet, oldSnippet, m_navigator, this);
}
else if (oldSnippet->getStartLineNumber() >= start && oldSnippet->getEndLineNumber() <= end) // enclosing
{
// copy all source locations from old to new snippet: fulltext locations got lost
oldSnippet->getArea()->getSourceLocationFile()->copySourceLocations(
newSnippet->getArea()->getSourceLocationFile());
newSnippet->getArea()->updateSourceLocations(oldSnippet->getArea()->getSourceLocationFile());
}
m_navigator->clearSnippetReferences();
oldSnippet->hide();
m_snippetLayout->removeWidget(oldSnippet);
oldSnippet->deleteLater();
m_snippets.erase(m_snippets.begin() + i);
}
m_snippetLayout->insertWidget(i, newSnippet);
m_snippets.insert(m_snippets.begin() + i, newSnippet);
setSnippets();
return newSnippet;
}
void QtCodeFile::updateCodeSnippet(const CodeSnippetParams& params)
void QtCodeFile::updateSourceLocations(const CodeSnippetParams& params)
{
if (m_isWholeFile && m_snippets.size() == 1)
{
m_snippets[0]->updateCodeSnippet(params);
m_snippets[0]->updateSourceLocations(params);
return;
}
@@ -187,11 +99,16 @@ void QtCodeFile::updateCodeSnippet(const CodeSnippetParams& params)
if (snippet->getStartLineNumber() == params.startLineNumber &&
snippet->getEndLineNumber() == params.endLineNumber)
{
snippet->updateCodeSnippet(params);
snippet->updateSourceLocations(params);
}
}
}
const std::vector<QtCodeSnippet*>& QtCodeFile::getSnippets() const
{
return m_snippets;
}
std::vector<QtCodeSnippet*> QtCodeFile::getVisibleSnippets() const
{
std::vector<QtCodeSnippet*> snippets;
@@ -251,32 +168,7 @@ std::pair<QtCodeSnippet*, Id> QtCodeFile::getFirstSnippetWithActiveLocationId(Id
return result;
}
bool QtCodeFile::isCollapsed() const
{
return !m_snippets.size();
}
void QtCodeFile::requestContent()
{
if (!isCollapsed() || m_contentRequested)
{
updateContent();
return;
}
m_contentRequested = true;
MessageChangeFileView::FileState state =
m_isWholeFile ? MessageChangeFileView::FILE_MAXIMIZED : MessageChangeFileView::FILE_SNIPPETS;
bool needsData = (m_snippets.size() == 0);
MessageChangeFileView msg(m_filePath, state, MessageChangeFileView::VIEW_LIST, needsData, m_navigator->hasErrors());
msg.setSchedulerId(m_navigator->getSchedulerId());
msg.dispatch();
}
void QtCodeFile::requestWholeFileContent()
void QtCodeFile::requestWholeFileContent(size_t targetLineNumber)
{
if (!m_isWholeFile)
{
@@ -284,8 +176,7 @@ void QtCodeFile::requestWholeFileContent()
m_filePath,
MessageChangeFileView::FILE_MAXIMIZED,
MessageChangeFileView::VIEW_LIST,
true,
m_navigator->hasErrors()
CodeScrollParams::toLine(m_filePath, targetLineNumber, CodeScrollParams::Target::VISIBLE)
);
msg.setSchedulerId(m_navigator->getSchedulerId());
msg.dispatch();
@@ -309,7 +200,6 @@ void QtCodeFile::updateContent()
void QtCodeFile::setWholeFile(bool isWholeFile, int refCount)
{
m_isWholeFile = isWholeFile;
setMinimized();
updateRefCount(isWholeFile ? 0 : refCount);
}
@@ -344,16 +234,28 @@ void QtCodeFile::setSnippets()
m_titleBar->setSnippets();
}
void QtCodeFile::setMaximized()
{
setSnippets();
}
bool QtCodeFile::hasSnippets() const
{
return m_snippets.size() > 0;
}
void QtCodeFile::clearSnippets()
{
for (QtCodeSnippet* snippet : m_snippets)
{
m_snippetLayout->removeWidget(snippet);
snippet->hide();
snippet->deleteLater();
}
if (m_snippets.size())
{
m_navigator->clearSnippetReferences();
}
m_snippets.clear();
}
void QtCodeFile::updateSnippets()
{
if (m_snippets.size() == 0)
@@ -391,27 +293,13 @@ 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 msg(
m_filePath,
MessageChangeFileView::FILE_MINIMIZED,
MessageChangeFileView::VIEW_LIST,
false,
m_navigator->hasErrors()
CodeScrollParams::toFile(m_filePath, CodeScrollParams::Target::VISIBLE)
);
msg.setSchedulerId(m_navigator->getSchedulerId());
msg.dispatch();
@@ -419,14 +307,11 @@ void QtCodeFile::clickedMinimizeButton()
void QtCodeFile::clickedSnippetButton()
{
m_navigator->requestScroll(m_filePath, 0, 0, false, QtCodeNavigateable::SCROLL_VISIBLE);
MessageChangeFileView msg(
m_filePath,
MessageChangeFileView::FILE_SNIPPETS,
MessageChangeFileView::VIEW_LIST,
isCollapsed(),
m_navigator->hasErrors()
CodeScrollParams::toFile(m_filePath, CodeScrollParams::Target::VISIBLE)
);
msg.setSchedulerId(m_navigator->getSchedulerId());
msg.dispatch();
@@ -453,14 +338,17 @@ void QtCodeFile::clickedMaximizeButton()
}
}
m_navigator->requestScroll(m_filePath, lineNumber, locationId, false, QtCodeNavigateable::SCROLL_CENTER);
m_navigator->setMode(QtCodeNavigator::MODE_SINGLE);
CodeScrollParams scrollParams = locationId ?
CodeScrollParams::toReference(m_filePath, locationId, CodeScrollParams::Target::CENTER) :
CodeScrollParams::toLine(m_filePath, lineNumber, CodeScrollParams::Target::CENTER);
MessageChangeFileView msg(
m_filePath,
MessageChangeFileView::FILE_MAXIMIZED,
MessageChangeFileView::VIEW_SINGLE,
true, // TODO: check if data is really needed
m_navigator->hasErrors(),
scrollParams,
true
);
msg.setSchedulerId(m_navigator->getSchedulerId());
+4 -11
View File
@@ -35,19 +35,16 @@ public:
const QtCodeFileTitleBar* getTitleBar() const;
QtCodeSnippet* addCodeSnippet(const CodeSnippetParams& params);
QtCodeSnippet* insertCodeSnippet(const CodeSnippetParams& params);
void updateCodeSnippet(const CodeSnippetParams& params);
void updateSourceLocations(const CodeSnippetParams& params);
const std::vector<QtCodeSnippet*>& getSnippets() const;
std::vector<QtCodeSnippet*> getVisibleSnippets() const;
QtCodeSnippet* getSnippetForLocationId(Id locationId) const;
QtCodeSnippet* getSnippetForLine(unsigned int line) const;
std::pair<QtCodeSnippet*, Id> getFirstSnippetWithActiveLocationId(Id tokenId) const;
bool isCollapsed() const;
void requestContent();
void requestWholeFileContent();
void requestWholeFileContent(size_t targetLineNumber);
void updateContent();
void setWholeFile(bool isWholeFile, int refCount);
@@ -56,16 +53,14 @@ public:
void setMinimized();
void setSnippets();
void setMaximized();
bool hasSnippets() const;
void clearSnippets();
void updateSnippets();
void updateTitleBar();
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();
@@ -83,8 +78,6 @@ private:
const FilePath m_filePath;
bool m_isWholeFile;
mutable bool m_contentRequested;
};
#endif // QT_CODE_FILE_H
+63 -136
View File
@@ -115,13 +115,51 @@ QtCodeFile* QtCodeFileList::getFile(const FilePath filePath)
return file;
}
void QtCodeFileList::addFile(std::shared_ptr<SourceLocationFile> locationFile, int refCount, TimeStamp modificationTime)
void QtCodeFileList::addFile(const CodeFileParams& params)
{
QtCodeFile* file = getFile(locationFile->getFilePath());
file->setWholeFile(locationFile->isWhole(), refCount);
file->setModificationTime(modificationTime);
file->setIsComplete(locationFile->isComplete());
file->setIsIndexed(locationFile->isIndexed());
QtCodeFile* file = getFile(params.locationFile->getFilePath());
file->setWholeFile(params.locationFile->isWhole(), params.referenceCount);
file->setModificationTime(params.modificationTime);
file->setIsComplete(params.locationFile->isComplete());
file->setIsIndexed(params.locationFile->isIndexed());
if (params.isMinimized)
{
file->setMinimized();
}
else
{
bool same = true;
const std::vector<QtCodeSnippet*> snippets = file->getSnippets();
if (params.snippetParams.size() != snippets.size())
{
same = false;
}
else
{
for (size_t i = 0; i < snippets.size(); i++)
{
if (params.snippetParams[i].startLineNumber != snippets[i]->getStartLineNumber() ||
params.snippetParams[i].endLineNumber != snippets[i]->getEndLineNumber())
{
same = false;
break;
}
}
}
if (!same)
{
file->clearSnippets();
for (const CodeSnippetParams& snippetParams : params.snippetParams)
{
file->addCodeSnippet(snippetParams);
}
}
file->setSnippets();
}
}
QScrollArea* QtCodeFileList::getScrollArea()
@@ -129,47 +167,36 @@ QScrollArea* QtCodeFileList::getScrollArea()
return m_scrollArea;
}
void QtCodeFileList::addCodeSnippet(const CodeSnippetParams& params)
void QtCodeFileList::updateSourceLocations(const CodeSnippetParams& params)
{
QtCodeFile* file = getFile(params.locationFile->getFilePath());
if (params.insertSnippet)
if (file)
{
file->insertCodeSnippet(params);
file->updateSourceLocations(params);
}
else
}
void QtCodeFileList::updateFiles()
{
for (QtCodeFile* file : m_files)
{
file->addCodeSnippet(params);
file->setProperty("last", file == m_files.back());
file->updateContent();
file->updateTitleBar();
file->show();
}
file->setModificationTime(params.modificationTime);
file->setIsComplete(params.locationFile->isComplete());
file->setIsIndexed(params.locationFile->isIndexed());
// Perform delayed so all widgets are already visible
QTimer::singleShot(100, this, &QtCodeFileList::updateSnippetTitleAndScrollBarSlot);
}
void QtCodeFileList::updateCodeSnippet(const CodeSnippetParams& params)
{
QtCodeFile* file = getFile(params.locationFile->getFilePath());
file->updateCodeSnippet(params);
}
void QtCodeFileList::requestFileContent(const FilePath& filePath)
{
getFile(filePath)->requestContent();
}
bool QtCodeFileList::requestScroll(const FilePath& filePath, size_t lineNumber, Id locationId, bool animated, ScrollTarget target)
void QtCodeFileList::scrollTo(
const FilePath& filePath, size_t lineNumber, Id locationId, bool animated, CodeScrollParams::Target target)
{
QtCodeFile* file = getFile(filePath);
if (!file)
{
return true;
}
if (file->isCollapsed())
{
file->requestContent();
return false;
return;
}
QtCodeSnippet* snippet = nullptr;
@@ -187,16 +214,10 @@ bool QtCodeFileList::requestScroll(const FilePath& filePath, size_t lineNumber,
snippet = file->getSnippetForLine(1);
}
if (!snippet)
if (!snippet || !snippet->isVisible())
{
ensureWidgetVisibleAnimated(m_filesArea, file->getTitleBar(), QRect(), animated, target);
return true;
}
if (!snippet->isVisible())
{
file->setSnippets();
return true;
return;
}
size_t endLineNumber = 0;
@@ -228,29 +249,6 @@ bool QtCodeFileList::requestScroll(const FilePath& filePath, size_t lineNumber,
ensureWidgetVisibleAnimated(m_filesArea, snippet, lineRect, animated, target);
snippet->ensureLocationIdVisible(locationId, animated);
return true;
}
void QtCodeFileList::updateFiles()
{
for (QtCodeFile* file : m_files)
{
file->setProperty("last", file == m_files.back());
file->updateContent();
}
// Perform delayed so all widgets are already visible
QTimer::singleShot(100, this, &QtCodeFileList::updateSnippetTitleAndScrollBarSlot);
}
void QtCodeFileList::showContents()
{
for (QtCodeFile* file : m_files)
{
file->updateTitleBar();
file->show();
}
}
void QtCodeFileList::onWindowFocus()
@@ -274,67 +272,6 @@ 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())
{
if (m_files.size())
{
m_files[0]->setMinimized();
}
}
else
{
QtCodeFile* file = getFile(path);
file->setMinimized();
if (m_firstSnippetTitleBar->isVisible())
{
ensureWidgetVisibleAnimated(m_filesArea, file->getTitleBar(), QRect(), false, SCROLL_TOP);
}
}
}
void QtCodeFileList::setFileSnippets(const FilePath path)
{
if (path.empty())
{
if (m_files.size())
{
m_files[0]->setSnippets();
}
}
else
{
getFile(path)->setSnippets();
}
}
void QtCodeFileList::setFileMaximized(const FilePath path)
{
if (path.empty())
{
if (m_files.size())
{
m_files[0]->setMaximized();
}
}
else
{
getFile(path)->setMaximized();
}
}
void QtCodeFileList::maximizeFirstFile()
{
if (m_files.size())
@@ -347,11 +284,6 @@ std::pair<QtCodeFile*, Id> QtCodeFileList::getFirstFileWithActiveLocationId() co
{
for (QtCodeFile* file : m_files)
{
if (file->isCollapsed())
{
continue;
}
std::pair<QtCodeSnippet*, Id> snippet = file->getFirstSnippetWithActiveLocationId(0);
if (snippet.first != nullptr)
{
@@ -368,11 +300,6 @@ std::pair<QtCodeSnippet*, Id> QtCodeFileList::getFirstSnippetWithActiveLocationI
for (QtCodeFile* file : m_files)
{
if (file->isCollapsed())
{
continue;
}
result = file->getFirstSnippetWithActiveLocationId(tokenId);
if (result.first != nullptr)
{
+6 -14
View File
@@ -29,30 +29,21 @@ public:
void clearSnippetTitleAndScrollBar();
QtCodeFile* getFile(const FilePath filePath);
void addFile(std::shared_ptr<SourceLocationFile> locationFile, int refCount, TimeStamp modificationTime);
void addFile(const CodeFileParams& params);
// QtCodeNaviatebale implementation
QScrollArea* getScrollArea() override;
void addCodeSnippet(const CodeSnippetParams& params) override;
void updateCodeSnippet(const CodeSnippetParams& params) override;
void requestFileContent(const FilePath& filePath) override;
bool requestScroll(const FilePath& filePath, size_t lineNumber, Id locationId, bool animated, ScrollTarget target) override;
void updateSourceLocations(const CodeSnippetParams& params) override;
void updateFiles() override;
void showContents() override;
void scrollTo(const FilePath& filePath, size_t lineNumber, Id locationId, bool animated, CodeScrollParams::Target target) override;
void onWindowFocus() override;
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);
void setFileMaximized(const FilePath path);
void maximizeFirstFile();
std::pair<QtCodeFile*, Id> getFirstFileWithActiveLocationId() const;
@@ -64,6 +55,7 @@ protected:
private slots:
void updateSnippetTitleAndScrollBarSlot();
void updateSnippetTitleAndScrollBar(int value = 0);
void scrollLastSnippet(int value);
void scrollLastSnippetScrollBar(int value);
+103 -148
View File
@@ -9,7 +9,6 @@
#include "FilePath.h"
#include "logging.h"
#include "MessageChangeFileView.h"
#include "SourceLocationFile.h"
#include "QtCodeArea.h"
#include "QtCodeFileTitleBar.h"
@@ -20,8 +19,6 @@
QtCodeFileSingle::QtCodeFileSingle(QtCodeNavigator* navigator, QWidget* parent)
: m_navigator(navigator)
, m_area(nullptr)
, m_contentRequested(false)
, m_scrollRequested(false)
{
setObjectName("code_container");
@@ -44,11 +41,6 @@ QtCodeFileSingle::QtCodeFileSingle(QtCodeNavigator* navigator, QWidget* parent)
layout()->addWidget(m_areaWrapper);
}
QAbstractScrollArea* QtCodeFileSingle::getScrollArea()
{
return m_area;
}
void QtCodeFileSingle::clearFile()
{
setFileData(FileData());
@@ -65,110 +57,115 @@ void QtCodeFileSingle::clearCache()
m_fileDatas.clear();
m_filePaths.clear();
m_lastLocationFile.reset();
}
void QtCodeFileSingle::addCodeSnippet(const CodeSnippetParams& params)
bool QtCodeFileSingle::addFile(const CodeFileParams& params, bool useSingleFileCache)
{
if (!params.locationFile->isWhole())
if (!params.fileParams)
{
LOG_ERROR("Snippet params passed are not for whole file.");
return;
}
FileData file = getFileData(params.locationFile->getFilePath());
if (file.area)
{
setFileData(file);
return;
}
file.filePath = params.locationFile->getFilePath();
file.modificationTime = params.modificationTime;
file.isComplete = params.locationFile->isComplete();
file.isIndexed = params.locationFile->isIndexed();
if (params.reduced)
{
file.title = params.title;
}
file.area = new QtCodeArea(1, params.code, params.locationFile, m_navigator, !params.reduced, this);
connect(file.area->verticalScrollBar(), &QScrollBar::valueChanged, m_navigator, &QtCodeNavigator::scrolled);
m_fileDatas.emplace(file.filePath, file);
m_filePaths.push_back(file.filePath);
setFileData(file);
m_contentRequested = false;
if (m_filePaths.size() > 100)
{
FilePath toDelete = m_filePaths.front();
m_filePaths.pop_front();
auto it = m_fileDatas.find(toDelete);
if (it != m_fileDatas.end())
{
it->second.area->deleteLater();
m_fileDatas.erase(it);
}
}
}
void QtCodeFileSingle::updateCodeSnippet(const CodeSnippetParams& params)
{
auto it = m_fileDatas.find(params.locationFile->getFilePath());
if (it != m_fileDatas.end())
{
it->second.area->updateSourceLocations(params.locationFile);
}
}
void QtCodeFileSingle::requestFileContent(const FilePath& filePath)
{
if (m_contentRequested)
{
return;
}
FileData file = getFileData(filePath);
if (file.area)
{
setFileData(file);
return;
}
m_contentRequested = true;
MessageChangeFileView msg(
filePath,
MessageChangeFileView::FILE_MAXIMIZED,
MessageChangeFileView::VIEW_SINGLE,
true,
m_navigator->hasErrors()
);
msg.setSchedulerId(m_navigator->getSchedulerId());
msg.dispatch();
}
bool QtCodeFileSingle::requestScroll(
const FilePath& filePath, size_t lineNumber, Id locationId, bool animated, ScrollTarget target)
{
FileData file = getFileData(filePath);
if (file.area)
{
setFileData(file);
}
else
{
requestFileContent(filePath);
LOG_ERROR("File params have missing information.");
return false;
}
if (!m_scrollRequested)
std::shared_ptr<SourceLocationFile> locationFile = params.fileParams->locationFile;
FileData file = useSingleFileCache ? getFileData(locationFile->getFilePath()) : FileData();
if (file.area)
{
animated = false;
if (file.area == m_area)
{
return false;
}
setFileData(file);
return true;
}
if (!locationFile->isWhole())
{
LOG_ERROR("Snippet params passed are not for whole file.");
return false;
}
// prevent non cached file from being created again when currently displayed
if (locationFile == m_lastLocationFile && locationFile->getFilePath() == m_currentFilePath)
{
return false;
}
m_lastLocationFile = locationFile;
file.filePath = locationFile->getFilePath();
file.isComplete = locationFile->isComplete();
file.isIndexed = locationFile->isIndexed();
file.modificationTime = params.modificationTime;
if (params.fileParams->isOverview)
{
file.title = params.fileParams->title;
}
file.area = new QtCodeArea(1, params.fileParams->code, locationFile, m_navigator, !params.fileParams->isOverview, this);
connect(file.area->verticalScrollBar(), &QScrollBar::valueChanged, m_navigator, &QtCodeNavigator::scrolled);
setFileData(file);
updateRefCount(params.referenceCount);
if (useSingleFileCache)
{
m_fileDatas.emplace(file.filePath, file);
m_filePaths.push_back(file.filePath);
if (m_filePaths.size() > 100)
{
// TODO: don't delete files that were added multiple times
FilePath toDelete = m_filePaths.front();
m_filePaths.pop_front();
auto it = m_fileDatas.find(toDelete);
if (it != m_fileDatas.end())
{
it->second.area->deleteLater();
m_fileDatas.erase(it);
}
}
}
return true;
}
QAbstractScrollArea* QtCodeFileSingle::getScrollArea()
{
return m_area;
}
void QtCodeFileSingle::updateSourceLocations(const CodeSnippetParams& params)
{
if (m_currentFilePath == params.locationFile->getFilePath())
{
m_area->updateSourceLocations(params.locationFile);
}
}
void QtCodeFileSingle::updateFiles()
{
if (m_area)
{
m_area->updateContent();
m_area->show();
// Resizes the area to fix a bug where the area could be scrolled below the last line.
m_area->updateGeometry();
}
}
void QtCodeFileSingle::scrollTo(
const FilePath& filePath, size_t lineNumber, Id locationId, bool animated, CodeScrollParams::Target target)
{
if (m_currentFilePath != filePath)
{
return;
}
size_t endLineNumber = 0;
@@ -196,30 +193,6 @@ bool QtCodeFileSingle::requestScroll(
ensurePercentVisibleAnimated(percentA, percentB, animated, target);
m_area->ensureLocationIdVisible(locationId, width(), animated);
m_scrollRequested = true;
return true;
}
void QtCodeFileSingle::updateFiles()
{
if (m_area)
{
m_area->updateContent();
}
}
void QtCodeFileSingle::showContents()
{
if (m_area)
{
m_area->show();
updateRefCount(m_area->getActiveLocationCount());
// Resizes the area to fix a bug where the area could be scrolled below the last line.
m_area->updateGeometry();
}
}
void QtCodeFileSingle::onWindowFocus()
@@ -235,21 +208,6 @@ 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;
@@ -278,14 +236,13 @@ Id QtCodeFileSingle::getLocationIdOfFirstActiveLocationOfTokenId(Id tokenId) con
void QtCodeFileSingle::clickedSnippetButton()
{
m_navigator->requestScroll(m_currentFilePath, 0, 0, false, QtCodeNavigateable::SCROLL_TOP);
m_navigator->setMode(QtCodeNavigator::MODE_LIST);
MessageChangeFileView(
m_currentFilePath,
MessageChangeFileView::FILE_SNIPPETS,
MessageChangeFileView::VIEW_LIST,
true, // TODO: check if data is really needed
m_navigator->hasErrors(),
CodeScrollParams::toFile(m_currentFilePath, CodeScrollParams::Target::TOP),
true
).dispatch();
}
@@ -350,8 +307,6 @@ void QtCodeFileSingle::setFileData(const FileData& file)
// Resizes the area to fix a bug where the area could be scrolled below the last line.
m_area->updateGeometry();
m_scrollRequested = false;
}
else
{
+6 -12
View File
@@ -30,26 +30,21 @@ public:
void clearFile();
void clearCache();
bool addFile(const CodeFileParams& params, bool useSingleFileCache);
// QtCodeNavigateable implementation
QAbstractScrollArea* getScrollArea() override;
void addCodeSnippet(const CodeSnippetParams& params) override;
void updateCodeSnippet(const CodeSnippetParams& params) override;
void requestFileContent(const FilePath& filePath) override;
bool requestScroll(
const FilePath& filePath, size_t lineNumber, Id locationId, bool animated, ScrollTarget target) override;
void updateSourceLocations(const CodeSnippetParams& params) override;
void updateFiles() override;
void showContents() override;
void scrollTo(const FilePath& filePath, size_t lineNumber, Id locationId, bool animated, CodeScrollParams::Target target) override;
void onWindowFocus() override;
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;
@@ -86,8 +81,7 @@ private:
std::map<FilePath, FileData> m_fileDatas;
std::deque<FilePath> m_filePaths;
bool m_contentRequested;
bool m_scrollRequested;
std::shared_ptr<SourceLocationFile> m_lastLocationFile;
};
#endif // QT_CODE_FILE_SINGLE_H
@@ -11,7 +11,7 @@ QtCodeNavigateable::~QtCodeNavigateable()
}
void QtCodeNavigateable::ensureWidgetVisibleAnimated(
const QWidget* parentWidget, const QWidget *childWidget, QRectF rect, bool animated, ScrollTarget target)
const QWidget* parentWidget, const QWidget *childWidget, QRectF rect, bool animated, CodeScrollParams::Target target)
{
QAbstractScrollArea* area = getScrollArea();
if (!area || !parentWidget->isAncestorOf(childWidget))
@@ -36,19 +36,28 @@ void QtCodeNavigateable::ensureWidgetVisibleAnimated(
// scroll to top if widget is bigger than view
if (focusRect.height() > visibleRect.height())
{
target = SCROLL_TOP;
target = CodeScrollParams::Target::TOP;
}
int value = 0;
switch (target)
{
case SCROLL_VISIBLE:
case CodeScrollParams::Target::VISIBLE:
if (focusRect.top() > visibleRect.top() && focusRect.bottom() < visibleRect.bottom())
{
return;
}
else if (focusRect.top() < visibleRect.top())
{
value = focusRect.top() - visibleRect.top() - 50;
}
else
{
value = focusRect.bottom() - visibleRect.bottom() + 50;
}
break;
case SCROLL_CENTER:
case CodeScrollParams::Target::CENTER:
value = focusRect.center().y() - visibleRect.center().y();
if (abs(value) < 50)
{
@@ -56,8 +65,12 @@ void QtCodeNavigateable::ensureWidgetVisibleAnimated(
}
break;
case SCROLL_TOP:
case CodeScrollParams::Target::TOP:
value = focusRect.top() - visibleRect.top() - 50;
if (value > 0 && value < 150)
{
value = 0;
}
break;
}
@@ -80,7 +93,8 @@ void QtCodeNavigateable::ensureWidgetVisibleAnimated(
}
}
void QtCodeNavigateable::ensurePercentVisibleAnimated(double percentA, double percentB, bool animated, ScrollTarget target)
void QtCodeNavigateable::ensurePercentVisibleAnimated(
double percentA, double percentB, bool animated, CodeScrollParams::Target target)
{
QAbstractScrollArea* area = getScrollArea();
if (!area)
@@ -105,18 +119,18 @@ void QtCodeNavigateable::ensurePercentVisibleAnimated(double percentA, double pe
if (rectHeight > visibleHeight)
{
target = SCROLL_TOP;
target = CodeScrollParams::Target::TOP;
}
switch (target)
{
case SCROLL_VISIBLE:
case CodeScrollParams::Target::VISIBLE:
if (scrollY > visibleY && scrollY + rectHeight < visibleY + scrollableHeight)
{
return;
}
case SCROLL_CENTER:
case CodeScrollParams::Target::CENTER:
if (rectHeight < visibleHeight / 2)
{
scrollY -= visibleHeight / 4;
@@ -127,8 +141,8 @@ void QtCodeNavigateable::ensurePercentVisibleAnimated(double percentA, double pe
}
break;
case SCROLL_TOP:
scrollY -= 20;
case CodeScrollParams::Target::TOP:
scrollY -= 100;
break;
}
@@ -3,9 +3,9 @@
#include <set>
#include "types.h"
#include "CodeScrollParams.h"
#include "CodeSnippetParams.h"
#include "types.h"
class FilePath;
class QRectF;
@@ -17,35 +17,24 @@ class QWidget;
class QtCodeNavigateable
{
public:
enum ScrollTarget
{
SCROLL_VISIBLE,
SCROLL_CENTER,
SCROLL_TOP
};
virtual ~QtCodeNavigateable();
virtual QAbstractScrollArea* getScrollArea() = 0;
virtual void addCodeSnippet(const CodeSnippetParams& params) = 0;
virtual void updateCodeSnippet(const CodeSnippetParams& params) = 0;
virtual void requestFileContent(const FilePath& filePath) = 0;
virtual bool requestScroll(const FilePath& filePath, size_t lineNumber, Id locationId, bool animated, ScrollTarget target) = 0;
virtual void updateSourceLocations(const CodeSnippetParams& params) = 0;
virtual void updateFiles() = 0;
virtual void showContents() = 0;
virtual void scrollTo(
const FilePath& filePath, size_t lineNumber, Id locationId, bool animated, CodeScrollParams::Target target) = 0;
virtual void onWindowFocus() = 0;
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);
void ensureWidgetVisibleAnimated(
const QWidget* parentWidget, const QWidget *childWidget, QRectF rect, bool animated, CodeScrollParams::Target target);
void ensurePercentVisibleAnimated(double percentA, double percentB, bool animated, CodeScrollParams::Target target);
QRect getFocusRectForWidget(const QWidget* childWidget, const QWidget* parentWidget) const;
};
File diff suppressed because it is too large Load Diff
+13 -95
View File
@@ -10,8 +10,6 @@
#include "QtThreadedFunctor.h"
#include "MessageListener.h"
#include "MessageIndexingFinished.h"
#include "MessageCodeReference.h"
#include "MessageShowReference.h"
#include "MessageSwitchColorScheme.h"
#include "MessageWindowFocus.h"
@@ -23,9 +21,7 @@ class SourceLocationFile;
class QtCodeNavigator
: public QWidget
, public MessageListener<MessageCodeReference>
, public MessageListener<MessageIndexingFinished>
, public MessageListener<MessageShowReference>
, public MessageListener<MessageSwitchColorScheme>
, public MessageListener<MessageWindowFocus>
{
@@ -42,16 +38,16 @@ public:
QtCodeNavigator(QWidget* parent = nullptr);
virtual ~QtCodeNavigator();
void addCodeSnippet(const CodeSnippetParams& params);
void updateCodeSnippet(const CodeSnippetParams& params);
void addFile(std::shared_ptr<SourceLocationFile> locationFile, int refCount, TimeStamp modificationTime);
void addedFiles();
void addSnippetFile(const CodeFileParams& params);
bool addSingleFile(const CodeFileParams& params, bool useSingleFileCache);
void updateSourceLocations(const CodeSnippetParams& params);
void updateReferenceCount(
size_t referenceCount, size_t referenceIndex, size_t localReferenceCount, size_t localReferenceIndex);
void clear();
void clearCodeSnippets(bool useSingleFileCache);
void clearSnippets();
void clearFile();
void clearCaches();
void clearCache();
void clearSnippetReferences();
void setMode(Mode mode);
@@ -86,18 +82,10 @@ public:
bool isInListMode() const;
bool hasSingleFileCached(const FilePath& filePath) const;
void showActiveSnippet(
const std::vector<Id>& activeTokenIds, std::shared_ptr<SourceLocationCollection> collection, bool scrollTo);
void focusTokenIds(const std::vector<Id>& focusedTokenIds);
void defocusTokenIds();
void setFileMinimized(const FilePath path);
void setFileSnippets(const FilePath path);
void setFileMaximized(const FilePath path);
void updateFiles();
void showContents();
void refreshStyle();
@@ -107,17 +95,7 @@ public:
bool hasScreenMatches() const;
void clearScreenMatches();
void scrollToValue(int value, bool inListMode);
void scrollToLine(const FilePath& filePath, unsigned int line);
void scrollToDefinition(bool animated, bool ignoreActiveReference);
void scrollToSnippetIfRequested();
void requestScroll(
const FilePath& filePath, size_t lineNumber, Id locationId, bool animated, QtCodeNavigateable::ScrollTarget target);
signals:
void scrollRequest();
void scrollTo(const CodeScrollParams& params, bool animated);
public slots:
void scrolled(int value);
@@ -126,62 +104,17 @@ protected:
void showEvent(QShowEvent* event) override;
private slots:
void handleScrollRequest();
void setValue();
void previousReference();
void nextReference();
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 previousLocalReference();
void nextLocalReference();
void setModeList();
void setModeSingle();
private:
struct Reference
{
Reference()
: tokenId(0)
, locationId(0)
, locationType(LOCATION_TOKEN)
{
}
FilePath filePath;
Id tokenId;
Id locationId;
LocationType locationType;
};
void showCurrentReference(bool fromUI);
void showCurrentLocalReference();
void updateRefLabels();
struct ScrollRequest
{
ScrollRequest()
: lineNumber(0)
, locationId(0)
, animated(false)
, target(QtCodeNavigateable::SCROLL_VISIBLE)
{
}
FilePath filePath;
size_t lineNumber;
Id locationId;
bool animated;
QtCodeNavigateable::ScrollTarget target;
};
void handleMessage(MessageCodeReference* message) override;
void handleMessage(MessageIndexingFinished* message) override;
void handleMessage(MessageShowReference* message) override;
void handleMessage(MessageSwitchColorScheme* message) override;
void handleMessage(MessageWindowFocus* message) override;
@@ -205,12 +138,6 @@ private:
std::set<Id> m_focusedTokenIds;
std::map<Id, ErrorInfo> m_errorInfos;
Id m_activeTokenId;
int m_value;
QtSearchBarButton* m_prevFileButton;
QtSearchBarButton* m_nextFileButton;
QtSearchBarButton* m_prevReferenceButton;
QtSearchBarButton* m_nextReferenceButton;
QLabel* m_refLabel;
@@ -224,16 +151,7 @@ private:
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;
CodeScrollParams m_scrollParams;
std::vector<std::pair<QtCodeArea*, Id>> m_screenMatches;
Id m_activeScreenMatchId = 0;
+5 -62
View File
@@ -10,54 +10,6 @@
#include "QtCodeNavigator.h"
#include "QtCodeFile.h"
QtCodeSnippet* QtCodeSnippet::merged(
const QtCodeSnippet* a, const QtCodeSnippet* b, QtCodeNavigator* navigator, QtCodeFile* file)
{
const QtCodeSnippet* first = a->getStartLineNumber() < b->getStartLineNumber() ? a : b;
const QtCodeSnippet* second = a->getStartLineNumber() > b->getStartLineNumber() ? a : b;
SourceLocationFile* aFile = a->m_codeArea->getSourceLocationFile().get();
SourceLocationFile* bFile = b->m_codeArea->getSourceLocationFile().get();
std::shared_ptr<SourceLocationFile> locationFile = std::make_shared<SourceLocationFile>(
aFile->getFilePath(), aFile->getLanguage(), aFile->isWhole(), aFile->isComplete(), aFile->isIndexed());
aFile->forEachSourceLocation(
[&locationFile](SourceLocation* loc)
{
locationFile->addSourceLocationCopy(loc);
}
);
bFile->forEachSourceLocation(
[&locationFile](SourceLocation* loc)
{
locationFile->addSourceLocationCopy(loc);
}
);
std::string code = first->getCode();
std::string secondCode = second->getCode();
int secondCodeStartIndex = 0;
for (size_t i = second->getStartLineNumber(); i <= first->getEndLineNumber(); i++)
{
secondCodeStartIndex = secondCode.find("\n", secondCodeStartIndex) + 1;
}
code += secondCode.substr(secondCodeStartIndex, secondCode.npos);
CodeSnippetParams params;
params.startLineNumber = first->getStartLineNumber();
params.title = first->m_titleString;
params.titleId = first->m_titleId;
params.footer = second->m_footerString;
params.footerId = second->m_footerId;
params.code = code;
params.locationFile = locationFile;
return new QtCodeSnippet(params, navigator, file);
}
QtCodeSnippet::QtCodeSnippet(const CodeSnippetParams& params, QtCodeNavigator* navigator, QtCodeFile* file)
: QFrame(file)
, m_navigator(navigator)
@@ -78,7 +30,7 @@ QtCodeSnippet::QtCodeSnippet(const CodeSnippetParams& params, QtCodeNavigator* n
layout->setAlignment(Qt::AlignTop);
setLayout(layout);
if (!m_titleString.empty() && !params.reduced)
if (!m_titleString.empty() && !params.isOverview)
{
m_title = createScopeLine(layout);
if (m_titleId == 0) // title is a file path
@@ -92,7 +44,7 @@ QtCodeSnippet::QtCodeSnippet(const CodeSnippetParams& params, QtCodeNavigator* n
connect(m_title, &QPushButton::clicked, this, &QtCodeSnippet::clickedTitle);
}
m_codeArea = new QtCodeArea(params.startLineNumber, params.code, params.locationFile, navigator, !params.reduced, this);
m_codeArea = new QtCodeArea(params.startLineNumber, params.code, params.locationFile, navigator, !params.isOverview, this);
layout->addWidget(m_codeArea);
if (!m_footerString.empty())
@@ -139,7 +91,7 @@ int QtCodeSnippet::lineNumberDigits() const
return m_codeArea->lineNumberDigits();
}
void QtCodeSnippet::updateCodeSnippet(const CodeSnippetParams& params)
void QtCodeSnippet::updateSourceLocations(const CodeSnippetParams& params)
{
m_codeArea->updateSourceLocations(params.locationFile);
@@ -199,11 +151,6 @@ 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);
@@ -217,10 +164,8 @@ void QtCodeSnippet::clickedTitle()
}
else
{
getFile()->requestWholeFileContent();
getFile()->requestWholeFileContent(getStartLineNumber());
}
m_navigator->requestScroll(getFile()->getFilePath(), getStartLineNumber(), 0, true, QtCodeNavigateable::SCROLL_VISIBLE);
}
void QtCodeSnippet::clickedFooter()
@@ -231,10 +176,8 @@ void QtCodeSnippet::clickedFooter()
}
else
{
getFile()->requestWholeFileContent();
getFile()->requestWholeFileContent(getEndLineNumber());
}
m_navigator->requestScroll(getFile()->getFilePath(), getEndLineNumber(), 0, true, QtCodeNavigateable::SCROLL_CENTER);
}
QPushButton* QtCodeSnippet::createScopeLine(QBoxLayout* layout)
+1 -6
View File
@@ -23,9 +23,6 @@ class QtCodeSnippet
Q_OBJECT
public:
static QtCodeSnippet* merged(
const QtCodeSnippet* a, const QtCodeSnippet* b, QtCodeNavigator* navigator, QtCodeFile* file);
QtCodeSnippet(const CodeSnippetParams& params, QtCodeNavigator* navigator, QtCodeFile* file);
virtual ~QtCodeSnippet();
@@ -37,7 +34,7 @@ public:
int lineNumberDigits() const;
void updateCodeSnippet(const CodeSnippetParams& params);
void updateSourceLocations(const CodeSnippetParams& params);
void updateLineNumberAreaWidthForDigits(int digits);
void updateContent();
@@ -54,8 +51,6 @@ 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:
+80 -119
View File
@@ -35,7 +35,7 @@ void QtCodeView::refreshView()
setStyleSheet();
m_widget->clearCaches();
m_widget->clearCache();
QtCodeArea::clearAnnotationColors();
QtHighlighter::clearHighlightingRules();
@@ -99,8 +99,6 @@ void QtCodeView::clear()
{
m_widget->clear();
});
m_scrollParams = ScrollParams();
}
bool QtCodeView::showsErrors() const
@@ -108,123 +106,97 @@ bool QtCodeView::showsErrors() const
return m_widget->hasErrors();
}
void QtCodeView::showCodeSnippets(const std::vector<CodeSnippetParams>& snippets, const CodeParams params)
void QtCodeView::showSnippets(
const std::vector<CodeFileParams> files, const CodeParams params, const CodeScrollParams scrollParams)
{
m_onQtThread([=]()
{
TRACE("show code snippets");
TRACE("show snippets");
m_widget->setMode(QtCodeNavigator::MODE_LIST);
if (params.clearSnippets)
{
m_widget->clearCodeSnippets(params.useSingleFileCache);
m_widget->setActiveTokenIds(params.activeTokenIds);
m_widget->setErrorInfos(params.errorInfos);
if (!snippets.size())
{
m_widget->clearFile();
}
m_widget->clearSnippets();
}
bool addedFiles = false;
setNavigationState(params);
for (const CodeSnippetParams& snippet : snippets)
for (const CodeFileParams& file : files)
{
if (snippet.isCollapsed)
{
m_widget->addFile(snippet.locationFile, snippet.refCount, snippet.modificationTime);
addedFiles = true;
}
else
{
m_widget->addCodeSnippet(snippet);
}
m_widget->addSnippetFile(file);
}
if (addedFiles)
m_widget->updateFiles();
m_widget->scrollTo(scrollParams, !params.clearSnippets);
});
}
void QtCodeView::showSingleFile(
const CodeFileParams file, const CodeParams params, const CodeScrollParams scrollParams)
{
m_onQtThread([=]()
{
TRACE("show single file");
bool animatedScroll = !m_widget->isInListMode();
m_widget->setMode(QtCodeNavigator::MODE_SINGLE);
if (params.clearSnippets)
{
m_widget->addedFiles();
m_widget->clearSnippets();
}
if (params.showContents)
setNavigationState(params);
if (file.locationFile)
{
if (m_widget->addSingleFile(file, params.useSingleFileCache))
{
animatedScroll = false;
}
m_widget->updateFiles();
m_widget->showContents();
performScroll();
m_widget->scrollTo(scrollParams, animatedScroll);
}
else
{
m_widget->clearFile();
}
});
}
void QtCodeView::updateCodeSnippets(const std::vector<CodeSnippetParams>& snippets)
void QtCodeView::updateSourceLocations(const std::vector<CodeFileParams> files)
{
m_onQtThread([=]()
{
TRACE("update code snippets");
TRACE("update source locations");
for (const CodeSnippetParams& snippet : snippets)
for (const CodeFileParams& file : files)
{
if (!snippet.locationFile || snippet.isCollapsed || snippet.reduced)
for (const CodeSnippetParams& snippet : file.snippetParams)
{
continue;
if (snippet.hasAllSourceLocations)
{
m_widget->updateSourceLocations(snippet);
}
}
m_widget->updateCodeSnippet(snippet);
if (file.fileParams && file.fileParams->hasAllSourceLocations)
{
m_widget->updateSourceLocations(*file.fileParams.get());
}
}
});
}
void QtCodeView::scrollTo(const ScrollParams params)
{
m_scrollParams = params;
}
void QtCodeView::setFileState(const FilePath filePath, FileState state)
void QtCodeView::scrollTo(const CodeScrollParams params, bool animated)
{
m_onQtThread([=]()
{
switch (state)
{
case FILE_MINIMIZED:
m_widget->setFileMinimized(filePath);
break;
case FILE_SNIPPETS:
m_widget->setFileSnippets(filePath);
break;
case FILE_MAXIMIZED:
m_widget->setFileMaximized(filePath);
break;
}
});
}
void QtCodeView::showActiveSnippet(
const std::vector<Id>& activeTokenIds, std::shared_ptr<SourceLocationCollection> collection, bool scrollTo)
{
m_onQtThread([=]()
{
TRACE("show active snippet");
m_widget->showActiveSnippet(activeTokenIds, collection, scrollTo);
});
}
void QtCodeView::showActiveTokenIds(const std::vector<Id>& activeTokenIds)
{
m_onQtThread([=]()
{
m_widget->setActiveTokenIds(activeTokenIds);
m_widget->updateFiles();
performScroll();
});
}
void QtCodeView::showActiveLocalSymbolIds(const std::vector<Id>& activeLocalSymbolIds)
{
m_onQtThread([=]()
{
m_widget->setActiveLocalTokenIds(activeLocalSymbolIds, LOCATION_LOCAL_SYMBOL);
m_widget->updateFiles();
m_widget->scrollTo(params, animated);
});
}
@@ -244,17 +216,6 @@ void QtCodeView::defocusTokenIds()
});
}
void QtCodeView::showContents()
{
m_onQtThread([=]()
{
TRACE("show contents");
m_widget->updateFiles();
m_widget->showContents();
performScroll();
});
}
bool QtCodeView::isInListMode() const
{
return m_widget->isInListMode();
@@ -262,15 +223,7 @@ bool QtCodeView::isInListMode() const
void QtCodeView::setMode(bool listMode)
{
if (isInListMode() == listMode)
{
return;
}
m_onQtThread([=]()
{
m_widget->setMode(listMode ? QtCodeNavigator::MODE_LIST : QtCodeNavigator::MODE_SINGLE);
});
m_widget->setMode(listMode ? QtCodeNavigator::MODE_LIST : QtCodeNavigator::MODE_SINGLE);
}
bool QtCodeView::hasSingleFileCached(const FilePath& filePath) const
@@ -278,26 +231,34 @@ bool QtCodeView::hasSingleFileCached(const FilePath& filePath) const
return m_widget->hasSingleFileCached(filePath);
}
void QtCodeView::performScroll()
void QtCodeView::setNavigationState(const CodeParams& params)
{
switch (m_scrollParams.type)
m_widget->setActiveTokenIds(params.activeTokenIds);
m_widget->setErrorInfos(params.errorInfos);
if (params.activeLocationIds.size())
{
case ScrollParams::SCROLL_TO_DEFINITION:
m_widget->scrollToDefinition(m_scrollParams.animated, m_scrollParams.ignoreActiveReference);
break;
case ScrollParams::SCROLL_TO_LINE:
m_widget->scrollToLine(m_scrollParams.filePath, m_scrollParams.line);
break;
case ScrollParams::SCROLL_TO_VALUE:
m_widget->scrollToValue(m_scrollParams.value, m_scrollParams.inListMode);
break;
default:
break;
m_widget->setCurrentActiveLocationIds(params.activeLocationIds);
}
m_widget->scrollToSnippetIfRequested();
if (params.activeLocalSymbolIds.size())
{
if (params.activeLocalSymbolType == LOCATION_TOKEN)
{
m_widget->setCurrentActiveTokenIds(
params.currentActiveLocalLocationIds.size() ? std::vector<Id>() : params.activeLocalSymbolIds);
}
m_scrollParams = ScrollParams();
m_widget->setActiveLocalTokenIds(params.activeLocalSymbolIds, params.activeLocalSymbolType);
}
if (params.currentActiveLocalLocationIds.size())
{
m_widget->setCurrentActiveLocalLocationIds(params.currentActiveLocalLocationIds);
}
m_widget->updateReferenceCount(
params.referenceCount, params.referenceIndex, params.localReferenceCount, params.localReferenceIndex);
}
void QtCodeView::setStyleSheet() const
+12 -15
View File
@@ -27,38 +27,35 @@ public:
// CodeView implementation
void clear() override;
void showCodeSnippets(const std::vector<CodeSnippetParams>& snippets, const CodeParams params) override;
void updateCodeSnippets(const std::vector<CodeSnippetParams>& snippets) override;
void scrollTo(const ScrollParams params) override;
void showSnippets(
const std::vector<CodeFileParams> files, const CodeParams params, const CodeScrollParams scrollParams) override;
void showSingleFile(
const CodeFileParams file, const CodeParams params, const CodeScrollParams scrollParams) override;
void updateSourceLocations(const std::vector<CodeFileParams> files) override;
void scrollTo(const CodeScrollParams params, bool animated) override;
bool showsErrors() const override;
void setFileState(const FilePath filePath, FileState state) override;
void showActiveSnippet(
const std::vector<Id>& activeTokenIds, std::shared_ptr<SourceLocationCollection> collection, bool scrollTo) override;
void showActiveTokenIds(const std::vector<Id>& activeTokenIds) override;
void showActiveLocalSymbolIds(const std::vector<Id>& activeLocalSymbolIds) override;
void focusTokenIds(const std::vector<Id>& focusedTokenIds) override;
void defocusTokenIds() override;
void showContents() override;
bool isInListMode() const override;
void setMode(bool listMode) override;
bool hasSingleFileCached(const FilePath& filePath) const override;
private:
void performScroll();
void setNavigationState(const CodeParams& params);
// void performScroll(const CodeScrollParams& scrollParams);
void setStyleSheet() const;
QtThreadedLambdaFunctor m_onQtThread;
QtCodeNavigator* m_widget;
ScrollParams m_scrollParams;
};
# endif // QT_CODE_VIEW_H
+1 -1
View File
@@ -39,5 +39,5 @@ Test Suites:\n\n
<type>C++ Source Group</type>
</source_group_475571d1-b082-4fff-81c5-d099c19f957d>
</source_groups>
<version>7</version>
<version>8</version>
</config>
+1 -1
View File
@@ -29,5 +29,5 @@
<type>C++ Source Group</type>
</source_group_475571d1-b082-4fff-81c5-d099c19f957d>
</source_groups>
<version>7</version>
<version>8</version>
</config>