ui: clicking snippet title to show full scope

This change lets the user click the snippet title in the CodeView to insert the full scope. The existing snippets are
merged with the new lines accordingly.
This commit is contained in:
Eberhard Graether
2015-07-20 00:57:19 +02:00
parent e5a8609d7a
commit 73aa6080aa
23 changed files with 313 additions and 26 deletions
+1
View File
@@ -275,6 +275,7 @@ add_files(
utility/messaging/type/MessageSearch.h
utility/messaging/type/MessageSearchAutocomplete.h
utility/messaging/type/MessageShowFile.h
utility/messaging/type/MessageShowScope.h
utility/messaging/type/MessageStatus.h
utility/messaging/type/MessageSwitchColorScheme.h
utility/messaging/type/MessageUndo.h
@@ -114,7 +114,6 @@ void CodeController::handleMessage(MessageShowFile* message)
params.endLineNumber = message->endLineNumber;
std::shared_ptr<TextAccess> textAccess = TextAccess::createFromFile(message->filePath);
params.lineCount = textAccess->getLineCount();
params.code = textAccess->getText();
params.locationFile = m_storageAccess->getTokenLocationsForFile(message->filePath);
@@ -122,6 +121,29 @@ void CodeController::handleMessage(MessageShowFile* message)
getView()->showCodeFile(params);
}
void CodeController::handleMessage(MessageShowScope* message)
{
TokenLocationCollection collection =
m_storageAccess->getTokenLocationsForLocationIds(std::vector<Id>(1, message->scopeLocationId));
TokenLocation* location = collection.findTokenLocationById(message->scopeLocationId);
if (!location || !location->isScopeTokenLocation() || !location->getOtherTokenLocation())
{
LOG_ERROR("MessageShowScope did not contain a valid scope location id");
return;
}
std::vector<CodeView::CodeSnippetParams> snippets = getSnippetsForActiveTokenLocations(collection, 0);
if (snippets.size() != 1)
{
LOG_ERROR("MessageShowScope didn't result in one single snippet to be created");
return;
}
getView()->addCodeSnippet(snippets[0]);
}
CodeView* CodeController::getView()
{
return Controller::getView<CodeView>();
@@ -228,6 +250,7 @@ std::vector<CodeView::CodeSnippetParams> CodeController::getSnippetsForFile(std:
[&](TokenLocation* location)
{
params.title = m_storageAccess->getNameForNodeWithId(location->getTokenId());
params.titleId = location->getId();
}
);
}
@@ -10,6 +10,7 @@
#include "utility/messaging/type/MessageFocusIn.h"
#include "utility/messaging/type/MessageFocusOut.h"
#include "utility/messaging/type/MessageShowFile.h"
#include "utility/messaging/type/MessageShowScope.h"
#include "utility/types.h"
#include "component/controller/helper/SnippetMerger.h"
@@ -27,6 +28,7 @@ class CodeController
, public MessageListener<MessageFocusIn>
, public MessageListener<MessageFocusOut>
, public MessageListener<MessageShowFile>
, public MessageListener<MessageShowScope>
{
public:
CodeController(StorageAccess* storageAccess);
@@ -40,6 +42,7 @@ private:
virtual void handleMessage(MessageFocusIn* message);
virtual void handleMessage(MessageFocusOut* message);
virtual void handleMessage(MessageShowFile* message);
virtual void handleMessage(MessageShowScope* message);
CodeView* getView();
+1 -1
View File
@@ -6,7 +6,7 @@
CodeView::CodeSnippetParams::CodeSnippetParams()
: startLineNumber(0)
, endLineNumber(0)
, lineCount(0)
, titleId(0)
, locationFile(std::make_shared<TokenLocationFile>(""))
, isActive(false)
, isDeclaration(false)
+3 -1
View File
@@ -21,11 +21,12 @@ public:
uint startLineNumber;
uint endLineNumber;
uint lineCount;
std::string title;
std::string code;
Id titleId;
std::shared_ptr<TokenLocationFile> locationFile;
bool isActive;
@@ -41,6 +42,7 @@ public:
virtual void setErrorMessages(const std::vector<std::string>& errorMessages) = 0;
virtual void showCodeSnippets(const std::vector<CodeSnippetParams>& snippets) = 0;
virtual void addCodeSnippet(const CodeSnippetParams& snippet) = 0;
virtual void showCodeFile(const CodeSnippetParams& params) = 0;
virtual void scrollToFirstActiveSnippet() = 0;
+17
View File
@@ -997,6 +997,23 @@ TokenLocationCollection Storage::getTokenLocationsForTokenIds(const std::vector<
return ret;
}
TokenLocationCollection Storage::getTokenLocationsForLocationIds(const std::vector<Id>& locationIds) const
{
TokenLocationCollection ret;
for (Id locationId : locationIds)
{
TokenLocation* location = m_locationCollection.findTokenLocationById(locationId);
if (location->getOtherTokenLocation())
{
ret.addTokenLocationAsPlainCopy(location);
ret.addTokenLocationAsPlainCopy(location->getOtherTokenLocation());
}
}
return ret;
}
std::shared_ptr<TokenLocationFile> Storage::getTokenLocationsForFile(const std::string& filePath) const
{
std::shared_ptr<TokenLocationFile> ret = std::make_shared<TokenLocationFile>(filePath);
+1
View File
@@ -126,6 +126,7 @@ public:
virtual std::vector<Id> getTokenIdsForAggregationEdge(Id aggregationId) const;
virtual TokenLocationCollection getTokenLocationsForTokenIds(const std::vector<Id>& tokenIds) const;
virtual TokenLocationCollection getTokenLocationsForLocationIds(const std::vector<Id>& locationIds) const;
virtual std::shared_ptr<TokenLocationFile> getTokenLocationsForFile(const std::string& filePath) const;
virtual std::shared_ptr<TokenLocationFile> getTokenLocationsForLinesInFile(
const std::string& filePath, uint firstLineNumber, uint lastLineNumber
+1
View File
@@ -39,6 +39,7 @@ public:
virtual std::vector<Id> getTokenIdsForAggregationEdge(Id aggregationId) const = 0;
virtual TokenLocationCollection getTokenLocationsForTokenIds(const std::vector<Id>& tokenIds) const = 0;
virtual TokenLocationCollection getTokenLocationsForLocationIds(const std::vector<Id>& locationIds) const = 0;
virtual std::shared_ptr<TokenLocationFile> getTokenLocationsForFile(const std::string& filePath) const = 0;
virtual std::shared_ptr<TokenLocationFile> getTokenLocationsForLinesInFile(
const std::string& filePath, uint firstLineNumber, uint lastLineNumber) const = 0;
@@ -152,6 +152,16 @@ TokenLocationCollection StorageAccessProxy::getTokenLocationsForTokenIds(const s
return TokenLocationCollection();
}
TokenLocationCollection StorageAccessProxy::getTokenLocationsForLocationIds(const std::vector<Id>& locationIds) const
{
if (hasSubject())
{
return m_subject->getTokenLocationsForLocationIds(locationIds);
}
return TokenLocationCollection();
}
std::shared_ptr<TokenLocationFile> StorageAccessProxy::getTokenLocationsForFile(const std::string& filePath) const
{
if (hasSubject())
+1
View File
@@ -31,6 +31,7 @@ public:
virtual std::vector<Id> getTokenIdsForAggregationEdge(Id aggregationId) const;
virtual TokenLocationCollection getTokenLocationsForTokenIds(const std::vector<Id>& tokenIds) const;
virtual TokenLocationCollection getTokenLocationsForLocationIds(const std::vector<Id>& locationIds) const;
virtual std::shared_ptr<TokenLocationFile> getTokenLocationsForFile(const std::string& filePath) const;
virtual std::shared_ptr<TokenLocationFile> getTokenLocationsForLinesInFile(
const std::string& filePath, uint firstLineNumber, uint lastLineNumber
+5
View File
@@ -177,6 +177,11 @@ bool TokenLocation::isEndTokenLocation() const
return !m_isStart;
}
bool TokenLocation::isScopeTokenLocation() const
{
return m_type == LOCATION_SCOPE;
}
Id TokenLocation::s_locationId = 1;
std::ostream& operator<<(std::ostream& ostream, const TokenLocation& location)
+2
View File
@@ -54,6 +54,8 @@ public:
bool isStartTokenLocation() const;
bool isEndTokenLocation() const;
bool isScopeTokenLocation() const;
private:
static Id s_locationId; // next free own id
@@ -0,0 +1,24 @@
#ifndef MESSAGE_SHOW_SCOPE_H
#define MESSAGE_SHOW_SCOPE_H
#include "utility/messaging/Message.h"
#include "utility/types.h"
class MessageShowScope
: public Message<MessageShowScope>
{
public:
MessageShowScope(Id scopeLocationId)
: scopeLocationId(scopeLocationId)
{
}
static const std::string getStaticType()
{
return "MessageShowScope";
}
const Id scopeLocationId;
};
#endif // MESSAGE_SHOW_SCOPE_H