logic: make SearchController only listen to MessageActivateTokens

This change makes MessageActivateTokens being used consistently throughout all Controllers. The FeatureController
accepts all incoming activation messages and turns them into MessageActivateTokens, which are then accepted by all
view controllers.
This commit is contained in:
Eberhard Graether
2015-10-02 10:18:17 +02:00
parent 2704d47cd8
commit a855e14ebf
7 changed files with 61 additions and 54 deletions
@@ -12,42 +12,12 @@ SearchController::~SearchController()
{
}
void SearchController::handleMessage(MessageActivateEdge* message)
void SearchController::handleMessage(MessageActivateTokens* message)
{
if (!message->isAggregation())
if (!message->isEdge)
{
return;
getView()->setMatches(m_storageAccess->getSearchMatchesForTokenIds(message->tokenIds));
}
getView()->setMatches(std::vector<SearchMatch>());
}
void SearchController::handleMessage(MessageActivateFile* message)
{
SearchMatch match;
match.fullName = message->filePath.fileName();
match.nodeType = Node::NODE_FILE;
match.tokenIds.insert(m_storageAccess->getTokenIdForFileNode(message->filePath));
match.searchType = SearchMatch::SEARCH_TOKEN;
getView()->setMatches(std::vector<SearchMatch>(1, match));
}
void SearchController::handleMessage(MessageActivateNodes* message)
{
std::vector<SearchMatch> matches;
for (const MessageActivateNodes::ActiveNode& node : message->nodes)
{
SearchMatch match;
match.fullName = node.nameHierarchy.getFullName();
match.nodeType = node.type;
match.tokenIds.insert(node.nodeId);
match.searchType = SearchMatch::SEARCH_TOKEN;
matches.push_back(match);
}
getView()->setMatches(matches);
}
void SearchController::handleMessage(MessageFind* message)
@@ -55,11 +25,6 @@ void SearchController::handleMessage(MessageFind* message)
getView()->setFocus();
}
void SearchController::handleMessage(MessageSearch* message)
{
getView()->setMatches(message->getMatches());
}
void SearchController::handleMessage(MessageSearchAutocomplete* message)
{
LOG_INFO("autocomplete string: \"" + message->word + "\"");
@@ -1,15 +1,10 @@
#ifndef SEARCH_CONTROLLER_H
#define SEARCH_CONTROLLER_H
#include <string>
#include "component/controller/Controller.h"
#include "utility/messaging/MessageListener.h"
#include "utility/messaging/type/MessageActivateEdge.h"
#include "utility/messaging/type/MessageActivateFile.h"
#include "utility/messaging/type/MessageActivateNodes.h"
#include "utility/messaging/type/MessageActivateTokens.h"
#include "utility/messaging/type/MessageFind.h"
#include "utility/messaging/type/MessageSearch.h"
#include "utility/messaging/type/MessageSearchAutocomplete.h"
class StorageAccess;
@@ -17,11 +12,8 @@ class SearchView;
class SearchController
: public Controller
, public MessageListener<MessageActivateEdge>
, public MessageListener<MessageActivateFile>
, public MessageListener<MessageActivateNodes>
, public MessageListener<MessageActivateTokens>
, public MessageListener<MessageFind>
, public MessageListener<MessageSearch>
, public MessageListener<MessageSearchAutocomplete>
{
public:
@@ -29,11 +21,8 @@ public:
~SearchController();
private:
virtual void handleMessage(MessageActivateEdge* message);
virtual void handleMessage(MessageActivateFile* message);
virtual void handleMessage(MessageActivateNodes* message);
virtual void handleMessage(MessageActivateTokens* message);
virtual void handleMessage(MessageFind* message);
virtual void handleMessage(MessageSearch* message);
virtual void handleMessage(MessageSearchAutocomplete* message);
SearchView* getView();
+36
View File
@@ -784,6 +784,42 @@ std::vector<SearchMatch> Storage::getAutocompletionMatches(const std::string& qu
return matches;
}
std::vector<SearchMatch> Storage::getSearchMatchesForTokenIds(const std::vector<Id>& tokenIds) const
{
std::vector<SearchMatch> matches;
for (Id tokenId : tokenIds)
{
SearchMatch match;
if (m_sqliteStorage.isFile(tokenId))
{
StorageFile file = m_sqliteStorage.getFileById(tokenId);
match.fullName = m_tokenIndex.getNameHierarchyForTokenId(tokenId).getFullName();
match.nodeType = Node::NODE_FILE;
}
else if (m_sqliteStorage.isNode(tokenId))
{
StorageNode node = m_sqliteStorage.getNodeById(tokenId);
match.fullName = m_tokenIndex.getNameHierarchyForTokenId(tokenId).getFullName();
match.nodeType = Node::intToType(node.type);
}
else
{
continue;
}
match.tokenIds.insert(tokenId);
match.searchType = SearchMatch::SEARCH_TOKEN;
matches.push_back(match);
}
return matches;
}
std::shared_ptr<Graph> Storage::getGraphForActiveTokenIds(const std::vector<Id>& tokenIds) const
{
std::shared_ptr<Graph> g = std::make_shared<Graph>();
+4
View File
@@ -130,8 +130,10 @@ public:
virtual NameHierarchy getNameHierarchyForNodeWithId(Id nodeId) const;
virtual Node::NodeType getNodeTypeForNodeWithId(Id nodeId) const;
virtual std::vector<SearchMatch> getAutocompletionMatches(
const std::string& query, const std::string& word) const;
virtual std::vector<SearchMatch> getSearchMatchesForTokenIds(const std::vector<Id>& tokenIds) const;
virtual std::shared_ptr<Graph> getGraphForActiveTokenIds(const std::vector<Id>& tokenIds) const;
@@ -156,6 +158,8 @@ public:
virtual std::shared_ptr<TextAccess> getFileContent(const FilePath& filePath) const;
private:
Id addNodeHierarchy(Node::NodeType nodeType, NameHierarchy nameHierarchy, bool distinct = false);
Id addNodeHierarchyWithDistinctSignature(Node::NodeType type, const ParseFunction& function);
+2
View File
@@ -31,8 +31,10 @@ public:
virtual NameHierarchy getNameHierarchyForNodeWithId(Id id) const = 0;
virtual Node::NodeType getNodeTypeForNodeWithId(Id id) const = 0;
virtual std::vector<SearchMatch> getAutocompletionMatches(
const std::string& query, const std::string& word) const = 0;
virtual std::vector<SearchMatch> getSearchMatchesForTokenIds(const std::vector<Id>& tokenIds) const = 0;
virtual std::shared_ptr<Graph> getGraphForActiveTokenIds(const std::vector<Id>& tokenIds) const = 0;
@@ -94,6 +94,16 @@ std::vector<SearchMatch> StorageAccessProxy::getAutocompletionMatches(
return std::vector<SearchMatch>();
}
std::vector<SearchMatch> StorageAccessProxy::getSearchMatchesForTokenIds(const std::vector<Id>& tokenIds) const
{
if (hasSubject())
{
return m_subject->getSearchMatchesForTokenIds(tokenIds);
}
return std::vector<SearchMatch>();
}
std::shared_ptr<Graph> StorageAccessProxy::getGraphForActiveTokenIds(const std::vector<Id>& tokenIds) const
{
if (hasSubject())
+3 -2
View File
@@ -21,8 +21,9 @@ public:
virtual NameHierarchy getNameHierarchyForNodeWithId(Id id) const;
virtual Node::NodeType getNodeTypeForNodeWithId(Id id) const;
virtual std::vector<SearchMatch> getAutocompletionMatches(
const std::string& query, const std::string& word) const;
virtual std::vector<SearchMatch> getAutocompletionMatches(const std::string& query, const std::string& word) const;
virtual std::vector<SearchMatch> getSearchMatchesForTokenIds(const std::vector<Id>& tokenIds) const;
virtual std::shared_ptr<Graph> getGraphForActiveTokenIds(const std::vector<Id>& tokenIds) const;