logic: Refactored Code View to process all contents in one update
* Use unified showCodeSnippets method for setting file information on CodeView * Made async initial file and snippet expansion synced * Add ScrollParams API to CodeView * Regard scope size when scrolling to definition * Only use QtThreadedLambdaFunctor in QtCodeView now
This commit is contained in:
@@ -357,7 +357,6 @@ add_files(
|
|||||||
utility/messaging/type/MessageClearLogView.h
|
utility/messaging/type/MessageClearLogView.h
|
||||||
utility/messaging/type/MessageClearStatusView.h
|
utility/messaging/type/MessageClearStatusView.h
|
||||||
utility/messaging/type/MessageCodeReference.h
|
utility/messaging/type/MessageCodeReference.h
|
||||||
utility/messaging/type/MessageCodeViewExpandedInitialFiles.h
|
|
||||||
utility/messaging/type/MessageColorSchemeTest.h
|
utility/messaging/type/MessageColorSchemeTest.h
|
||||||
utility/messaging/type/MessageCreateBookmark.h
|
utility/messaging/type/MessageCreateBookmark.h
|
||||||
utility/messaging/type/MessageCreateBookmarkCategory.h
|
utility/messaging/type/MessageCreateBookmarkCategory.h
|
||||||
@@ -424,7 +423,7 @@ add_files(
|
|||||||
utility/messaging/MessageListenerBase.h
|
utility/messaging/MessageListenerBase.h
|
||||||
utility/messaging/MessageQueue.cpp
|
utility/messaging/MessageQueue.cpp
|
||||||
utility/messaging/MessageQueue.h
|
utility/messaging/MessageQueue.h
|
||||||
|
|
||||||
utility/migration/Migration.h
|
utility/migration/Migration.h
|
||||||
utility/migration/Migrator.h
|
utility/migration/Migrator.h
|
||||||
|
|
||||||
|
|||||||
@@ -72,7 +72,7 @@ void ActivationController::handleMessage(MessageActivateFile* message)
|
|||||||
|
|
||||||
if (message->line > 0)
|
if (message->line > 0)
|
||||||
{
|
{
|
||||||
MessageScrollToLine(message->filePath, message->line, true).dispatch();
|
MessageScrollToLine(message->filePath, message->line).dispatch();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -18,9 +18,6 @@
|
|||||||
|
|
||||||
CodeController::CodeController(StorageAccess* storageAccess)
|
CodeController::CodeController(StorageAccess* storageAccess)
|
||||||
: m_storageAccess(storageAccess)
|
: m_storageAccess(storageAccess)
|
||||||
, m_scrollToDefinition(false)
|
|
||||||
, m_scrollToValue(-1)
|
|
||||||
, m_scrollToLine(0)
|
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -94,10 +91,10 @@ void CodeController::handleMessage(MessageActivateAll* message)
|
|||||||
|
|
||||||
statsSnippet.code = ss.str();
|
statsSnippet.code = ss.str();
|
||||||
|
|
||||||
CodeView* view = getView();
|
CodeView::CodeParams params;
|
||||||
view->showCodeSnippets(std::vector<CodeSnippetParams>(1, statsSnippet), std::vector<Id>(), true);
|
params.clearSnippets = true;
|
||||||
|
params.showContents = !message->isReplayed();
|
||||||
showContents(message);
|
getView()->showCodeSnippets(std::vector<CodeSnippetParams>(1, statsSnippet), params);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CodeController::handleMessage(MessageActivateLocalSymbols* message)
|
void CodeController::handleMessage(MessageActivateLocalSymbols* message)
|
||||||
@@ -112,47 +109,47 @@ void CodeController::handleMessage(MessageActivateTokens* message)
|
|||||||
|
|
||||||
CodeView* view = getView();
|
CodeView* view = getView();
|
||||||
|
|
||||||
std::vector<Id> activeTokenIds = message->tokenIds;
|
CodeView::CodeParams params;
|
||||||
if (!activeTokenIds.size())
|
params.activeTokenIds = message->tokenIds;
|
||||||
|
if (!params.activeTokenIds.size())
|
||||||
{
|
{
|
||||||
view->clear();
|
view->clear();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!message->keepContent())
|
params.clearSnippets = !message->keepContent();
|
||||||
{
|
params.showContents = !message->isReplayed();
|
||||||
view->clearCodeSnippets();
|
|
||||||
}
|
|
||||||
|
|
||||||
Id declarationId = 0; // 0 means that no token is found.
|
Id declarationId = 0; // 0 means that no token is found.
|
||||||
if (!message->isAggregation)
|
if (!message->isAggregation)
|
||||||
{
|
{
|
||||||
activeTokenIds = m_storageAccess->getActiveTokenIdsForId(activeTokenIds[0], &declarationId);
|
params.activeTokenIds = m_storageAccess->getActiveTokenIdsForId(params.activeTokenIds[0], &declarationId);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (message->isEdge)
|
if (message->isEdge)
|
||||||
{
|
{
|
||||||
std::shared_ptr<SourceLocationCollection> collection = m_storageAccess->getSourceLocationsForTokenIds(activeTokenIds);
|
std::shared_ptr<SourceLocationCollection> collection =
|
||||||
view->showActiveSnippet(activeTokenIds, collection, message->isLast());
|
m_storageAccess->getSourceLocationsForTokenIds(params.activeTokenIds);
|
||||||
|
view->showActiveSnippet(params.activeTokenIds, collection, message->isLast());
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
else if (message->keepContent())
|
|
||||||
|
if (message->keepContent())
|
||||||
{
|
{
|
||||||
view->showActiveTokenIds(activeTokenIds);
|
view->showActiveTokenIds(params.activeTokenIds);
|
||||||
if (m_scrollToDefinition)
|
|
||||||
{
|
|
||||||
getView()->scrollToDefinition(true);
|
|
||||||
m_scrollToDefinition = false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
m_collection = m_storageAccess->getSourceLocationsForTokenIds(activeTokenIds);
|
CodeView::ScrollParams scrollParams(CodeView::ScrollParams::SCROLL_TO_DEFINITION);
|
||||||
view->showCodeSnippets(
|
scrollParams.ignoreActiveReference = true;
|
||||||
getSnippetsForActiveSourceLocations(m_collection.get(), declarationId),
|
view->scrollTo(scrollParams);
|
||||||
activeTokenIds,
|
|
||||||
!message->isReplayed() || message->isReplayCleared()
|
m_collection = m_storageAccess->getSourceLocationsForTokenIds(params.activeTokenIds);
|
||||||
);
|
|
||||||
m_scrollToDefinition = !message->isReplayed() || message->isReplayCleared();
|
std::vector<CodeSnippetParams> snippets = getSnippetsForActiveSourceLocations(m_collection.get(), declarationId);
|
||||||
|
expandVisibleSnippets(&snippets);
|
||||||
|
|
||||||
|
view->showCodeSnippets(snippets, params);
|
||||||
|
|
||||||
size_t fileCount = m_collection->getSourceLocationFileCount();
|
size_t fileCount = m_collection->getSourceLocationFileCount();
|
||||||
size_t referenceCount = m_collection->getSourceLocationCount();
|
size_t referenceCount = m_collection->getSourceLocationCount();
|
||||||
@@ -177,27 +174,23 @@ void CodeController::handleMessage(MessageActivateTokens* message)
|
|||||||
|
|
||||||
MessageStatus(ss.str()).dispatch();
|
MessageStatus(ss.str()).dispatch();
|
||||||
}
|
}
|
||||||
|
|
||||||
showContents(message);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void CodeController::handleMessage(MessageActivateTrailEdge* message)
|
void CodeController::handleMessage(MessageActivateTrailEdge* message)
|
||||||
{
|
{
|
||||||
TRACE("trail edge activate");
|
TRACE("trail edge activate");
|
||||||
|
|
||||||
CodeView* view = getView();
|
CodeView::ScrollParams scrollParams(CodeView::ScrollParams::SCROLL_TO_DEFINITION);
|
||||||
view->clearCodeSnippets();
|
getView()->scrollTo(scrollParams);
|
||||||
|
|
||||||
std::vector<Id> activeTokenIds = { message->tokenId };
|
CodeView::CodeParams params;
|
||||||
m_collection = m_storageAccess->getSourceLocationsForTokenIds(activeTokenIds);
|
params.clearSnippets = true;
|
||||||
|
params.showContents = !message->isReplayed();
|
||||||
|
params.activeTokenIds.push_back(message->tokenId);
|
||||||
|
|
||||||
view->showCodeSnippets(
|
m_collection = m_storageAccess->getSourceLocationsForTokenIds(params.activeTokenIds);
|
||||||
getSnippetsForActiveSourceLocations(m_collection.get(), 0),
|
|
||||||
activeTokenIds,
|
|
||||||
!message->isReplayed() || message->isReplayCleared()
|
|
||||||
);
|
|
||||||
|
|
||||||
showContents(message);
|
getView()->showCodeSnippets(getSnippetsForActiveSourceLocations(m_collection.get(), 0), params);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CodeController::handleMessage(MessageChangeFileView* message)
|
void CodeController::handleMessage(MessageChangeFileView* message)
|
||||||
@@ -212,87 +205,38 @@ void CodeController::handleMessage(MessageChangeFileView* message)
|
|||||||
CodeView* view = getView();
|
CodeView* view = getView();
|
||||||
bool inListMode = view->isInListMode();
|
bool inListMode = view->isInListMode();
|
||||||
|
|
||||||
MessageChangeFileView::FileState state = message->state;
|
CodeView::FileState state;
|
||||||
if (state == MessageChangeFileView::FILE_DEFAULT_FOR_MODE)
|
switch (message->state)
|
||||||
{
|
|
||||||
state = inListMode ? MessageChangeFileView::FILE_SNIPPETS : MessageChangeFileView::FILE_MAXIMIZED;
|
|
||||||
}
|
|
||||||
|
|
||||||
switch (state)
|
|
||||||
{
|
{
|
||||||
case MessageChangeFileView::FILE_MINIMIZED:
|
case MessageChangeFileView::FILE_MINIMIZED:
|
||||||
view->setFileState(message->filePath, CodeView::FILE_MINIMIZED);
|
state = CodeView::FILE_MINIMIZED;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case MessageChangeFileView::FILE_SNIPPETS:
|
case MessageChangeFileView::FILE_SNIPPETS:
|
||||||
if (message->needsData && inListMode)
|
state = CodeView::FILE_SNIPPETS;
|
||||||
{
|
|
||||||
std::shared_ptr<SourceLocationFile> file = m_collection->getSourceLocationFileByPath(message->filePath);
|
|
||||||
if (!file)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (message->showErrors)
|
|
||||||
{
|
|
||||||
file->setIsWhole(false);
|
|
||||||
}
|
|
||||||
|
|
||||||
view->addCodeSnippets(getSnippetsForFile(file, !message->showErrors), false);
|
|
||||||
}
|
|
||||||
view->setFileState(message->filePath, CodeView::FILE_SNIPPETS);
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case MessageChangeFileView::FILE_MAXIMIZED:
|
case MessageChangeFileView::FILE_MAXIMIZED:
|
||||||
if (message->needsData)
|
state = CodeView::FILE_MAXIMIZED;
|
||||||
{
|
|
||||||
CodeSnippetParams params;
|
|
||||||
params.startLineNumber = 1;
|
|
||||||
params.refCount = -1;
|
|
||||||
|
|
||||||
std::shared_ptr<TextAccess> textAccess = m_storageAccess->getFileContent(message->filePath);
|
|
||||||
params.code = textAccess->getText();
|
|
||||||
|
|
||||||
params.modificationTime = m_storageAccess->getFileInfoForFilePath(message->filePath).lastWriteTime;
|
|
||||||
|
|
||||||
if (message->showErrors)
|
|
||||||
{
|
|
||||||
params.locationFile = m_collection->getSourceLocationFileByPath(message->filePath);
|
|
||||||
if (!params.locationFile)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
params.locationFile->setIsWhole(true);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
std::shared_ptr<SourceLocationFile> file =
|
|
||||||
m_storageAccess->getSourceLocationsForFile(message->filePath);
|
|
||||||
|
|
||||||
SourceLocationFile* activeLocations = m_collection->getSourceLocationFileByPath(message->filePath).get();
|
|
||||||
if (activeLocations)
|
|
||||||
{
|
|
||||||
activeLocations->forEachSourceLocation(
|
|
||||||
[&file](SourceLocation* location)
|
|
||||||
{
|
|
||||||
file->addSourceLocationCopy(location);
|
|
||||||
}
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
params.locationFile = file;
|
|
||||||
}
|
|
||||||
|
|
||||||
getView()->addCodeSnippets(std::vector<CodeSnippetParams>(1, params), false);
|
|
||||||
}
|
|
||||||
|
|
||||||
view->setFileState(message->filePath, CodeView::FILE_MAXIMIZED);
|
|
||||||
break;
|
break;
|
||||||
default:
|
|
||||||
|
case MessageChangeFileView::FILE_DEFAULT_FOR_MODE:
|
||||||
|
state = inListMode ? CodeView::FILE_SNIPPETS : CodeView::FILE_MAXIMIZED;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
showContents(message);
|
if (message->needsData)
|
||||||
|
{
|
||||||
|
CodeView::CodeParams params;
|
||||||
|
view->showCodeSnippets(getSnippetsForFileWithState(message->filePath, state, !message->showErrors), params);
|
||||||
|
}
|
||||||
|
|
||||||
|
view->setFileState(message->filePath, state);
|
||||||
|
|
||||||
|
if (!message->isReplayed())
|
||||||
|
{
|
||||||
|
view->showContents();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void CodeController::handleMessage(MessageClearErrorCount* message)
|
void CodeController::handleMessage(MessageClearErrorCount* message)
|
||||||
@@ -307,16 +251,16 @@ void CodeController::handleMessage(MessageDeactivateEdge* message)
|
|||||||
{
|
{
|
||||||
if (message->scrollToDefinition)
|
if (message->scrollToDefinition)
|
||||||
{
|
{
|
||||||
m_scrollToDefinition = true;
|
CodeView::ScrollParams scrollParams(CodeView::ScrollParams::SCROLL_TO_DEFINITION);
|
||||||
|
scrollParams.animated = true;
|
||||||
|
scrollParams.ignoreActiveReference = true;
|
||||||
|
getView()->scrollTo(scrollParams);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void CodeController::handleMessage(MessageFlushUpdates* message)
|
void CodeController::handleMessage(MessageFlushUpdates* message)
|
||||||
{
|
{
|
||||||
MessageCodeViewExpandedInitialFiles* msgPtr = nullptr;
|
getView()->showContents();
|
||||||
handleMessage(msgPtr);
|
|
||||||
|
|
||||||
showContents(message);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void CodeController::handleMessage(MessageFocusIn* message)
|
void CodeController::handleMessage(MessageFocusIn* message)
|
||||||
@@ -329,54 +273,28 @@ void CodeController::handleMessage(MessageFocusOut* message)
|
|||||||
getView()->defocusTokenIds();
|
getView()->defocusTokenIds();
|
||||||
}
|
}
|
||||||
|
|
||||||
void CodeController::handleMessage(MessageCodeViewExpandedInitialFiles* message)
|
|
||||||
{
|
|
||||||
if (m_scrollToDefinition || (message && message->scrollToDefinition))
|
|
||||||
{
|
|
||||||
getView()->scrollToDefinition(false);
|
|
||||||
m_scrollToDefinition = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (m_scrollToValue != -1)
|
|
||||||
{
|
|
||||||
getView()->scrollToValue(m_scrollToValue, m_scrollInListMode);
|
|
||||||
m_scrollToValue = -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (m_scrollToLine)
|
|
||||||
{
|
|
||||||
getView()->scrollToLine(m_scrollToFilePath, m_scrollToLine);
|
|
||||||
m_scrollToLine = 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void CodeController::handleMessage(MessageScrollToLine* message)
|
void CodeController::handleMessage(MessageScrollToLine* message)
|
||||||
{
|
{
|
||||||
m_scrollToFilePath = message->filePath;
|
CodeView::ScrollParams scrollParams(CodeView::ScrollParams::SCROLL_TO_LINE);
|
||||||
m_scrollToLine = message->line;
|
scrollParams.filePath = message->filePath;
|
||||||
|
scrollParams.line = message->line;
|
||||||
|
getView()->scrollTo(scrollParams);
|
||||||
|
|
||||||
if (message->isModified)
|
MessageStatus(
|
||||||
{
|
"Showing source location: " + message->filePath.str()
|
||||||
MessageStatus(
|
+ " : " + std::to_string(message->line) + ". The file was modified, please refresh.",
|
||||||
"Showing source location: " + message->filePath.str()
|
true
|
||||||
+ " : " + std::to_string(message->line) + ". The file was modified, please refresh.",
|
).dispatch();
|
||||||
true
|
|
||||||
).dispatch();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
MessageStatus(
|
|
||||||
"Showing source location: " + message->filePath.str() + " : " + std::to_string(message->line)
|
|
||||||
).dispatch();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void CodeController::handleMessage(MessageScrollCode* message)
|
void CodeController::handleMessage(MessageScrollCode* message)
|
||||||
{
|
{
|
||||||
if (message->isReplayed())
|
if (message->isReplayed())
|
||||||
{
|
{
|
||||||
m_scrollToValue = message->value;
|
CodeView::ScrollParams scrollParams(CodeView::ScrollParams::SCROLL_TO_VALUE);
|
||||||
m_scrollInListMode = message->inListMode;
|
scrollParams.value = message->value;
|
||||||
|
scrollParams.inListMode = message->inListMode;
|
||||||
|
getView()->scrollTo(scrollParams);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -387,23 +305,28 @@ void CodeController::handleMessage(MessageShowErrors* message)
|
|||||||
CodeView* view = getView();
|
CodeView* view = getView();
|
||||||
if (!view->showsErrors() || !message->errorId)
|
if (!view->showsErrors() || !message->errorId)
|
||||||
{
|
{
|
||||||
|
CodeView::ScrollParams scrollParams(CodeView::ScrollParams::SCROLL_TO_DEFINITION);
|
||||||
|
view->scrollTo(scrollParams);
|
||||||
|
|
||||||
std::vector<ErrorInfo> errors;
|
std::vector<ErrorInfo> errors;
|
||||||
m_collection = m_storageAccess->getErrorSourceLocationsLimited(&errors);
|
m_collection = m_storageAccess->getErrorSourceLocationsLimited(&errors);
|
||||||
std::vector<CodeSnippetParams> snippets = getSnippetsForCollection(m_collection);
|
std::vector<CodeSnippetParams> snippets = getSnippetsForCollection(m_collection);
|
||||||
|
|
||||||
std::sort(snippets.begin(), snippets.end(), CodeSnippetParams::sortById);
|
std::sort(snippets.begin(), snippets.end(), CodeSnippetParams::sortById);
|
||||||
|
|
||||||
view->clear();
|
expandVisibleSnippets(&snippets);
|
||||||
view->setErrorInfos(errors);
|
|
||||||
view->showCodeSnippets(
|
|
||||||
snippets, std::vector<Id>(), !message->errorId && (!message->isReplayed() || message->isReplayCleared()));
|
|
||||||
|
|
||||||
showContents(message);
|
CodeView::CodeParams params;
|
||||||
|
params.clearSnippets = true;
|
||||||
|
params.errorInfos = errors;
|
||||||
|
params.showContents = !message->isReplayed();
|
||||||
|
|
||||||
|
view->showCodeSnippets(snippets, params);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (message->errorId)
|
if (message->errorId)
|
||||||
{
|
{
|
||||||
view->showActiveSnippet(std::vector<Id>(1, message->errorId), m_collection, true);
|
view->showActiveSnippet(std::vector<Id>(1, message->errorId), m_collection, message->isLast());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -411,14 +334,18 @@ void CodeController::handleMessage(MessageSearchFullText* message)
|
|||||||
{
|
{
|
||||||
TRACE("code fulltext");
|
TRACE("code fulltext");
|
||||||
|
|
||||||
CodeView* view = getView();
|
|
||||||
view->clear();
|
|
||||||
|
|
||||||
m_collection = m_storageAccess->getFullTextSearchLocations(message->searchTerm, message->caseSensitive);
|
m_collection = m_storageAccess->getFullTextSearchLocations(message->searchTerm, message->caseSensitive);
|
||||||
view->showCodeSnippets(
|
|
||||||
getSnippetsForCollection(m_collection, true), std::vector<Id>(), !message->isReplayed() || message->isReplayCleared());
|
|
||||||
|
|
||||||
showContents(message);
|
CodeView::ScrollParams scrollParams(CodeView::ScrollParams::SCROLL_TO_DEFINITION);
|
||||||
|
getView()->scrollTo(scrollParams);
|
||||||
|
|
||||||
|
std::vector<CodeSnippetParams> snippets = getSnippetsForCollection(m_collection, true);
|
||||||
|
expandVisibleSnippets(&snippets);
|
||||||
|
|
||||||
|
CodeView::CodeParams params;
|
||||||
|
params.clearSnippets = true;
|
||||||
|
params.showContents = !message->isReplayed();
|
||||||
|
getView()->showCodeSnippets(snippets, params);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CodeController::handleMessage(MessageShowScope* message)
|
void CodeController::handleMessage(MessageShowScope* message)
|
||||||
@@ -443,32 +370,23 @@ void CodeController::handleMessage(MessageShowScope* message)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
snippets[0].insertSnippet = true;
|
||||||
|
|
||||||
if (message->showErrors)
|
if (message->showErrors)
|
||||||
{
|
{
|
||||||
snippets[0].locationFile = m_collection->getSourceLocationFileByPath(snippets[0].locationFile->getFilePath());
|
snippets[0].locationFile = m_collection->getSourceLocationFileByPath(snippets[0].locationFile->getFilePath());
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
SourceLocationFile* activeLocations =
|
addActiveSourceLocations(snippets[0].locationFile);
|
||||||
m_collection->getSourceLocationFileByPath(snippets[0].locationFile->getFilePath()).get();
|
|
||||||
if (activeLocations)
|
|
||||||
{
|
|
||||||
std::shared_ptr<SourceLocationFile> file = snippets[0].locationFile;
|
|
||||||
activeLocations->forEachSourceLocation(
|
|
||||||
[&file](SourceLocation* location)
|
|
||||||
{
|
|
||||||
file->addSourceLocationCopy(location);
|
|
||||||
}
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
getView()->addCodeSnippets(snippets, true);
|
CodeView::CodeParams params;
|
||||||
|
params.showContents = !message->isReplayed();
|
||||||
showContents(message);
|
getView()->showCodeSnippets(snippets, params);
|
||||||
}
|
}
|
||||||
|
|
||||||
CodeView* CodeController::getView()
|
CodeView* CodeController::getView() const
|
||||||
{
|
{
|
||||||
return Controller::getView<CodeView>();
|
return Controller::getView<CodeView>();
|
||||||
}
|
}
|
||||||
@@ -480,14 +398,103 @@ void CodeController::clear()
|
|||||||
m_collection.reset();
|
m_collection.reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
void CodeController::showContents(MessageBase* message)
|
void CodeController::expandVisibleSnippets(std::vector<CodeSnippetParams>* snippets) const
|
||||||
{
|
{
|
||||||
if (!message->isReplayed())
|
bool inListMode = getView()->isInListMode();
|
||||||
|
|
||||||
|
size_t filesToExpand = inListMode ? std::min(int(snippets->size()), 3) : 1;
|
||||||
|
CodeView::FileState state = inListMode ? CodeView::FILE_SNIPPETS : CodeView::FILE_MAXIMIZED;
|
||||||
|
|
||||||
|
for (size_t i = 0; i < filesToExpand; i++)
|
||||||
{
|
{
|
||||||
getView()->showContents();
|
CodeSnippetParams& oldSnippet = snippets->at(i);
|
||||||
|
|
||||||
|
if (!inListMode && getView()->hasSingleFileCached(oldSnippet.locationFile->getFilePath()))
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::vector<CodeSnippetParams> newSnippets =
|
||||||
|
getSnippetsForFileWithState(oldSnippet.locationFile->getFilePath(), state, true);
|
||||||
|
if (!newSnippets.size())
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (CodeSnippetParams newSnippet : newSnippets)
|
||||||
|
{
|
||||||
|
newSnippet.isDeclaration = oldSnippet.isDeclaration;
|
||||||
|
newSnippet.isDefinition = oldSnippet.isDefinition;
|
||||||
|
|
||||||
|
newSnippet.isCollapsed = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
snippets->insert(snippets->end(), newSnippets.begin(), newSnippets.end());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::vector<CodeSnippetParams> CodeController::getSnippetsForFileWithState(
|
||||||
|
const FilePath& filePath, CodeView::FileState state, bool addSourceLocations) const
|
||||||
|
{
|
||||||
|
TRACE();
|
||||||
|
|
||||||
|
std::vector<CodeSnippetParams> snippets;
|
||||||
|
|
||||||
|
switch (state)
|
||||||
|
{
|
||||||
|
case CodeView::FILE_SNIPPETS:
|
||||||
|
{
|
||||||
|
std::shared_ptr<SourceLocationFile> file = m_collection->getSourceLocationFileByPath(filePath);
|
||||||
|
if (!file)
|
||||||
|
{
|
||||||
|
return snippets;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!addSourceLocations)
|
||||||
|
{
|
||||||
|
file->setIsWhole(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
snippets = getSnippetsForFile(file, addSourceLocations);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case CodeView::FILE_MAXIMIZED:
|
||||||
|
{
|
||||||
|
CodeSnippetParams params;
|
||||||
|
params.startLineNumber = 1;
|
||||||
|
params.refCount = -1;
|
||||||
|
|
||||||
|
std::shared_ptr<TextAccess> textAccess = m_storageAccess->getFileContent(filePath);
|
||||||
|
params.code = textAccess->getText();
|
||||||
|
|
||||||
|
params.modificationTime = m_storageAccess->getFileInfoForFilePath(filePath).lastWriteTime;
|
||||||
|
|
||||||
|
if (!addSourceLocations)
|
||||||
|
{
|
||||||
|
params.locationFile = m_collection->getSourceLocationFileByPath(filePath);
|
||||||
|
if (!params.locationFile)
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
params.locationFile->setIsWhole(true);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
params.locationFile = m_storageAccess->getSourceLocationsForFile(filePath);
|
||||||
|
addActiveSourceLocations(params.locationFile);
|
||||||
|
}
|
||||||
|
|
||||||
|
snippets.push_back(params);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
return snippets;
|
||||||
|
}
|
||||||
|
|
||||||
std::vector<CodeSnippetParams> CodeController::getSnippetsForActiveSourceLocations(
|
std::vector<CodeSnippetParams> CodeController::getSnippetsForActiveSourceLocations(
|
||||||
const SourceLocationCollection* collection, Id declarationId
|
const SourceLocationCollection* collection, Id declarationId
|
||||||
) const {
|
) const {
|
||||||
@@ -857,3 +864,17 @@ void CodeController::addModificationTimes(std::vector<CodeSnippetParams>& snippe
|
|||||||
snippet.modificationTime = fileInfoMap[snippet.locationFile->getFilePath()].lastWriteTime;
|
snippet.modificationTime = fileInfoMap[snippet.locationFile->getFilePath()].lastWriteTime;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CodeController::addActiveSourceLocations(std::shared_ptr<SourceLocationFile> locationFile) const
|
||||||
|
{
|
||||||
|
SourceLocationFile* activeLocations = m_collection->getSourceLocationFileByPath(locationFile->getFilePath()).get();
|
||||||
|
if (activeLocations)
|
||||||
|
{
|
||||||
|
activeLocations->forEachSourceLocation(
|
||||||
|
[&locationFile](SourceLocation* location)
|
||||||
|
{
|
||||||
|
locationFile->addSourceLocationCopy(location);
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -12,7 +12,6 @@
|
|||||||
#include "utility/messaging/type/MessageActivateTrailEdge.h"
|
#include "utility/messaging/type/MessageActivateTrailEdge.h"
|
||||||
#include "utility/messaging/type/MessageChangeFileView.h"
|
#include "utility/messaging/type/MessageChangeFileView.h"
|
||||||
#include "utility/messaging/type/MessageClearErrorCount.h"
|
#include "utility/messaging/type/MessageClearErrorCount.h"
|
||||||
#include "utility/messaging/type/MessageCodeViewExpandedInitialFiles.h"
|
|
||||||
#include "utility/messaging/type/MessageDeactivateEdge.h"
|
#include "utility/messaging/type/MessageDeactivateEdge.h"
|
||||||
#include "utility/messaging/type/MessageFlushUpdates.h"
|
#include "utility/messaging/type/MessageFlushUpdates.h"
|
||||||
#include "utility/messaging/type/MessageFocusIn.h"
|
#include "utility/messaging/type/MessageFocusIn.h"
|
||||||
@@ -41,7 +40,6 @@ class CodeController
|
|||||||
, public MessageListener<MessageActivateTrailEdge>
|
, public MessageListener<MessageActivateTrailEdge>
|
||||||
, public MessageListener<MessageChangeFileView>
|
, public MessageListener<MessageChangeFileView>
|
||||||
, public MessageListener<MessageClearErrorCount>
|
, public MessageListener<MessageClearErrorCount>
|
||||||
, public MessageListener<MessageCodeViewExpandedInitialFiles>
|
|
||||||
, public MessageListener<MessageDeactivateEdge>
|
, public MessageListener<MessageDeactivateEdge>
|
||||||
, public MessageListener<MessageFlushUpdates>
|
, public MessageListener<MessageFlushUpdates>
|
||||||
, public MessageListener<MessageFocusIn>
|
, public MessageListener<MessageFocusIn>
|
||||||
@@ -65,7 +63,6 @@ private:
|
|||||||
virtual void handleMessage(MessageActivateTrailEdge* message);
|
virtual void handleMessage(MessageActivateTrailEdge* message);
|
||||||
virtual void handleMessage(MessageChangeFileView* message);
|
virtual void handleMessage(MessageChangeFileView* message);
|
||||||
virtual void handleMessage(MessageClearErrorCount* message);
|
virtual void handleMessage(MessageClearErrorCount* message);
|
||||||
virtual void handleMessage(MessageCodeViewExpandedInitialFiles* message);
|
|
||||||
virtual void handleMessage(MessageDeactivateEdge* message);
|
virtual void handleMessage(MessageDeactivateEdge* message);
|
||||||
virtual void handleMessage(MessageFlushUpdates* message);
|
virtual void handleMessage(MessageFlushUpdates* message);
|
||||||
virtual void handleMessage(MessageFocusIn* message);
|
virtual void handleMessage(MessageFocusIn* message);
|
||||||
@@ -76,11 +73,14 @@ private:
|
|||||||
virtual void handleMessage(MessageShowErrors* message);
|
virtual void handleMessage(MessageShowErrors* message);
|
||||||
virtual void handleMessage(MessageShowScope* message);
|
virtual void handleMessage(MessageShowScope* message);
|
||||||
|
|
||||||
CodeView* getView();
|
CodeView* getView() const;
|
||||||
|
|
||||||
virtual void clear();
|
virtual void clear();
|
||||||
|
|
||||||
void showContents(MessageBase* message);
|
void expandVisibleSnippets(std::vector<CodeSnippetParams>* snippets) const;
|
||||||
|
|
||||||
|
std::vector<CodeSnippetParams> getSnippetsForFileWithState(
|
||||||
|
const FilePath& filePath, CodeView::FileState state, bool addSourceLocations) const;
|
||||||
|
|
||||||
std::vector<CodeSnippetParams> getSnippetsForActiveSourceLocations(
|
std::vector<CodeSnippetParams> getSnippetsForActiveSourceLocations(
|
||||||
const SourceLocationCollection* collection, Id declarationId) const;
|
const SourceLocationCollection* collection, Id declarationId) const;
|
||||||
@@ -98,15 +98,10 @@ private:
|
|||||||
std::vector<std::string> getProjectDescription(SourceLocationFile* locationFile) const;
|
std::vector<std::string> getProjectDescription(SourceLocationFile* locationFile) const;
|
||||||
|
|
||||||
void addModificationTimes(std::vector<CodeSnippetParams>& snippets) const;
|
void addModificationTimes(std::vector<CodeSnippetParams>& snippets) const;
|
||||||
|
void addActiveSourceLocations(std::shared_ptr<SourceLocationFile> locationFile) const;
|
||||||
|
|
||||||
StorageAccess* m_storageAccess;
|
StorageAccess* m_storageAccess;
|
||||||
mutable std::shared_ptr<SourceLocationCollection> m_collection;
|
mutable std::shared_ptr<SourceLocationCollection> m_collection;
|
||||||
|
|
||||||
bool m_scrollToDefinition;
|
|
||||||
int m_scrollToValue;
|
|
||||||
bool m_scrollInListMode;
|
|
||||||
FilePath m_scrollToFilePath;
|
|
||||||
size_t m_scrollToLine;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // CODE_CONTROLLER_H
|
#endif // CODE_CONTROLLER_H
|
||||||
|
|||||||
@@ -369,7 +369,7 @@ void GraphController::handleMessage(MessageShowErrors* message)
|
|||||||
|
|
||||||
void GraphController::handleMessage(MessageShowReference* message)
|
void GraphController::handleMessage(MessageShowReference* message)
|
||||||
{
|
{
|
||||||
if (!message->tokenId || !message->animated)
|
if (!message->tokenId || !message->fromUser)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -152,7 +152,6 @@ void UndoRedoController::handleMessage(MessageFinishedParsing* message)
|
|||||||
msg->isFromSearch = false;
|
msg->isFromSearch = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
command.message->setIsReplayCleared(true);
|
|
||||||
newList.insert(newList.end(), command);
|
newList.insert(newList.end(), command);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -469,7 +468,6 @@ void UndoRedoController::replayCommand(std::list<Command>::iterator it)
|
|||||||
}
|
}
|
||||||
|
|
||||||
m->dispatch();
|
m->dispatch();
|
||||||
m->setIsReplayCleared(false);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void UndoRedoController::processCommand(Command command)
|
void UndoRedoController::processCommand(Command command)
|
||||||
|
|||||||
@@ -23,21 +23,60 @@ public:
|
|||||||
FILE_MAXIMIZED
|
FILE_MAXIMIZED
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct CodeParams
|
||||||
|
{
|
||||||
|
CodeParams()
|
||||||
|
: clearSnippets(false)
|
||||||
|
, showContents(false)
|
||||||
|
{}
|
||||||
|
|
||||||
|
bool clearSnippets;
|
||||||
|
bool showContents;
|
||||||
|
std::vector<Id> activeTokenIds;
|
||||||
|
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);
|
CodeView(ViewLayout* viewLayout);
|
||||||
virtual ~CodeView();
|
virtual ~CodeView();
|
||||||
|
|
||||||
virtual std::string getName() const;
|
virtual std::string getName() const;
|
||||||
|
|
||||||
virtual void clear() = 0;
|
virtual void clear() = 0;
|
||||||
virtual void clearCodeSnippets() = 0;
|
|
||||||
|
|
||||||
virtual void setErrorInfos(const std::vector<ErrorInfo>& errorInfos) = 0;
|
virtual void showCodeSnippets(const std::vector<CodeSnippetParams>& snippets, const CodeParams params) = 0;
|
||||||
|
virtual void scrollTo(const ScrollParams params) = 0;
|
||||||
|
|
||||||
virtual bool showsErrors() const = 0;
|
virtual bool showsErrors() const = 0;
|
||||||
|
|
||||||
virtual void showCodeSnippets(
|
|
||||||
const std::vector<CodeSnippetParams>& snippets, const std::vector<Id>& activeTokenIds, bool setupFiles) = 0;
|
|
||||||
virtual void addCodeSnippets(const std::vector<CodeSnippetParams>& snippets, bool insert) = 0;
|
|
||||||
|
|
||||||
virtual void setFileState(const FilePath filePath, FileState state) = 0;
|
virtual void setFileState(const FilePath filePath, FileState state) = 0;
|
||||||
|
|
||||||
virtual void showActiveSnippet(
|
virtual void showActiveSnippet(
|
||||||
@@ -50,11 +89,8 @@ public:
|
|||||||
|
|
||||||
virtual void showContents() = 0;
|
virtual void showContents() = 0;
|
||||||
|
|
||||||
virtual void scrollToValue(int value, bool inListMode) = 0;
|
|
||||||
virtual void scrollToLine(const FilePath filePath, unsigned int line) = 0;
|
|
||||||
virtual void scrollToDefinition(bool ignoreActiveReference) = 0;
|
|
||||||
|
|
||||||
virtual bool isInListMode() const = 0;
|
virtual bool isInListMode() const = 0;
|
||||||
|
virtual bool hasSingleFileCached(const FilePath& filePath) const = 0;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
CodeController* getController();
|
CodeController* getController();
|
||||||
|
|||||||
@@ -7,11 +7,11 @@ CodeSnippetParams::CodeSnippetParams()
|
|||||||
, endLineNumber(0)
|
, endLineNumber(0)
|
||||||
, titleId(0)
|
, titleId(0)
|
||||||
, footerId(0)
|
, footerId(0)
|
||||||
, locationFile()
|
|
||||||
, refCount(0)
|
, refCount(0)
|
||||||
, isCollapsed(false)
|
, isCollapsed(false)
|
||||||
, isDeclaration(false)
|
, isDeclaration(false)
|
||||||
, isDefinition(false)
|
, isDefinition(false)
|
||||||
|
, insertSnippet(false)
|
||||||
, reduced(false)
|
, reduced(false)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -36,6 +36,7 @@ struct CodeSnippetParams
|
|||||||
bool isDeclaration;
|
bool isDeclaration;
|
||||||
bool isDefinition;
|
bool isDefinition;
|
||||||
|
|
||||||
|
bool insertSnippet;
|
||||||
bool reduced;
|
bool reduced;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -10,7 +10,6 @@ public:
|
|||||||
MessageBase()
|
MessageBase()
|
||||||
: m_isParallel(false)
|
: m_isParallel(false)
|
||||||
, m_isReplayed(false)
|
, m_isReplayed(false)
|
||||||
, m_isReplayCleared(false)
|
|
||||||
, m_sendAsTask(true)
|
, m_sendAsTask(true)
|
||||||
, m_keepContent(false)
|
, m_keepContent(false)
|
||||||
, m_isLast(true)
|
, m_isLast(true)
|
||||||
@@ -55,16 +54,6 @@ public:
|
|||||||
m_isReplayed = isReplayed;
|
m_isReplayed = isReplayed;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool isReplayCleared() const
|
|
||||||
{
|
|
||||||
return m_isReplayCleared;
|
|
||||||
}
|
|
||||||
|
|
||||||
void setIsReplayCleared(bool isReplayCleared)
|
|
||||||
{
|
|
||||||
m_isReplayCleared = isReplayCleared;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool isLast() const
|
bool isLast() const
|
||||||
{
|
{
|
||||||
return m_isLast;
|
return m_isLast;
|
||||||
@@ -107,9 +96,7 @@ public:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
bool m_isParallel;
|
bool m_isParallel;
|
||||||
|
|
||||||
bool m_isReplayed;
|
bool m_isReplayed;
|
||||||
bool m_isReplayCleared;
|
|
||||||
|
|
||||||
bool m_sendAsTask;
|
bool m_sendAsTask;
|
||||||
bool m_keepContent;
|
bool m_keepContent;
|
||||||
|
|||||||
@@ -1,23 +0,0 @@
|
|||||||
#ifndef MESSAGE_CODE_VIEW_EXPANDED_INITIAL_FILES_H
|
|
||||||
#define MESSAGE_CODE_VIEW_EXPANDED_INITIAL_FILES_H
|
|
||||||
|
|
||||||
#include "utility/messaging/Message.h"
|
|
||||||
|
|
||||||
class MessageCodeViewExpandedInitialFiles
|
|
||||||
: public Message<MessageCodeViewExpandedInitialFiles>
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
MessageCodeViewExpandedInitialFiles(bool scrollToDefinition)
|
|
||||||
: scrollToDefinition(scrollToDefinition)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
static const std::string getStaticType()
|
|
||||||
{
|
|
||||||
return "MessageCodeViewExpandedInitialFiles";
|
|
||||||
}
|
|
||||||
|
|
||||||
bool scrollToDefinition;
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif // MESSAGE_CODE_VIEW_EXPANDED_INITIAL_FILES_H
|
|
||||||
@@ -1,17 +1,16 @@
|
|||||||
#ifndef MESSAGE_SCROLL_TO_LINE_h
|
#ifndef MESSAGE_SCROLL_TO_LINE_H
|
||||||
#define MESSAGE_SCROLL_TO_LINE_h
|
#define MESSAGE_SCROLL_TO_LINE_H
|
||||||
|
|
||||||
#include "utility/messaging/Message.h"
|
|
||||||
#include "utility/file/FilePath.h"
|
#include "utility/file/FilePath.h"
|
||||||
|
#include "utility/messaging/Message.h"
|
||||||
|
|
||||||
class MessageScrollToLine
|
class MessageScrollToLine
|
||||||
: public Message<MessageScrollToLine>
|
: public Message<MessageScrollToLine>
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
MessageScrollToLine(const FilePath& filePath, unsigned int line, bool isModified = false)
|
MessageScrollToLine(const FilePath& filePath, size_t line)
|
||||||
: filePath(filePath)
|
: filePath(filePath)
|
||||||
, line(line)
|
, line(line)
|
||||||
, isModified(isModified)
|
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -21,8 +20,7 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
const FilePath filePath;
|
const FilePath filePath;
|
||||||
unsigned int line;
|
size_t line;
|
||||||
bool isModified;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // MESSAGE_SCROLL_TO_LINE_h
|
#endif // MESSAGE_SCROLL_TO_LINE_H
|
||||||
|
|||||||
@@ -8,11 +8,11 @@ class MessageShowReference
|
|||||||
: public Message<MessageShowReference>
|
: public Message<MessageShowReference>
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
MessageShowReference(size_t refIndex, Id tokenId, Id locationId, bool animated)
|
MessageShowReference(size_t refIndex, Id tokenId, Id locationId, bool fromUser)
|
||||||
: refIndex(refIndex)
|
: refIndex(refIndex)
|
||||||
, tokenId(tokenId)
|
, tokenId(tokenId)
|
||||||
, locationId(locationId)
|
, locationId(locationId)
|
||||||
, animated(animated)
|
, fromUser(fromUser)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -29,7 +29,7 @@ public:
|
|||||||
const size_t refIndex;
|
const size_t refIndex;
|
||||||
const Id tokenId;
|
const Id tokenId;
|
||||||
const Id locationId;
|
const Id locationId;
|
||||||
const bool animated;
|
const bool fromUser;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // MESSAGE_SHOW_REFERENCE_H
|
#endif // MESSAGE_SHOW_REFERENCE_H
|
||||||
|
|||||||
@@ -153,7 +153,6 @@ QtCodeArea::QtCodeArea(
|
|||||||
m_highlighter->highlightDocument();
|
m_highlighter->highlightDocument();
|
||||||
|
|
||||||
createAnnotations(locationFile);
|
createAnnotations(locationFile);
|
||||||
annotateText();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QtCodeArea::~QtCodeArea()
|
QtCodeArea::~QtCodeArea()
|
||||||
@@ -294,39 +293,38 @@ uint QtCodeArea::getLineNumberForLocationId(Id locationId) const
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint QtCodeArea::getStartLineNumberOfFirstActiveLocationOfTokenId(Id tokenId) const
|
std::pair<uint, uint> QtCodeArea::getLineNumbersForLocationId(Id locationId) const
|
||||||
{
|
{
|
||||||
int firstActiveLine = 0;
|
|
||||||
for (const Annotation& annotation : m_annotations)
|
for (const Annotation& annotation : m_annotations)
|
||||||
{
|
{
|
||||||
if (annotation.locationType == LocationType::LOCATION_TOKEN && annotation.isActive)
|
if (annotation.locationId == locationId)
|
||||||
{
|
{
|
||||||
if (annotation.tokenIds.find(tokenId) != annotation.tokenIds.end())
|
return std::pair<uint, uint>(annotation.startLine, annotation.endLine);
|
||||||
{
|
}
|
||||||
if (!firstActiveLine || firstActiveLine == annotation.startLine)
|
}
|
||||||
{
|
|
||||||
return getStartLineNumber();
|
return std::pair<uint, uint>(0, 0);
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
Id QtCodeArea::getLocationIdOfFirstActiveLocation(Id tokenId) const
|
||||||
return annotation.startLine;
|
{
|
||||||
}
|
for (const Annotation& annotation : m_annotations)
|
||||||
}
|
{
|
||||||
else
|
if (annotation.locationType == LocationType::LOCATION_TOKEN && annotation.isActive &&
|
||||||
{
|
annotation.tokenIds.find(tokenId) != annotation.tokenIds.end())
|
||||||
firstActiveLine = annotation.startLine;
|
{
|
||||||
}
|
return annotation.locationId;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
Id QtCodeArea::getLocationIdOfFirstActiveLocationOfTokenId(Id tokenId) const
|
Id QtCodeArea::getLocationIdOfFirstActiveScopeLocation(Id tokenId) const
|
||||||
{
|
{
|
||||||
for (const Annotation& annotation : m_annotations)
|
for (const Annotation& annotation : m_annotations)
|
||||||
{
|
{
|
||||||
if (annotation.locationType == LocationType::LOCATION_TOKEN && annotation.isActive &&
|
if (annotation.locationType == LocationType::LOCATION_SCOPE && annotation.isActive &&
|
||||||
annotation.tokenIds.find(tokenId) != annotation.tokenIds.end())
|
annotation.tokenIds.find(tokenId) != annotation.tokenIds.end())
|
||||||
{
|
{
|
||||||
return annotation.locationId;
|
return annotation.locationId;
|
||||||
|
|||||||
@@ -85,8 +85,11 @@ public:
|
|||||||
void setIsActiveFile(bool isActiveFile);
|
void setIsActiveFile(bool isActiveFile);
|
||||||
|
|
||||||
uint getLineNumberForLocationId(Id locationId) const;
|
uint getLineNumberForLocationId(Id locationId) const;
|
||||||
uint getStartLineNumberOfFirstActiveLocationOfTokenId(Id tokenId) const;
|
std::pair<uint, uint> getLineNumbersForLocationId(Id locationId) const;
|
||||||
Id getLocationIdOfFirstActiveLocationOfTokenId(Id tokenId) const;
|
|
||||||
|
Id getLocationIdOfFirstActiveLocation(Id tokenId) const;
|
||||||
|
Id getLocationIdOfFirstActiveScopeLocation(Id tokenId) const;
|
||||||
|
|
||||||
uint getActiveLocationCount() const;
|
uint getActiveLocationCount() const;
|
||||||
|
|
||||||
QRectF getLineRectForLineNumber(uint lineNumber) const;
|
QRectF getLineRectForLineNumber(uint lineNumber) const;
|
||||||
|
|||||||
@@ -226,17 +226,17 @@ QtCodeSnippet* QtCodeFile::getFileSnippet() const
|
|||||||
return m_fileSnippet.get();
|
return m_fileSnippet.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
std::pair<QtCodeSnippet*, uint> QtCodeFile::getFirstSnippetWithActiveLocation(Id tokenId) const
|
std::pair<QtCodeSnippet*, Id> QtCodeFile::getFirstSnippetWithActiveLocationId(Id tokenId) const
|
||||||
{
|
{
|
||||||
std::pair<QtCodeSnippet*, uint> result(nullptr, 0);
|
std::pair<QtCodeSnippet*, Id> result(nullptr, 0);
|
||||||
|
|
||||||
for (std::shared_ptr<QtCodeSnippet> snippet : m_snippets)
|
for (std::shared_ptr<QtCodeSnippet> snippet : m_snippets)
|
||||||
{
|
{
|
||||||
uint startLineNumber = snippet->getStartLineNumberOfFirstActiveLocationOfTokenId(tokenId);
|
Id locationId = snippet->getFirstActiveLocationId(tokenId);
|
||||||
if (startLineNumber != 0)
|
if (locationId != 0)
|
||||||
{
|
{
|
||||||
result.first = snippet.get();
|
result.first = snippet.get();
|
||||||
result.second = startLineNumber;
|
result.second = locationId;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -249,7 +249,7 @@ bool QtCodeFile::isCollapsed() const
|
|||||||
return m_isCollapsed;
|
return m_isCollapsed;
|
||||||
}
|
}
|
||||||
|
|
||||||
void QtCodeFile::requestContent(bool isFirstInList)
|
void QtCodeFile::requestContent()
|
||||||
{
|
{
|
||||||
if (!isCollapsed() || m_contentRequested)
|
if (!isCollapsed() || m_contentRequested)
|
||||||
{
|
{
|
||||||
@@ -260,12 +260,7 @@ void QtCodeFile::requestContent(bool isFirstInList)
|
|||||||
m_contentRequested = true;
|
m_contentRequested = true;
|
||||||
|
|
||||||
MessageChangeFileView::FileState state =
|
MessageChangeFileView::FileState state =
|
||||||
isFirstInList ? MessageChangeFileView::FILE_DEFAULT_FOR_MODE : MessageChangeFileView::FILE_SNIPPETS;
|
m_isWholeFile ? MessageChangeFileView::FILE_MAXIMIZED : MessageChangeFileView::FILE_SNIPPETS;
|
||||||
|
|
||||||
if (m_isWholeFile)
|
|
||||||
{
|
|
||||||
state = MessageChangeFileView::FILE_MAXIMIZED;
|
|
||||||
}
|
|
||||||
|
|
||||||
MessageChangeFileView(m_filePath, state, isCollapsed(), m_navigator->hasErrors()).dispatch();
|
MessageChangeFileView(m_filePath, state, isCollapsed(), m_navigator->hasErrors()).dispatch();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -39,11 +39,11 @@ public:
|
|||||||
QtCodeSnippet* getSnippetForLine(unsigned int line) const;
|
QtCodeSnippet* getSnippetForLine(unsigned int line) const;
|
||||||
QtCodeSnippet* getFileSnippet() const;
|
QtCodeSnippet* getFileSnippet() const;
|
||||||
|
|
||||||
std::pair<QtCodeSnippet*, uint> getFirstSnippetWithActiveLocation(Id tokenId) const;
|
std::pair<QtCodeSnippet*, Id> getFirstSnippetWithActiveLocationId(Id tokenId) const;
|
||||||
|
|
||||||
bool isCollapsed() const;
|
bool isCollapsed() const;
|
||||||
|
|
||||||
void requestContent(bool isFirstInList = false);
|
void requestContent();
|
||||||
void updateContent();
|
void updateContent();
|
||||||
|
|
||||||
void setWholeFile(bool isWholeFile, int refCount);
|
void setWholeFile(bool isWholeFile, int refCount);
|
||||||
|
|||||||
@@ -83,14 +83,12 @@ QScrollArea* QtCodeFileList::getScrollArea()
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
void QtCodeFileList::addCodeSnippet(
|
void QtCodeFileList::addCodeSnippet(const CodeSnippetParams& params)
|
||||||
const CodeSnippetParams& params,
|
{
|
||||||
bool insert
|
|
||||||
){
|
|
||||||
QtCodeFile* file = getFile(params.locationFile->getFilePath());
|
QtCodeFile* file = getFile(params.locationFile->getFilePath());
|
||||||
QtCodeSnippet* snippet = nullptr;
|
QtCodeSnippet* snippet = nullptr;
|
||||||
|
|
||||||
if (insert)
|
if (params.insertSnippet)
|
||||||
{
|
{
|
||||||
snippet = file->insertCodeSnippet(params);
|
snippet = file->insertCodeSnippet(params);
|
||||||
}
|
}
|
||||||
@@ -103,9 +101,9 @@ void QtCodeFileList::addCodeSnippet(
|
|||||||
file->setIsComplete(params.locationFile->isComplete());
|
file->setIsComplete(params.locationFile->isComplete());
|
||||||
}
|
}
|
||||||
|
|
||||||
void QtCodeFileList::requestFileContent(const FilePath& filePath, bool isFirstInList)
|
void QtCodeFileList::requestFileContent(const FilePath& filePath)
|
||||||
{
|
{
|
||||||
getFile(filePath)->requestContent(isFirstInList);
|
getFile(filePath)->requestContent();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool QtCodeFileList::requestScroll(const FilePath& filePath, uint lineNumber, Id locationId, bool animated, bool onTop)
|
bool QtCodeFileList::requestScroll(const FilePath& filePath, uint lineNumber, Id locationId, bool animated, bool onTop)
|
||||||
@@ -147,11 +145,19 @@ bool QtCodeFileList::requestScroll(const FilePath& filePath, uint lineNumber, Id
|
|||||||
file->setSnippets();
|
file->setSnippets();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
uint endLineNumber = 0;
|
||||||
if (!lineNumber)
|
if (!lineNumber)
|
||||||
{
|
{
|
||||||
if (locationId)
|
if (locationId)
|
||||||
{
|
{
|
||||||
lineNumber = snippet->getLineNumberForLocationId(locationId);
|
std::pair<uint, uint> lineNumbers = snippet->getLineNumbersForLocationId(locationId);
|
||||||
|
|
||||||
|
lineNumber = lineNumbers.first;
|
||||||
|
|
||||||
|
if (lineNumbers.first != lineNumbers.second)
|
||||||
|
{
|
||||||
|
endLineNumber = lineNumbers.second;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -159,7 +165,13 @@ bool QtCodeFileList::requestScroll(const FilePath& filePath, uint lineNumber, Id
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ensureWidgetVisibleAnimated(m_filesArea, snippet, snippet->getLineRectForLineNumber(lineNumber), animated, onTop);
|
QRectF lineRect = snippet->getLineRectForLineNumber(lineNumber);
|
||||||
|
if (endLineNumber)
|
||||||
|
{
|
||||||
|
lineRect |= snippet->getLineRectForLineNumber(endLineNumber);
|
||||||
|
}
|
||||||
|
|
||||||
|
ensureWidgetVisibleAnimated(m_filesArea, snippet, lineRect, animated, onTop);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -203,9 +215,9 @@ void QtCodeFileList::setFileMaximized(const FilePath path)
|
|||||||
getFile(path)->setMaximized();
|
getFile(path)->setMaximized();
|
||||||
}
|
}
|
||||||
|
|
||||||
std::pair<QtCodeSnippet*, uint> QtCodeFileList::getFirstSnippetWithActiveLocation(Id tokenId) const
|
std::pair<QtCodeSnippet*, Id> QtCodeFileList::getFirstSnippetWithActiveLocationId(Id tokenId) const
|
||||||
{
|
{
|
||||||
std::pair<QtCodeSnippet*, uint> result(nullptr, 0);
|
std::pair<QtCodeSnippet*, Id> result(nullptr, 0);
|
||||||
|
|
||||||
for (std::shared_ptr<QtCodeFile> filePtr : m_files)
|
for (std::shared_ptr<QtCodeFile> filePtr : m_files)
|
||||||
{
|
{
|
||||||
@@ -214,7 +226,7 @@ std::pair<QtCodeSnippet*, uint> QtCodeFileList::getFirstSnippetWithActiveLocatio
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
result = filePtr->getFirstSnippetWithActiveLocation(tokenId);
|
result = filePtr->getFirstSnippetWithActiveLocationId(tokenId);
|
||||||
if (result.first != nullptr)
|
if (result.first != nullptr)
|
||||||
{
|
{
|
||||||
break;
|
break;
|
||||||
|
|||||||
@@ -33,9 +33,9 @@ public:
|
|||||||
// QtCodeNaviatebale implementation
|
// QtCodeNaviatebale implementation
|
||||||
virtual QScrollArea* getScrollArea();
|
virtual QScrollArea* getScrollArea();
|
||||||
|
|
||||||
virtual void addCodeSnippet(const CodeSnippetParams& params, bool insert = false);
|
virtual void addCodeSnippet(const CodeSnippetParams& params);
|
||||||
|
|
||||||
void requestFileContent(const FilePath& filePath, bool isFirstInList = false);
|
virtual void requestFileContent(const FilePath& filePath);
|
||||||
virtual bool requestScroll(const FilePath& filePath, uint lineNumber, Id locationId, bool animated, bool onTop);
|
virtual bool requestScroll(const FilePath& filePath, uint lineNumber, Id locationId, bool animated, bool onTop);
|
||||||
|
|
||||||
virtual void updateFiles();
|
virtual void updateFiles();
|
||||||
@@ -47,7 +47,7 @@ public:
|
|||||||
void setFileSnippets(const FilePath path);
|
void setFileSnippets(const FilePath path);
|
||||||
void setFileMaximized(const FilePath path);
|
void setFileMaximized(const FilePath path);
|
||||||
|
|
||||||
std::pair<QtCodeSnippet*, uint> getFirstSnippetWithActiveLocation(Id tokenId) const;
|
std::pair<QtCodeSnippet*, Id> getFirstSnippetWithActiveLocationId(Id tokenId) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QtCodeNavigator* m_navigator;
|
QtCodeNavigator* m_navigator;
|
||||||
|
|||||||
@@ -20,6 +20,7 @@ QtCodeFileSingle::QtCodeFileSingle(QtCodeNavigator* navigator, QWidget* parent)
|
|||||||
: m_navigator(navigator)
|
: m_navigator(navigator)
|
||||||
, m_area(nullptr)
|
, m_area(nullptr)
|
||||||
, m_contentRequested(false)
|
, m_contentRequested(false)
|
||||||
|
, m_scrollRequested(false)
|
||||||
{
|
{
|
||||||
setObjectName("code_container");
|
setObjectName("code_container");
|
||||||
|
|
||||||
@@ -83,7 +84,7 @@ void QtCodeFileSingle::clearCache()
|
|||||||
m_filePaths.clear();
|
m_filePaths.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
void QtCodeFileSingle::addCodeSnippet(const CodeSnippetParams& params, bool insert)
|
void QtCodeFileSingle::addCodeSnippet(const CodeSnippetParams& params)
|
||||||
{
|
{
|
||||||
if (!params.locationFile->isWhole())
|
if (!params.locationFile->isWhole())
|
||||||
{
|
{
|
||||||
@@ -163,11 +164,24 @@ bool QtCodeFileSingle::requestScroll(const FilePath& filePath, uint lineNumber,
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!m_scrollRequested)
|
||||||
|
{
|
||||||
|
animated = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint endLineNumber = 0;
|
||||||
if (!lineNumber)
|
if (!lineNumber)
|
||||||
{
|
{
|
||||||
if (locationId)
|
if (locationId)
|
||||||
{
|
{
|
||||||
lineNumber = m_area->getLineNumberForLocationId(locationId);
|
std::pair<uint, uint> lineNumbers = m_area->getLineNumbersForLocationId(locationId);
|
||||||
|
|
||||||
|
lineNumber = lineNumbers.first;
|
||||||
|
|
||||||
|
if (lineNumbers.first != lineNumbers.second)
|
||||||
|
{
|
||||||
|
endLineNumber = lineNumbers.second;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -175,7 +189,12 @@ bool QtCodeFileSingle::requestScroll(const FilePath& filePath, uint lineNumber,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ensurePercentVisibleAnimated(double(lineNumber - 1) / m_area->getEndLineNumber(), animated, onTop);
|
double percentA = double(lineNumber - 1) / m_area->getEndLineNumber();
|
||||||
|
double percentB = endLineNumber ? double(endLineNumber - 1) / m_area->getEndLineNumber() : 0.0f;
|
||||||
|
|
||||||
|
ensurePercentVisibleAnimated(percentA, percentB, animated, onTop);
|
||||||
|
|
||||||
|
m_scrollRequested = true;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -206,6 +225,11 @@ const FilePath& QtCodeFileSingle::getCurrentFilePath() const
|
|||||||
return m_currentFilePath;
|
return m_currentFilePath;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool QtCodeFileSingle::hasFileCached(const FilePath& filePath) const
|
||||||
|
{
|
||||||
|
return getFileData(filePath).area != nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
Id QtCodeFileSingle::getLocationIdOfFirstActiveLocationOfTokenId(Id tokenId) const
|
Id QtCodeFileSingle::getLocationIdOfFirstActiveLocationOfTokenId(Id tokenId) const
|
||||||
{
|
{
|
||||||
if (!m_area)
|
if (!m_area)
|
||||||
@@ -213,7 +237,13 @@ Id QtCodeFileSingle::getLocationIdOfFirstActiveLocationOfTokenId(Id tokenId) con
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
return m_area->getLocationIdOfFirstActiveLocationOfTokenId(tokenId);
|
Id scopeId = m_area->getLocationIdOfFirstActiveScopeLocation(tokenId);
|
||||||
|
if (scopeId)
|
||||||
|
{
|
||||||
|
return scopeId;
|
||||||
|
}
|
||||||
|
|
||||||
|
return m_area->getLocationIdOfFirstActiveLocation(tokenId);
|
||||||
}
|
}
|
||||||
|
|
||||||
QtCodeFileSingle::FileData QtCodeFileSingle::getFileData(const FilePath& filePath) const
|
QtCodeFileSingle::FileData QtCodeFileSingle::getFileData(const FilePath& filePath) const
|
||||||
@@ -273,6 +303,8 @@ void QtCodeFileSingle::setFileData(const FileData& file)
|
|||||||
|
|
||||||
m_title->show();
|
m_title->show();
|
||||||
m_area->show();
|
m_area->show();
|
||||||
|
|
||||||
|
m_scrollRequested = false;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -32,9 +32,9 @@ public:
|
|||||||
// QtCodeNaviatebale implementation
|
// QtCodeNaviatebale implementation
|
||||||
virtual QAbstractScrollArea* getScrollArea() override;
|
virtual QAbstractScrollArea* getScrollArea() override;
|
||||||
|
|
||||||
virtual void addCodeSnippet(const CodeSnippetParams& params, bool insert = false) override;
|
virtual void addCodeSnippet(const CodeSnippetParams& params) override;
|
||||||
|
|
||||||
void requestFileContent(const FilePath& filePath);
|
virtual void requestFileContent(const FilePath& filePath) override;
|
||||||
virtual bool requestScroll(const FilePath& filePath, uint lineNumber, Id locationId, bool animated, bool onTop) override;
|
virtual bool requestScroll(const FilePath& filePath, uint lineNumber, Id locationId, bool animated, bool onTop) override;
|
||||||
|
|
||||||
virtual void updateFiles() override;
|
virtual void updateFiles() override;
|
||||||
@@ -43,6 +43,7 @@ public:
|
|||||||
virtual void onWindowFocus() override;
|
virtual void onWindowFocus() override;
|
||||||
|
|
||||||
const FilePath& getCurrentFilePath() const;
|
const FilePath& getCurrentFilePath() const;
|
||||||
|
bool hasFileCached(const FilePath& filePath) const;
|
||||||
|
|
||||||
Id getLocationIdOfFirstActiveLocationOfTokenId(Id tokenId) const;
|
Id getLocationIdOfFirstActiveLocationOfTokenId(Id tokenId) const;
|
||||||
|
|
||||||
@@ -75,6 +76,7 @@ private:
|
|||||||
std::deque<FilePath> m_filePaths;
|
std::deque<FilePath> m_filePaths;
|
||||||
|
|
||||||
bool m_contentRequested;
|
bool m_contentRequested;
|
||||||
|
bool m_scrollRequested;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // QT_CODE_FILE_SINGLE_H
|
#endif // QT_CODE_FILE_SINGLE_H
|
||||||
|
|||||||
@@ -58,7 +58,7 @@ void QtCodeNavigateable::ensureWidgetVisibleAnimated(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void QtCodeNavigateable::ensurePercentVisibleAnimated(double percent, bool animated, bool onTop)
|
void QtCodeNavigateable::ensurePercentVisibleAnimated(double percentA, double percentB, bool animated, bool onTop)
|
||||||
{
|
{
|
||||||
QAbstractScrollArea* area = getScrollArea();
|
QAbstractScrollArea* area = getScrollArea();
|
||||||
if (!area)
|
if (!area)
|
||||||
@@ -74,10 +74,34 @@ void QtCodeNavigateable::ensurePercentVisibleAnimated(double percent, bool anima
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
int scrollHeight = totalHeight * percent;
|
int scrollHeight = totalHeight * percentA;
|
||||||
if (!onTop)
|
if (!onTop)
|
||||||
{
|
{
|
||||||
scrollHeight -= visibleHeight / 3;
|
if (percentB)
|
||||||
|
{
|
||||||
|
int scrollHeightB = totalHeight * percentB;
|
||||||
|
int rectHeight = scrollHeightB - scrollHeight;
|
||||||
|
|
||||||
|
if (rectHeight < visibleHeight)
|
||||||
|
{
|
||||||
|
if (rectHeight < visibleHeight / 2)
|
||||||
|
{
|
||||||
|
scrollHeight -= visibleHeight / 4;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
scrollHeight += rectHeight / 2 - visibleHeight / 2;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
scrollHeight -= 20;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
scrollHeight -= visibleHeight / 4;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -19,8 +19,9 @@ public:
|
|||||||
|
|
||||||
virtual QAbstractScrollArea* getScrollArea() = 0;
|
virtual QAbstractScrollArea* getScrollArea() = 0;
|
||||||
|
|
||||||
virtual void addCodeSnippet(const CodeSnippetParams& params, bool insert = false) = 0;
|
virtual void addCodeSnippet(const CodeSnippetParams& params) = 0;
|
||||||
|
|
||||||
|
virtual void requestFileContent(const FilePath& filePath) = 0;
|
||||||
virtual bool requestScroll(const FilePath& filePath, uint lineNumber, Id locationId, bool animated, bool onTop) = 0;
|
virtual bool requestScroll(const FilePath& filePath, uint lineNumber, Id locationId, bool animated, bool onTop) = 0;
|
||||||
|
|
||||||
virtual void updateFiles() = 0;
|
virtual void updateFiles() = 0;
|
||||||
@@ -30,7 +31,7 @@ public:
|
|||||||
|
|
||||||
protected:
|
protected:
|
||||||
void ensureWidgetVisibleAnimated(QWidget* parentWidget, QWidget *childWidget, QRectF rect, bool animated, bool onTop);
|
void ensureWidgetVisibleAnimated(QWidget* parentWidget, QWidget *childWidget, QRectF rect, bool animated, bool onTop);
|
||||||
void ensurePercentVisibleAnimated(double percent, bool animated, bool onTop);
|
void ensurePercentVisibleAnimated(double percentA, double percentB, bool animated, bool onTop);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // QT_CODE_NAVIGATEABLE_H
|
#endif // QT_CODE_NAVIGATEABLE_H
|
||||||
|
|||||||
@@ -8,7 +8,6 @@
|
|||||||
#include <QVBoxLayout>
|
#include <QVBoxLayout>
|
||||||
|
|
||||||
#include "utility/logging/logging.h"
|
#include "utility/logging/logging.h"
|
||||||
#include "utility/messaging/type/MessageCodeViewExpandedInitialFiles.h"
|
|
||||||
#include "utility/messaging/type/MessageScrollCode.h"
|
#include "utility/messaging/type/MessageScrollCode.h"
|
||||||
#include "utility/messaging/type/MessageShowErrors.h"
|
#include "utility/messaging/type/MessageShowErrors.h"
|
||||||
#include "utility/ResourcePaths.h"
|
#include "utility/ResourcePaths.h"
|
||||||
@@ -137,21 +136,30 @@ QtCodeNavigator::~QtCodeNavigator()
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
void QtCodeNavigator::addCodeSnippet(const CodeSnippetParams& params, bool insert)
|
void QtCodeNavigator::addCodeSnippet(const CodeSnippetParams& params)
|
||||||
{
|
{
|
||||||
|
FilePath currentPath = m_single->getCurrentFilePath();
|
||||||
|
|
||||||
if (params.reduced)
|
if (params.reduced)
|
||||||
{
|
{
|
||||||
m_list->addCodeSnippet(params, insert);
|
m_list->addCodeSnippet(params);
|
||||||
m_single->addCodeSnippet(params, insert);
|
m_single->addCodeSnippet(params);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
m_current->addCodeSnippet(params, insert);
|
m_current->addCodeSnippet(params);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (currentPath != m_single->getCurrentFilePath())
|
||||||
|
{
|
||||||
|
m_singleHasNewFile = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void QtCodeNavigator::addFile(std::shared_ptr<SourceLocationFile> locationFile, int refCount, TimePoint modificationTime)
|
void QtCodeNavigator::addFile(std::shared_ptr<SourceLocationFile> locationFile, int refCount, TimePoint modificationTime)
|
||||||
{
|
{
|
||||||
|
bool firstFile = m_references.size() == 0;
|
||||||
|
|
||||||
m_list->addFile(locationFile->getFilePath(), locationFile->isWhole(), refCount, modificationTime, locationFile->isComplete());
|
m_list->addFile(locationFile->getFilePath(), locationFile->isWhole(), refCount, modificationTime, locationFile->isComplete());
|
||||||
|
|
||||||
if (locationFile->isWhole())
|
if (locationFile->isWhole())
|
||||||
@@ -195,13 +203,26 @@ void QtCodeNavigator::addFile(std::shared_ptr<SourceLocationFile> locationFile,
|
|||||||
}
|
}
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (firstFile && m_references.size() && m_references[0].locationType != LOCATION_TOKEN)
|
||||||
|
{
|
||||||
|
clearCaches();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void QtCodeNavigator::addedFiles()
|
void QtCodeNavigator::addedFiles()
|
||||||
{
|
{
|
||||||
if (m_references.size() && m_references[0].locationType != LOCATION_TOKEN)
|
if (m_mode == MODE_SINGLE && m_references.size())
|
||||||
{
|
{
|
||||||
clearCaches();
|
if (!m_refIndex || !m_activeReference.tokenId)
|
||||||
|
{
|
||||||
|
m_single->requestFileContent(m_references.front().filePath);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (m_refIndex == 0)
|
||||||
|
{
|
||||||
|
updateRefLabel();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -343,6 +364,11 @@ bool QtCodeNavigator::isInListMode() const
|
|||||||
return m_mode == MODE_LIST;
|
return m_mode == MODE_LIST;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool QtCodeNavigator::hasSingleFileCached(const FilePath& filePath) const
|
||||||
|
{
|
||||||
|
return m_single->hasFileCached(filePath);
|
||||||
|
}
|
||||||
|
|
||||||
void QtCodeNavigator::showActiveSnippet(
|
void QtCodeNavigator::showActiveSnippet(
|
||||||
const std::vector<Id>& activeTokenIds, std::shared_ptr<SourceLocationCollection> collection, bool scrollTo)
|
const std::vector<Id>& activeTokenIds, std::shared_ptr<SourceLocationCollection> collection, bool scrollTo)
|
||||||
{
|
{
|
||||||
@@ -425,8 +451,11 @@ void QtCodeNavigator::showActiveSnippet(
|
|||||||
|
|
||||||
if (firstReference.tokenId)
|
if (firstReference.tokenId)
|
||||||
{
|
{
|
||||||
requestScroll(firstReference.filePath, 0, firstReference.locationId, true, false);
|
if (scrollTo)
|
||||||
emit scrollRequest();
|
{
|
||||||
|
requestScroll(firstReference.filePath, 0, firstReference.locationId, true, false);
|
||||||
|
emit scrollRequest();
|
||||||
|
}
|
||||||
|
|
||||||
m_refIndex = refIndex;
|
m_refIndex = refIndex;
|
||||||
updateRefLabel();
|
updateRefLabel();
|
||||||
@@ -465,46 +494,6 @@ void QtCodeNavigator::setFileMaximized(const FilePath path)
|
|||||||
m_list->setFileMaximized(path);
|
m_list->setFileMaximized(path);
|
||||||
}
|
}
|
||||||
|
|
||||||
void QtCodeNavigator::setupFiles()
|
|
||||||
{
|
|
||||||
if (m_mode == MODE_LIST)
|
|
||||||
{
|
|
||||||
std::set<FilePath> filePathsToExpand;
|
|
||||||
for (const Reference& ref : m_references)
|
|
||||||
{
|
|
||||||
if (filePathsToExpand.find(ref.filePath) == filePathsToExpand.end())
|
|
||||||
{
|
|
||||||
m_list->requestFileContent(ref.filePath, filePathsToExpand.size() == 0);
|
|
||||||
filePathsToExpand.insert(ref.filePath);
|
|
||||||
|
|
||||||
if (filePathsToExpand.size() >= 3)
|
|
||||||
{
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (filePathsToExpand.size())
|
|
||||||
{
|
|
||||||
MessageCodeViewExpandedInitialFiles(m_refIndex != 0 || m_activeReference.tokenId).dispatch();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (m_references.size())
|
|
||||||
{
|
|
||||||
m_singleHasNewFile = (m_single->getCurrentFilePath() != m_references.front().filePath);
|
|
||||||
if (!m_refIndex || !m_activeReference.tokenId)
|
|
||||||
{
|
|
||||||
m_single->requestFileContent(m_references.front().filePath);
|
|
||||||
}
|
|
||||||
MessageCodeViewExpandedInitialFiles(true).dispatch();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (m_refIndex == 0)
|
|
||||||
{
|
|
||||||
updateRefLabel();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void QtCodeNavigator::updateFiles()
|
void QtCodeNavigator::updateFiles()
|
||||||
{
|
{
|
||||||
m_current->updateFiles();
|
m_current->updateFiles();
|
||||||
@@ -555,7 +544,8 @@ void QtCodeNavigator::scrollToValue(int value, bool inListMode)
|
|||||||
if ((m_mode == MODE_LIST) == inListMode)
|
if ((m_mode == MODE_LIST) == inListMode)
|
||||||
{
|
{
|
||||||
m_value = value;
|
m_value = value;
|
||||||
QTimer::singleShot(1000, this, SLOT(setValue()));
|
QTimer::singleShot(100, this, SLOT(setValue()));
|
||||||
|
m_scrollRequest = ScrollRequest();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -565,7 +555,7 @@ void QtCodeNavigator::scrollToLine(const FilePath& filePath, unsigned int line)
|
|||||||
emit scrollRequest();
|
emit scrollRequest();
|
||||||
}
|
}
|
||||||
|
|
||||||
void QtCodeNavigator::scrollToDefinition(bool ignoreActiveReference)
|
void QtCodeNavigator::scrollToDefinition(bool animated, bool ignoreActiveReference)
|
||||||
{
|
{
|
||||||
if (ignoreActiveReference)
|
if (ignoreActiveReference)
|
||||||
{
|
{
|
||||||
@@ -594,25 +584,25 @@ void QtCodeNavigator::scrollToDefinition(bool ignoreActiveReference)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!m_activeTokenId && m_mode == MODE_SINGLE && m_references.size() && m_references.front().locationType != LOCATION_TOKEN)
|
|
||||||
{
|
|
||||||
requestScroll(m_references.front().filePath, 0, m_references.front().locationId, false, true);
|
|
||||||
emit scrollRequest();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!m_activeTokenId)
|
if (!m_activeTokenId)
|
||||||
{
|
{
|
||||||
|
if (m_mode == MODE_SINGLE && m_references.size() && m_references.front().locationType != LOCATION_TOKEN)
|
||||||
|
{
|
||||||
|
requestScroll(m_references.front().filePath, 0, m_references.front().locationId, false, false);
|
||||||
|
emit scrollRequest();
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (m_mode == MODE_LIST)
|
if (m_mode == MODE_LIST)
|
||||||
{
|
{
|
||||||
std::pair<QtCodeSnippet*, uint> result = m_list->getFirstSnippetWithActiveLocation(m_activeTokenId);
|
std::cout << animated << std::endl;
|
||||||
|
std::pair<QtCodeSnippet*, Id> result = m_list->getFirstSnippetWithActiveLocationId(m_activeTokenId);
|
||||||
if (result.first != nullptr)
|
if (result.first != nullptr)
|
||||||
{
|
{
|
||||||
requestScroll(result.first->getFile()->getFilePath(), result.second, 0, false, true);
|
requestScroll(result.first->getFile()->getFilePath(), 0, result.second, animated, false);
|
||||||
emit scrollRequest();
|
emit scrollRequest();
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -620,22 +610,18 @@ void QtCodeNavigator::scrollToDefinition(bool ignoreActiveReference)
|
|||||||
Id locationId = m_single->getLocationIdOfFirstActiveLocationOfTokenId(m_activeTokenId);
|
Id locationId = m_single->getLocationIdOfFirstActiveLocationOfTokenId(m_activeTokenId);
|
||||||
if (locationId)
|
if (locationId)
|
||||||
{
|
{
|
||||||
for (size_t i = 0; i < m_references.size(); i++)
|
requestScroll(m_single->getCurrentFilePath(), 0, locationId, true, false);
|
||||||
{
|
emit scrollRequest();
|
||||||
if (m_references[i].locationId == locationId)
|
return;
|
||||||
{
|
|
||||||
m_refIndex = i + 1;
|
|
||||||
showCurrentReference(false);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (m_references.size())
|
|
||||||
{
|
|
||||||
nextReference(false);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//m_singleHasNewFile = false;
|
if (m_references.size())
|
||||||
|
{
|
||||||
|
m_current->requestFileContent(m_references.front().filePath);
|
||||||
|
requestScroll(m_references.front().filePath, 0, m_references.front().locationId, false, false);
|
||||||
|
emit scrollRequest();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void QtCodeNavigator::scrollToSnippetIfRequested()
|
void QtCodeNavigator::scrollToSnippetIfRequested()
|
||||||
@@ -658,10 +644,6 @@ void QtCodeNavigator::requestScroll(const FilePath& filePath, uint lineNumber, I
|
|||||||
{
|
{
|
||||||
req.animated = false;
|
req.animated = false;
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
req.animated = (m_single->getCurrentFilePath() == filePath);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// std::cout << "scroll request: " << req.filePath.str() << " " << req.lineNumber << " " << req.locationId;
|
// std::cout << "scroll request: " << req.filePath.str() << " " << req.lineNumber << " " << req.locationId;
|
||||||
@@ -688,6 +670,10 @@ void QtCodeNavigator::handleScrollRequest()
|
|||||||
{
|
{
|
||||||
m_scrollRequest = ScrollRequest();
|
m_scrollRequest = ScrollRequest();
|
||||||
}
|
}
|
||||||
|
else if (m_mode == MODE_SINGLE)
|
||||||
|
{
|
||||||
|
m_scrollRequest.animated = false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void QtCodeNavigator::scrolled(int value)
|
void QtCodeNavigator::scrolled(int value)
|
||||||
@@ -789,7 +775,7 @@ void QtCodeNavigator::setMode(Mode mode)
|
|||||||
ApplicationSettings::getInstance()->setCodeViewModeSingle(m_mode == MODE_SINGLE);
|
ApplicationSettings::getInstance()->setCodeViewModeSingle(m_mode == MODE_SINGLE);
|
||||||
ApplicationSettings::getInstance()->save();
|
ApplicationSettings::getInstance()->save();
|
||||||
|
|
||||||
setupFiles();
|
scrollToDefinition(false, false);
|
||||||
showContents();
|
showContents();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -859,7 +845,7 @@ void QtCodeNavigator::handleMessage(MessageShowReference* message)
|
|||||||
setCurrentActiveLocationIds(std::vector<Id>(1, ref.locationId));
|
setCurrentActiveLocationIds(std::vector<Id>(1, ref.locationId));
|
||||||
updateFiles();
|
updateFiles();
|
||||||
|
|
||||||
requestScroll(ref.filePath, 0, ref.locationId, message->animated, false);
|
requestScroll(ref.filePath, 0, ref.locationId, true, false);
|
||||||
emit scrollRequest();
|
emit scrollRequest();
|
||||||
|
|
||||||
if (ref.locationType == LOCATION_ERROR)
|
if (ref.locationType == LOCATION_ERROR)
|
||||||
|
|||||||
@@ -34,7 +34,7 @@ public:
|
|||||||
QtCodeNavigator(QWidget* parent = nullptr);
|
QtCodeNavigator(QWidget* parent = nullptr);
|
||||||
virtual ~QtCodeNavigator();
|
virtual ~QtCodeNavigator();
|
||||||
|
|
||||||
void addCodeSnippet(const CodeSnippetParams& params, bool insert = false);
|
void addCodeSnippet(const CodeSnippetParams& params);
|
||||||
void addFile(std::shared_ptr<SourceLocationFile> locationFile, int refCount, TimePoint modificationTime);
|
void addFile(std::shared_ptr<SourceLocationFile> locationFile, int refCount, TimePoint modificationTime);
|
||||||
|
|
||||||
void addedFiles();
|
void addedFiles();
|
||||||
@@ -65,6 +65,7 @@ public:
|
|||||||
size_t getFatalErrorCountForFile(const FilePath& filePath) const;
|
size_t getFatalErrorCountForFile(const FilePath& filePath) const;
|
||||||
|
|
||||||
bool isInListMode() const;
|
bool isInListMode() const;
|
||||||
|
bool hasSingleFileCached(const FilePath& filePath) const;
|
||||||
|
|
||||||
void showActiveSnippet(
|
void showActiveSnippet(
|
||||||
const std::vector<Id>& activeTokenIds, std::shared_ptr<SourceLocationCollection> collection, bool scrollTo);
|
const std::vector<Id>& activeTokenIds, std::shared_ptr<SourceLocationCollection> collection, bool scrollTo);
|
||||||
@@ -76,7 +77,6 @@ public:
|
|||||||
void setFileSnippets(const FilePath path);
|
void setFileSnippets(const FilePath path);
|
||||||
void setFileMaximized(const FilePath path);
|
void setFileMaximized(const FilePath path);
|
||||||
|
|
||||||
void setupFiles();
|
|
||||||
void updateFiles();
|
void updateFiles();
|
||||||
void showContents();
|
void showContents();
|
||||||
|
|
||||||
@@ -84,7 +84,7 @@ public:
|
|||||||
|
|
||||||
void scrollToValue(int value, bool inListMode);
|
void scrollToValue(int value, bool inListMode);
|
||||||
void scrollToLine(const FilePath& filePath, unsigned int line);
|
void scrollToLine(const FilePath& filePath, unsigned int line);
|
||||||
void scrollToDefinition(bool ignoreActiveReference);
|
void scrollToDefinition(bool animated, bool ignoreActiveReference);
|
||||||
|
|
||||||
void scrollToSnippetIfRequested();
|
void scrollToSnippetIfRequested();
|
||||||
|
|
||||||
|
|||||||
@@ -164,9 +164,20 @@ uint QtCodeSnippet::getLineNumberForLocationId(Id locationId) const
|
|||||||
return m_codeArea->getLineNumberForLocationId(locationId);
|
return m_codeArea->getLineNumberForLocationId(locationId);
|
||||||
}
|
}
|
||||||
|
|
||||||
uint QtCodeSnippet::getStartLineNumberOfFirstActiveLocationOfTokenId(Id tokenId) const
|
std::pair<uint, uint> QtCodeSnippet::getLineNumbersForLocationId(Id locationId) const
|
||||||
{
|
{
|
||||||
return m_codeArea->getStartLineNumberOfFirstActiveLocationOfTokenId(tokenId);
|
return m_codeArea->getLineNumbersForLocationId(locationId);
|
||||||
|
}
|
||||||
|
|
||||||
|
Id QtCodeSnippet::getFirstActiveLocationId(Id tokenId) const
|
||||||
|
{
|
||||||
|
Id scopeId = m_codeArea->getLocationIdOfFirstActiveScopeLocation(tokenId);
|
||||||
|
if (scopeId)
|
||||||
|
{
|
||||||
|
return scopeId;
|
||||||
|
}
|
||||||
|
|
||||||
|
return m_codeArea->getLocationIdOfFirstActiveLocation(tokenId);
|
||||||
}
|
}
|
||||||
|
|
||||||
QRectF QtCodeSnippet::getLineRectForLineNumber(uint lineNumber) const
|
QRectF QtCodeSnippet::getLineRectForLineNumber(uint lineNumber) const
|
||||||
|
|||||||
@@ -44,7 +44,9 @@ public:
|
|||||||
void setIsActiveFile(bool isActiveFile);
|
void setIsActiveFile(bool isActiveFile);
|
||||||
|
|
||||||
uint getLineNumberForLocationId(Id locationId) const;
|
uint getLineNumberForLocationId(Id locationId) const;
|
||||||
uint getStartLineNumberOfFirstActiveLocationOfTokenId(Id tokenId) const;
|
std::pair<uint, uint> getLineNumbersForLocationId(Id locationId) const;
|
||||||
|
|
||||||
|
Id getFirstActiveLocationId(Id tokenId) const;
|
||||||
QRectF getLineRectForLineNumber(uint lineNumber) const;
|
QRectF getLineRectForLineNumber(uint lineNumber) const;
|
||||||
|
|
||||||
std::string getCode() const;
|
std::string getCode() const;
|
||||||
|
|||||||
+118
-165
@@ -1,25 +1,16 @@
|
|||||||
#include "qt/view/QtCodeView.h"
|
#include "qt/view/QtCodeView.h"
|
||||||
|
|
||||||
#include "utility/ResourcePaths.h"
|
#include "utility/ResourcePaths.h"
|
||||||
#include "qt/utility/utilityQt.h"
|
|
||||||
|
|
||||||
#include "qt/element/QtCodeArea.h"
|
#include "qt/element/QtCodeArea.h"
|
||||||
#include "qt/element/QtCodeNavigator.h"
|
#include "qt/element/QtCodeNavigator.h"
|
||||||
#include "qt/utility/QtHighlighter.h"
|
#include "qt/utility/QtHighlighter.h"
|
||||||
|
#include "qt/utility/utilityQt.h"
|
||||||
#include "qt/view/QtViewWidgetWrapper.h"
|
#include "qt/view/QtViewWidgetWrapper.h"
|
||||||
#include "settings/ColorScheme.h"
|
#include "settings/ColorScheme.h"
|
||||||
|
|
||||||
QtCodeView::QtCodeView(ViewLayout* viewLayout)
|
QtCodeView::QtCodeView(ViewLayout* viewLayout)
|
||||||
: CodeView(viewLayout)
|
: CodeView(viewLayout)
|
||||||
, m_showCodeSnippetsFunctor(
|
|
||||||
std::bind(&QtCodeView::doShowCodeSnippets, this, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3))
|
|
||||||
, m_addCodeSnippetsFunctor(std::bind(&QtCodeView::doAddCodeSnippets, this, std::placeholders::_1, std::placeholders::_2))
|
|
||||||
, m_setFileStateFunctor(std::bind(&QtCodeView::doSetFileState, this, std::placeholders::_1, std::placeholders::_2))
|
|
||||||
, m_doShowActiveSnippetFunctor(
|
|
||||||
std::bind(&QtCodeView::doShowActiveSnippet, this, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3))
|
|
||||||
, m_doShowActiveTokenIdsFunctor(std::bind(&QtCodeView::doShowActiveTokenIds, this, std::placeholders::_1))
|
|
||||||
, m_doShowActiveLocalSymbolIdsFunctor(std::bind(&QtCodeView::doShowActiveLocalSymbolIds, this, std::placeholders::_1))
|
|
||||||
, m_focusTokenIdsFunctor(std::bind(&QtCodeView::doFocusTokenIds, this, std::placeholders::_1))
|
|
||||||
{
|
{
|
||||||
m_widget = new QtCodeNavigator();
|
m_widget = new QtCodeNavigator();
|
||||||
setStyleSheet();
|
setStyleSheet();
|
||||||
@@ -40,138 +31,156 @@ void QtCodeView::initView()
|
|||||||
|
|
||||||
void QtCodeView::refreshView()
|
void QtCodeView::refreshView()
|
||||||
{
|
{
|
||||||
m_onQtThread(
|
m_onQtThread([=]()
|
||||||
[=]()
|
{
|
||||||
{
|
setStyleSheet();
|
||||||
setStyleSheet();
|
|
||||||
|
|
||||||
m_widget->refreshStyle();
|
m_widget->refreshStyle();
|
||||||
|
|
||||||
QtCodeArea::clearAnnotationColors();
|
QtCodeArea::clearAnnotationColors();
|
||||||
QtHighlighter::clearHighlightingRules();
|
QtHighlighter::clearHighlightingRules();
|
||||||
}
|
});
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void QtCodeView::clear()
|
void QtCodeView::clear()
|
||||||
{
|
{
|
||||||
m_onQtThread(
|
m_onQtThread([=]()
|
||||||
[=]()
|
{
|
||||||
{
|
m_widget->clear();
|
||||||
m_widget->clear();
|
});
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
m_errorInfos.clear();
|
m_scrollParams = ScrollParams();
|
||||||
}
|
|
||||||
|
|
||||||
void QtCodeView::clearCodeSnippets()
|
|
||||||
{
|
|
||||||
m_onQtThread(
|
|
||||||
[=]()
|
|
||||||
{
|
|
||||||
m_widget->clearCodeSnippets();
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
m_errorInfos.clear();
|
|
||||||
}
|
|
||||||
|
|
||||||
void QtCodeView::setErrorInfos(const std::vector<ErrorInfo>& errorInfos)
|
|
||||||
{
|
|
||||||
m_errorInfos = errorInfos;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool QtCodeView::showsErrors() const
|
bool QtCodeView::showsErrors() const
|
||||||
{
|
{
|
||||||
return m_errorInfos.size() > 0;
|
return m_widget->hasErrors();
|
||||||
}
|
}
|
||||||
|
|
||||||
void QtCodeView::showCodeSnippets(
|
void QtCodeView::showCodeSnippets(const std::vector<CodeSnippetParams>& snippets, const CodeParams params)
|
||||||
const std::vector<CodeSnippetParams>& snippets, const std::vector<Id>& activeTokenIds, bool setupFiles)
|
|
||||||
{
|
{
|
||||||
m_showCodeSnippetsFunctor(snippets, activeTokenIds, setupFiles);
|
m_onQtThread([=]()
|
||||||
|
{
|
||||||
|
if (params.clearSnippets)
|
||||||
|
{
|
||||||
|
m_widget->clearCodeSnippets();
|
||||||
|
|
||||||
|
m_widget->setActiveTokenIds(params.activeTokenIds);
|
||||||
|
m_widget->setErrorInfos(params.errorInfos);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool addedFiles = false;
|
||||||
|
|
||||||
|
for (const CodeSnippetParams& snippet : snippets)
|
||||||
|
{
|
||||||
|
if (snippet.isCollapsed)
|
||||||
|
{
|
||||||
|
m_widget->addFile(snippet.locationFile, snippet.refCount, snippet.modificationTime);
|
||||||
|
|
||||||
|
addedFiles = true;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
m_widget->addCodeSnippet(snippet);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (addedFiles)
|
||||||
|
{
|
||||||
|
m_widget->addedFiles();
|
||||||
|
}
|
||||||
|
|
||||||
|
m_widget->updateFiles();
|
||||||
|
|
||||||
|
if (m_widget->isInListMode())
|
||||||
|
{
|
||||||
|
setStyleSheet(); // so property "isLast" of QtCodeSnippet is computed correctly
|
||||||
|
}
|
||||||
|
|
||||||
|
if (params.showContents)
|
||||||
|
{
|
||||||
|
m_widget->showContents();
|
||||||
|
performScroll();
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
void QtCodeView::addCodeSnippets(const std::vector<CodeSnippetParams>& snippets, bool insert)
|
void QtCodeView::scrollTo(const ScrollParams params)
|
||||||
{
|
{
|
||||||
m_addCodeSnippetsFunctor(snippets, insert);
|
m_scrollParams = params;
|
||||||
}
|
}
|
||||||
|
|
||||||
void QtCodeView::setFileState(const FilePath filePath, FileState state)
|
void QtCodeView::setFileState(const FilePath filePath, FileState state)
|
||||||
{
|
{
|
||||||
m_setFileStateFunctor(filePath, state);
|
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(
|
void QtCodeView::showActiveSnippet(
|
||||||
const std::vector<Id>& activeTokenIds, std::shared_ptr<SourceLocationCollection> collection, bool scrollTo)
|
const std::vector<Id>& activeTokenIds, std::shared_ptr<SourceLocationCollection> collection, bool scrollTo)
|
||||||
{
|
{
|
||||||
m_doShowActiveSnippetFunctor(activeTokenIds, collection, scrollTo);
|
m_onQtThread([=]()
|
||||||
|
{
|
||||||
|
m_widget->showActiveSnippet(activeTokenIds, collection, scrollTo);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
void QtCodeView::showActiveTokenIds(const std::vector<Id>& activeTokenIds)
|
void QtCodeView::showActiveTokenIds(const std::vector<Id>& activeTokenIds)
|
||||||
{
|
{
|
||||||
m_doShowActiveTokenIdsFunctor(activeTokenIds);
|
m_onQtThread([=]()
|
||||||
|
{
|
||||||
|
m_widget->setActiveTokenIds(activeTokenIds);
|
||||||
|
m_widget->updateFiles();
|
||||||
|
|
||||||
|
performScroll();
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
void QtCodeView::showActiveLocalSymbolIds(const std::vector<Id>& activeLocalSymbolIds)
|
void QtCodeView::showActiveLocalSymbolIds(const std::vector<Id>& activeLocalSymbolIds)
|
||||||
{
|
{
|
||||||
m_doShowActiveLocalSymbolIdsFunctor(activeLocalSymbolIds);
|
m_onQtThread([=]()
|
||||||
|
{
|
||||||
|
m_widget->setActiveLocalSymbolIds(activeLocalSymbolIds);
|
||||||
|
m_widget->updateFiles();
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
void QtCodeView::focusTokenIds(const std::vector<Id>& focusedTokenIds)
|
void QtCodeView::focusTokenIds(const std::vector<Id>& focusedTokenIds)
|
||||||
{
|
{
|
||||||
m_focusTokenIdsFunctor(focusedTokenIds);
|
m_onQtThread([=]()
|
||||||
|
{
|
||||||
|
m_widget->focusTokenIds(focusedTokenIds);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
void QtCodeView::defocusTokenIds()
|
void QtCodeView::defocusTokenIds()
|
||||||
{
|
{
|
||||||
m_onQtThread(
|
m_onQtThread([=]()
|
||||||
[=]()
|
{
|
||||||
{
|
m_widget->defocusTokenIds();
|
||||||
m_widget->defocusTokenIds();
|
});
|
||||||
}
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void QtCodeView::showContents()
|
void QtCodeView::showContents()
|
||||||
{
|
{
|
||||||
m_onQtThread(
|
m_onQtThread([=]()
|
||||||
[=]()
|
{
|
||||||
{
|
m_widget->showContents();
|
||||||
m_widget->showContents();
|
performScroll();
|
||||||
}
|
});
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
void QtCodeView::scrollToValue(int value, bool inListMode)
|
|
||||||
{
|
|
||||||
m_onQtThread(
|
|
||||||
[=]()
|
|
||||||
{
|
|
||||||
m_widget->scrollToValue(value, inListMode);
|
|
||||||
}
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
void QtCodeView::scrollToLine(const FilePath filePath, unsigned int line)
|
|
||||||
{
|
|
||||||
m_onQtThread(
|
|
||||||
[=]()
|
|
||||||
{
|
|
||||||
m_widget->scrollToLine(filePath, line);
|
|
||||||
}
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
void QtCodeView::scrollToDefinition(bool ignoreActiveReference)
|
|
||||||
{
|
|
||||||
m_onQtThread(
|
|
||||||
[=]()
|
|
||||||
{
|
|
||||||
m_widget->scrollToDefinition(ignoreActiveReference);
|
|
||||||
}
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool QtCodeView::isInListMode() const
|
bool QtCodeView::isInListMode() const
|
||||||
@@ -179,87 +188,31 @@ bool QtCodeView::isInListMode() const
|
|||||||
return m_widget->isInListMode();
|
return m_widget->isInListMode();
|
||||||
}
|
}
|
||||||
|
|
||||||
void QtCodeView::doShowCodeSnippets(
|
bool QtCodeView::hasSingleFileCached(const FilePath& filePath) const
|
||||||
const std::vector<CodeSnippetParams>& snippets, const std::vector<Id>& activeTokenIds, bool setupFiles)
|
|
||||||
{
|
{
|
||||||
m_widget->setActiveTokenIds(activeTokenIds);
|
return m_widget->hasSingleFileCached(filePath);
|
||||||
m_widget->setErrorInfos(m_errorInfos);
|
|
||||||
|
|
||||||
for (const CodeSnippetParams& params : snippets)
|
|
||||||
{
|
|
||||||
if (params.isCollapsed)
|
|
||||||
{
|
|
||||||
m_widget->addFile(params.locationFile, params.refCount, params.modificationTime);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
m_widget->addCodeSnippet(params);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
m_widget->addedFiles();
|
|
||||||
|
|
||||||
if (setupFiles)
|
|
||||||
{
|
|
||||||
m_widget->setupFiles();
|
|
||||||
}
|
|
||||||
|
|
||||||
setStyleSheet(); // so property "isLast" of QtCodeSnippet is computed correctly
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void QtCodeView::doAddCodeSnippets(const std::vector<CodeSnippetParams>& snippets, bool insert)
|
void QtCodeView::performScroll()
|
||||||
{
|
{
|
||||||
for (const CodeSnippetParams& params : snippets)
|
switch (m_scrollParams.type)
|
||||||
{
|
{
|
||||||
m_widget->addCodeSnippet(params, insert);
|
case ScrollParams::SCROLL_TO_DEFINITION:
|
||||||
}
|
m_widget->scrollToDefinition(m_scrollParams.animated, m_scrollParams.ignoreActiveReference);
|
||||||
|
|
||||||
m_widget->updateFiles();
|
|
||||||
|
|
||||||
setStyleSheet(); // so property "isLast" of QtCodeSnippet is computed correctly
|
|
||||||
|
|
||||||
m_widget->scrollToSnippetIfRequested();
|
|
||||||
}
|
|
||||||
|
|
||||||
void QtCodeView::doSetFileState(const FilePath filePath, FileState state)
|
|
||||||
{
|
|
||||||
switch (state)
|
|
||||||
{
|
|
||||||
case FILE_MINIMIZED:
|
|
||||||
m_widget->setFileMinimized(filePath);
|
|
||||||
break;
|
break;
|
||||||
case FILE_SNIPPETS:
|
case ScrollParams::SCROLL_TO_LINE:
|
||||||
m_widget->setFileSnippets(filePath);
|
m_widget->scrollToLine(m_scrollParams.filePath, m_scrollParams.line);
|
||||||
break;
|
break;
|
||||||
case FILE_MAXIMIZED:
|
case ScrollParams::SCROLL_TO_VALUE:
|
||||||
m_widget->setFileMaximized(filePath);
|
m_widget->scrollToValue(m_scrollParams.value, m_scrollParams.inListMode);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
m_widget->scrollToSnippetIfRequested();
|
m_widget->scrollToSnippetIfRequested();
|
||||||
}
|
|
||||||
|
|
||||||
void QtCodeView::doShowActiveSnippet(
|
m_scrollParams = ScrollParams();
|
||||||
const std::vector<Id>& activeTokenIds, std::shared_ptr<SourceLocationCollection> collection, bool scrollTo)
|
|
||||||
{
|
|
||||||
m_widget->showActiveSnippet(activeTokenIds, collection, scrollTo);
|
|
||||||
}
|
|
||||||
|
|
||||||
void QtCodeView::doShowActiveTokenIds(const std::vector<Id>& activeTokenIds)
|
|
||||||
{
|
|
||||||
m_widget->setActiveTokenIds(activeTokenIds);
|
|
||||||
m_widget->updateFiles();
|
|
||||||
}
|
|
||||||
|
|
||||||
void QtCodeView::doShowActiveLocalSymbolIds(const std::vector<Id>& localSymbolIds)
|
|
||||||
{
|
|
||||||
m_widget->setActiveLocalSymbolIds(localSymbolIds);
|
|
||||||
m_widget->updateFiles();
|
|
||||||
}
|
|
||||||
|
|
||||||
void QtCodeView::doFocusTokenIds(const std::vector<Id>& focusedTokenIds)
|
|
||||||
{
|
|
||||||
m_widget->focusTokenIds(focusedTokenIds);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void QtCodeView::setStyleSheet() const
|
void QtCodeView::setStyleSheet() const
|
||||||
|
|||||||
@@ -1,17 +1,10 @@
|
|||||||
#ifndef QT_CODE_VIEW_H
|
#ifndef QT_CODE_VIEW_H
|
||||||
#define QT_CODE_VIEW_H
|
#define QT_CODE_VIEW_H
|
||||||
|
|
||||||
#include <memory>
|
|
||||||
#include <vector>
|
|
||||||
|
|
||||||
#include "utility/types.h"
|
|
||||||
|
|
||||||
#include "component/view/CodeView.h"
|
#include "component/view/CodeView.h"
|
||||||
#include "qt/utility/QtThreadedFunctor.h"
|
#include "qt/utility/QtThreadedFunctor.h"
|
||||||
|
|
||||||
class QFrame;
|
|
||||||
class QtCodeNavigator;
|
class QtCodeNavigator;
|
||||||
class QWidget;
|
|
||||||
|
|
||||||
class QtCodeView
|
class QtCodeView
|
||||||
: public CodeView
|
: public CodeView
|
||||||
@@ -27,15 +20,12 @@ public:
|
|||||||
|
|
||||||
// CodeView implementation
|
// CodeView implementation
|
||||||
virtual void clear();
|
virtual void clear();
|
||||||
virtual void clearCodeSnippets();
|
|
||||||
|
|
||||||
virtual void setErrorInfos(const std::vector<ErrorInfo>& errorInfos);
|
virtual void showCodeSnippets(const std::vector<CodeSnippetParams>& snippets, const CodeParams params);
|
||||||
|
virtual void scrollTo(const ScrollParams params);
|
||||||
|
|
||||||
virtual bool showsErrors() const;
|
virtual bool showsErrors() const;
|
||||||
|
|
||||||
virtual void showCodeSnippets(
|
|
||||||
const std::vector<CodeSnippetParams>& snippets, const std::vector<Id>& activeTokenIds, bool setupFiles);
|
|
||||||
virtual void addCodeSnippets(const std::vector<CodeSnippetParams>& snippets, bool insert);
|
|
||||||
|
|
||||||
virtual void setFileState(const FilePath filePath, FileState state);
|
virtual void setFileState(const FilePath filePath, FileState state);
|
||||||
|
|
||||||
virtual void showActiveSnippet(
|
virtual void showActiveSnippet(
|
||||||
@@ -48,41 +38,20 @@ public:
|
|||||||
|
|
||||||
virtual void showContents();
|
virtual void showContents();
|
||||||
|
|
||||||
virtual void scrollToValue(int value, bool inListMode);
|
|
||||||
virtual void scrollToLine(const FilePath filePath, unsigned int line);
|
|
||||||
virtual void scrollToDefinition(bool ignoreActiveReference);
|
|
||||||
|
|
||||||
virtual bool isInListMode() const;
|
virtual bool isInListMode() const;
|
||||||
|
virtual bool hasSingleFileCached(const FilePath& filePath) const;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void doShowCodeSnippets(
|
void performScroll();
|
||||||
const std::vector<CodeSnippetParams>& snippets, const std::vector<Id>& activeTokenIds, bool setupFiles);
|
|
||||||
void doAddCodeSnippets(const std::vector<CodeSnippetParams>& snippets, bool insert);
|
|
||||||
|
|
||||||
void doSetFileState(const FilePath filePath, FileState state);
|
|
||||||
|
|
||||||
void doShowActiveSnippet(
|
|
||||||
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);
|
|
||||||
|
|
||||||
void doFocusTokenIds(const std::vector<Id>& focusedTokenIds);
|
|
||||||
|
|
||||||
void setStyleSheet() const;
|
void setStyleSheet() const;
|
||||||
|
|
||||||
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<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;
|
|
||||||
|
|
||||||
QtThreadedLambdaFunctor m_onQtThread;
|
QtThreadedLambdaFunctor m_onQtThread;
|
||||||
|
|
||||||
QtCodeNavigator* m_widget;
|
QtCodeNavigator* m_widget;
|
||||||
|
|
||||||
std::vector<ErrorInfo> m_errorInfos;
|
ScrollParams m_scrollParams;
|
||||||
};
|
};
|
||||||
|
|
||||||
# endif // QT_CODE_VIEW_H
|
# endif // QT_CODE_VIEW_H
|
||||||
|
|||||||
Reference in New Issue
Block a user