logic: Refactored namespace activation
* show namespace name in search view when activated * show namespace definitions in code view when activated * no children in namespace * no implicit nodes in overview or namespace * Show a maximum of 10 open snippets * Fixed bug causing nodes in GraphView to be stacked at 0,0
This commit is contained in:
@@ -91,8 +91,7 @@ void CodeController::handleMessage(MessageActivateTokens* message)
|
||||
CodeView* view = getView();
|
||||
view->setErrorMessages(std::vector<std::string>());
|
||||
|
||||
std::vector<Id> activeTokenIds =
|
||||
(message->originalTokenIds.size() > 0 ? message->originalTokenIds : message->tokenIds);
|
||||
std::vector<Id> activeTokenIds = message->tokenIds;
|
||||
Id declarationId = 0; // 0 means that no token is found.
|
||||
|
||||
if (!message->isAggregation)
|
||||
@@ -106,11 +105,6 @@ void CodeController::handleMessage(MessageActivateTokens* message)
|
||||
activeTokenIds = m_storageAccess->getActiveTokenIdsForId(activeTokenIds[0], &declarationId);
|
||||
}
|
||||
|
||||
if (message->originalTokenIds.size() > 0)
|
||||
{
|
||||
declarationId = 0;
|
||||
}
|
||||
|
||||
if (message->isEdge)
|
||||
{
|
||||
view->showFirstActiveSnippet(activeTokenIds, message->isLast());
|
||||
@@ -305,7 +299,7 @@ std::vector<CodeSnippetParams> CodeController::getSnippetsForActiveTokenLocation
|
||||
}
|
||||
);
|
||||
|
||||
if (isDeclarationFile || collection->getTokenLocationFileCount() < 5 || file->isWholeCopy)
|
||||
if (snippets.size() < 10 && (isDeclarationFile || collection->getTokenLocationFileCount() < 5 || file->isWholeCopy))
|
||||
{
|
||||
std::vector<CodeSnippetParams> fileSnippets = getSnippetsForActiveTokenLocationsInFile(file);
|
||||
|
||||
|
||||
@@ -65,8 +65,6 @@ void FeatureController::handleMessage(MessageActivateTokenIds* message)
|
||||
void FeatureController::handleMessage(MessageActivateTokenLocations* message)
|
||||
{
|
||||
std::vector<Id> nodeIds = m_storageAccess->getNodeIdsForLocationIds(message->locationIds);
|
||||
nodeIds = m_storageAccess->getActiveTokenIdsForTokenIds(nodeIds);
|
||||
|
||||
MessageActivateNodes m;
|
||||
for (Id nodeId : nodeIds)
|
||||
{
|
||||
|
||||
@@ -67,16 +67,10 @@ void GraphController::handleMessage(MessageActivateTokens* message)
|
||||
|
||||
std::vector<Id> tokenIds = utility::concat(m_activeNodeIds, m_activeEdgeIds);
|
||||
|
||||
std::shared_ptr<Graph> graph =
|
||||
m_storageAccess->getGraphForActiveTokenIds(tokenIds, message->originalTokenIds.size() > 0);
|
||||
std::shared_ptr<Graph> graph = m_storageAccess->getGraphForActiveTokenIds(tokenIds);
|
||||
|
||||
createDummyGraphForTokenIds(tokenIds, graph);
|
||||
|
||||
if (message->originalTokenIds.size() > 0)
|
||||
{
|
||||
deactivateNodesRecursive(&m_dummyNodes);
|
||||
}
|
||||
|
||||
if (m_activeNodeIds.size() == 1)
|
||||
{
|
||||
bundleNodes();
|
||||
@@ -344,10 +338,13 @@ void GraphController::autoExpandActiveNode(const std::vector<Id>& activeTokenIds
|
||||
void GraphController::setActiveAndVisibility(const std::vector<Id>& activeTokenIds)
|
||||
{
|
||||
bool noActive = activeTokenIds.size() == 0;
|
||||
|
||||
for (DummyNode& node : m_dummyNodes)
|
||||
if (activeTokenIds.size() > 0)
|
||||
{
|
||||
setNodeActiveRecursive(node, activeTokenIds);
|
||||
noActive = true;
|
||||
for (DummyNode& node : m_dummyNodes)
|
||||
{
|
||||
setNodeActiveRecursive(node, activeTokenIds, &noActive);
|
||||
}
|
||||
}
|
||||
|
||||
for (DummyEdge& edge : m_dummyEdges)
|
||||
@@ -382,18 +379,23 @@ void GraphController::setActiveAndVisibility(const std::vector<Id>& activeTokenI
|
||||
}
|
||||
}
|
||||
|
||||
void GraphController::setNodeActiveRecursive(DummyNode& node, const std::vector<Id>& activeTokenIds) const
|
||||
void GraphController::setNodeActiveRecursive(DummyNode& node, const std::vector<Id>& activeTokenIds, bool* noActive) const
|
||||
{
|
||||
node.active = false;
|
||||
|
||||
if (node.isGraphNode())
|
||||
{
|
||||
node.active = find(activeTokenIds.begin(), activeTokenIds.end(), node.data->getId()) != activeTokenIds.end();
|
||||
|
||||
if (node.active)
|
||||
{
|
||||
*noActive = false;
|
||||
}
|
||||
}
|
||||
|
||||
for (DummyNode& subNode : node.subNodes)
|
||||
{
|
||||
setNodeActiveRecursive(subNode, activeTokenIds);
|
||||
setNodeActiveRecursive(subNode, activeTokenIds, noActive);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -474,15 +476,6 @@ void GraphController::setNodeVisibilityRecursiveTopDown(DummyNode& node, bool pa
|
||||
}
|
||||
}
|
||||
|
||||
void GraphController::deactivateNodesRecursive(std::vector<DummyNode>* nodes) const
|
||||
{
|
||||
for (DummyNode& node : *nodes)
|
||||
{
|
||||
node.active = false;
|
||||
deactivateNodesRecursive(&node.subNodes);
|
||||
}
|
||||
}
|
||||
|
||||
void GraphController::bundleNodes()
|
||||
{
|
||||
bundleNodesAndEdgesMatching(
|
||||
|
||||
@@ -63,11 +63,10 @@ private:
|
||||
void autoExpandActiveNode(const std::vector<Id>& activeTokenIds);
|
||||
|
||||
void setActiveAndVisibility(const std::vector<Id>& activeTokenIds);
|
||||
void setNodeActiveRecursive(DummyNode& node, const std::vector<Id>& activeTokenIds) const;
|
||||
void setNodeActiveRecursive(DummyNode& node, const std::vector<Id>& activeTokenIds, bool* noActive) const;
|
||||
void removeImplicitAndUndefinedChildrenRecursive(DummyNode& node);
|
||||
bool setNodeVisibilityRecursiveBottomUp(DummyNode& node, bool noActive) const;
|
||||
void setNodeVisibilityRecursiveTopDown(DummyNode& node, bool parentExpanded) const;
|
||||
void deactivateNodesRecursive(std::vector<DummyNode>* nodes) const;
|
||||
|
||||
void bundleNodes();
|
||||
void bundleNodesAndEdgesMatching(std::function<bool(const DummyNode&)> matcher, size_t count, const std::string& name);
|
||||
|
||||
@@ -22,10 +22,7 @@ void SearchController::handleMessage(MessageActivateTokens* message)
|
||||
{
|
||||
if (!message->keepContent() && !message->isFromSearch)
|
||||
{
|
||||
const std::vector<Id>& tokenIds =
|
||||
(message->originalTokenIds.size() > 0 ? message->originalTokenIds : message->tokenIds);
|
||||
|
||||
getView()->setMatches(m_storageAccess->getSearchMatchesForTokenIds(tokenIds));
|
||||
getView()->setMatches(m_storageAccess->getSearchMatchesForTokenIds(message->tokenIds));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -95,11 +95,7 @@ std::shared_ptr<MessageActivateTokens> ActivationTranslator::translateMessage(co
|
||||
}
|
||||
|
||||
std::shared_ptr<MessageActivateTokens> m;
|
||||
m = std::make_shared<MessageActivateTokens>(message, m_storageAccess->getActiveTokenIdsForTokenIds(nodeIds));
|
||||
if (nodeIds != m->tokenIds)
|
||||
{
|
||||
m->originalTokenIds = nodeIds;
|
||||
}
|
||||
m = std::make_shared<MessageActivateTokens>(message, nodeIds);
|
||||
m->isFromSystem = message->isFromSystem;
|
||||
return m;
|
||||
}
|
||||
@@ -135,12 +131,7 @@ std::shared_ptr<MessageActivateTokens> ActivationTranslator::translateMessage(co
|
||||
|
||||
std::vector<Id> tokenIds = m_storageAccess->getTokenIdsForMatches(matches);
|
||||
|
||||
std::shared_ptr<MessageActivateTokens> m =
|
||||
std::make_shared<MessageActivateTokens>(message, m_storageAccess->getActiveTokenIdsForTokenIds(tokenIds));
|
||||
if (tokenIds != m->tokenIds)
|
||||
{
|
||||
m->originalTokenIds = tokenIds;
|
||||
}
|
||||
std::shared_ptr<MessageActivateTokens> m = std::make_shared<MessageActivateTokens>(message, tokenIds);
|
||||
if (message->isFresh())
|
||||
{
|
||||
m->isFromSearch = true;
|
||||
|
||||
+61
-61
@@ -226,7 +226,9 @@ std::vector<SearchMatch> Storage::getAutocompletionMatches(const std::string& qu
|
||||
if (results[i].elementIds.size() > 0)
|
||||
{
|
||||
StorageNode firstNode(0, 0, "", 0);
|
||||
for (std::set<Id>::const_iterator itElementIds = results[i].elementIds.begin(); itElementIds != results[i].elementIds.end(); itElementIds++)
|
||||
for (std::set<Id>::const_iterator itElementIds = results[i].elementIds.begin();
|
||||
itElementIds != results[i].elementIds.end();
|
||||
itElementIds++)
|
||||
{
|
||||
Id elementId = *itElementIds;
|
||||
if (elementId != 0)
|
||||
@@ -270,7 +272,8 @@ std::vector<SearchMatch> Storage::getAutocompletionMatches(const std::string& qu
|
||||
|
||||
std::vector<SearchMatch> Storage::getSearchMatchesForTokenIds(const std::vector<Id>& elementIds) const
|
||||
{
|
||||
// todo: what if all these elements share the same node in the searchindex? in that case there should be only one search match.
|
||||
// todo: what if all these elements share the same node in the searchindex?
|
||||
// In that case there should be only one search match.
|
||||
std::vector<SearchMatch> matches;
|
||||
|
||||
for (Id elementId : elementIds)
|
||||
@@ -309,7 +312,8 @@ std::shared_ptr<Graph> Storage::getGraphForAll() const
|
||||
std::vector<Id> tokenIds;
|
||||
for (StorageNode node: m_sqliteStorage.getAllNodes())
|
||||
{
|
||||
if (intToDefinitionType(node.definitionType) != DEFINITION_NONE && (!m_hierarchyCache.isChildOfVisibleNodeOrInvisible(node.id) ||
|
||||
if (intToDefinitionType(node.definitionType) == DEFINITION_EXPLICIT &&
|
||||
(!m_hierarchyCache.isChildOfVisibleNodeOrInvisible(node.id) ||
|
||||
Node::intToType(node.type) == Node::NODE_NAMESPACE))
|
||||
{
|
||||
tokenIds.push_back(node.id);
|
||||
@@ -321,57 +325,86 @@ std::shared_ptr<Graph> Storage::getGraphForAll() const
|
||||
return graph;
|
||||
}
|
||||
|
||||
std::shared_ptr<Graph> Storage::getGraphForActiveTokenIds(const std::vector<Id>& tokenIds, bool activeOnly) const
|
||||
std::shared_ptr<Graph> Storage::getGraphForActiveTokenIds(const std::vector<Id>& tokenIds) const
|
||||
{
|
||||
std::shared_ptr<Graph> g = std::make_shared<Graph>();
|
||||
Graph* graph = g.get();
|
||||
|
||||
std::vector<Id> ids(tokenIds);
|
||||
bool isNamespace = false;
|
||||
|
||||
std::vector<Id> nodeIds;
|
||||
std::vector<Id> edgeIds;
|
||||
bool addAggregations = false;
|
||||
|
||||
if (tokenIds.size() == 1 && !activeOnly)
|
||||
if (tokenIds.size() == 1)
|
||||
{
|
||||
const Id elementId = tokenIds[0];
|
||||
StorageNode node = m_sqliteStorage.getNodeById(elementId);
|
||||
|
||||
if (m_sqliteStorage.isNode(elementId))
|
||||
if (node.id > 0)
|
||||
{
|
||||
nodeIds.push_back(elementId);
|
||||
|
||||
std::vector<StorageEdge> edges = m_sqliteStorage.getEdgesBySourceOrTargetId(elementId);
|
||||
for (const StorageEdge& edge : edges)
|
||||
if (Node::intToType(node.type) == Node::NODE_NAMESPACE)
|
||||
{
|
||||
if (Edge::intToType(edge.type) != Edge::EDGE_MEMBER)
|
||||
{
|
||||
edgeIds.push_back(edge.id);
|
||||
}
|
||||
}
|
||||
ids.clear();
|
||||
m_hierarchyCache.addFirstVisibleChildIdsForNodeId(elementId, &ids);
|
||||
|
||||
addAggregations = true;
|
||||
isNamespace = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
nodeIds.push_back(elementId);
|
||||
|
||||
std::vector<StorageEdge> edges = m_sqliteStorage.getEdgesBySourceOrTargetId(elementId);
|
||||
for (const StorageEdge& edge : edges)
|
||||
{
|
||||
if (Edge::intToType(edge.type) != Edge::EDGE_MEMBER)
|
||||
{
|
||||
edgeIds.push_back(edge.id);
|
||||
}
|
||||
}
|
||||
|
||||
addAggregations = true;
|
||||
}
|
||||
}
|
||||
else if (m_sqliteStorage.isEdge(elementId))
|
||||
{
|
||||
edgeIds.push_back(elementId);
|
||||
}
|
||||
}
|
||||
else if (tokenIds.size() >= 1)
|
||||
{
|
||||
for (size_t i = 0; i < tokenIds.size(); i++)
|
||||
{
|
||||
const Id elementId = tokenIds[i];
|
||||
|
||||
if (m_sqliteStorage.isNode(elementId))
|
||||
if (ids.size() >= 1 || isNamespace)
|
||||
{
|
||||
std::vector<StorageNode> nodes = m_sqliteStorage.getNodesByIds(ids);
|
||||
for (const StorageNode& node : nodes)
|
||||
{
|
||||
if (node.id > 0 && (!isNamespace || intToDefinitionType(node.definitionType) == DEFINITION_EXPLICIT))
|
||||
{
|
||||
nodeIds.push_back(elementId);
|
||||
nodeIds.push_back(node.id);
|
||||
}
|
||||
else
|
||||
}
|
||||
|
||||
if (nodeIds.size() != ids.size())
|
||||
{
|
||||
std::vector<StorageEdge> edges = m_sqliteStorage.getEdgesByIds(ids);
|
||||
for (const StorageEdge& edge : edges)
|
||||
{
|
||||
edgeIds.push_back(elementId);
|
||||
if (edge.id > 0)
|
||||
{
|
||||
edgeIds.push_back(edge.id);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
addNodesAndEdgesToGraph(nodeIds, edgeIds, graph);
|
||||
if (isNamespace)
|
||||
{
|
||||
addNodesToGraph(nodeIds, graph);
|
||||
}
|
||||
else
|
||||
{
|
||||
addNodesWithChildrenAndEdgesToGraph(nodeIds, edgeIds, graph);
|
||||
}
|
||||
|
||||
if (addAggregations)
|
||||
{
|
||||
@@ -383,39 +416,6 @@ std::shared_ptr<Graph> Storage::getGraphForActiveTokenIds(const std::vector<Id>&
|
||||
return g;
|
||||
}
|
||||
|
||||
std::vector<Id> Storage::getActiveTokenIdsForTokenIds(const std::vector<Id>& tokenIds) const
|
||||
{
|
||||
bool different = false;
|
||||
std::vector<Id> activeIds;
|
||||
|
||||
for (Id id : tokenIds)
|
||||
{
|
||||
if (m_sqliteStorage.isNode(id))
|
||||
{
|
||||
m_hierarchyCache.addFirstVisibleChildIdsForNodeId(id, &activeIds);
|
||||
if (id != activeIds.back())
|
||||
{
|
||||
different = true;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
activeIds.push_back(id);
|
||||
}
|
||||
}
|
||||
|
||||
if (!different)
|
||||
{
|
||||
return tokenIds;
|
||||
}
|
||||
|
||||
std::set<Id> idSet(activeIds.begin(), activeIds.end());
|
||||
activeIds.clear();
|
||||
activeIds.insert(activeIds.end(), idSet.begin(), idSet.end());
|
||||
|
||||
return activeIds;
|
||||
}
|
||||
|
||||
// TODO: rename: getActiveElementIdsForId; TODO: make separate function for declarationId
|
||||
std::vector<Id> Storage::getActiveTokenIdsForId(Id tokenId, Id* declarationId) const
|
||||
{
|
||||
@@ -815,7 +815,7 @@ void Storage::addEdgesToGraph(const std::vector<Id>& edgeIds, Graph* graph) cons
|
||||
}
|
||||
}
|
||||
|
||||
void Storage::addNodesAndEdgesToGraph(const std::vector<Id>& nodeIds, const std::vector<Id>& edgeIds, Graph* graph) const
|
||||
void Storage::addNodesWithChildrenAndEdgesToGraph(const std::vector<Id>& nodeIds, const std::vector<Id>& edgeIds, Graph* graph) const
|
||||
{
|
||||
std::set<Id> parentNodeIds;
|
||||
|
||||
@@ -908,7 +908,7 @@ void Storage::addAggregationEdgesToGraph(const Id nodeId, Graph* graph) const
|
||||
nodeIdsToAdd.push_back(aggregationTargetNodeId);
|
||||
}
|
||||
}
|
||||
addNodesAndEdgesToGraph(nodeIdsToAdd, std::vector<Id>(), graph);
|
||||
addNodesWithChildrenAndEdgesToGraph(nodeIdsToAdd, std::vector<Id>(), graph);
|
||||
|
||||
// create aggregation edges between parents and active node
|
||||
Node* sourceNode = graph->getNodeById(nodeId);
|
||||
|
||||
@@ -57,9 +57,8 @@ public:
|
||||
virtual std::vector<SearchMatch> getSearchMatchesForTokenIds(const std::vector<Id>& elementIds) const;
|
||||
|
||||
virtual std::shared_ptr<Graph> getGraphForAll() const;
|
||||
virtual std::shared_ptr<Graph> getGraphForActiveTokenIds(const std::vector<Id>& tokenIds, bool activeOnly) const;
|
||||
virtual std::shared_ptr<Graph> getGraphForActiveTokenIds(const std::vector<Id>& tokenIds) const;
|
||||
|
||||
virtual std::vector<Id> getActiveTokenIdsForTokenIds(const std::vector<Id>& tokenIds) const;
|
||||
virtual std::vector<Id> getActiveTokenIdsForId(Id tokenId, Id* declarationId) const;
|
||||
|
||||
virtual std::vector<Id> getNodeIdsForLocationIds(const std::vector<Id>& locationIds) const;
|
||||
@@ -93,7 +92,7 @@ private:
|
||||
|
||||
void addNodesToGraph(const std::vector<Id>& nodeIds, Graph* graph) const;
|
||||
void addEdgesToGraph(const std::vector<Id>& edgeIds, Graph* graph) const;
|
||||
void addNodesAndEdgesToGraph(const std::vector<Id>& nodeIds, const std::vector<Id>& edgeIds, Graph* graph) const;
|
||||
void addNodesWithChildrenAndEdgesToGraph(const std::vector<Id>& nodeIds, const std::vector<Id>& edgeIds, Graph* graph) const;
|
||||
|
||||
void addAggregationEdgesToGraph(const Id nodeId, Graph* graph) const;
|
||||
void addComponentAccessToGraph(Graph* graph) const;
|
||||
|
||||
@@ -39,9 +39,8 @@ public:
|
||||
virtual std::vector<SearchMatch> getSearchMatchesForTokenIds(const std::vector<Id>& tokenIds) const = 0;
|
||||
|
||||
virtual std::shared_ptr<Graph> getGraphForAll() const = 0;
|
||||
virtual std::shared_ptr<Graph> getGraphForActiveTokenIds(const std::vector<Id>& tokenIds, bool activeOnly) const = 0;
|
||||
virtual std::shared_ptr<Graph> getGraphForActiveTokenIds(const std::vector<Id>& tokenIds) const = 0;
|
||||
|
||||
virtual std::vector<Id> getActiveTokenIdsForTokenIds(const std::vector<Id>& tokenIds) const = 0;
|
||||
virtual std::vector<Id> getActiveTokenIdsForId(Id tokenId, Id* declarationId) const = 0;
|
||||
|
||||
virtual std::vector<Id> getNodeIdsForLocationIds(const std::vector<Id>& locationIds) const = 0;
|
||||
|
||||
@@ -113,26 +113,16 @@ std::shared_ptr<Graph> StorageAccessProxy::getGraphForAll() const
|
||||
return std::make_shared<Graph>();
|
||||
}
|
||||
|
||||
std::shared_ptr<Graph> StorageAccessProxy::getGraphForActiveTokenIds(const std::vector<Id>& tokenIds, bool activeOnly) const
|
||||
std::shared_ptr<Graph> StorageAccessProxy::getGraphForActiveTokenIds(const std::vector<Id>& tokenIds) const
|
||||
{
|
||||
if (hasSubject())
|
||||
{
|
||||
return m_subject->getGraphForActiveTokenIds(tokenIds, activeOnly);
|
||||
return m_subject->getGraphForActiveTokenIds(tokenIds);
|
||||
}
|
||||
|
||||
return std::make_shared<Graph>();
|
||||
}
|
||||
|
||||
std::vector<Id> StorageAccessProxy::getActiveTokenIdsForTokenIds(const std::vector<Id>& tokenIds) const
|
||||
{
|
||||
if (hasSubject())
|
||||
{
|
||||
return m_subject->getActiveTokenIdsForTokenIds(tokenIds);
|
||||
}
|
||||
|
||||
return std::vector<Id>();
|
||||
}
|
||||
|
||||
std::vector<Id> StorageAccessProxy::getActiveTokenIdsForId(Id tokenId, Id* delcarationId) const
|
||||
{
|
||||
if (hasSubject())
|
||||
|
||||
@@ -26,9 +26,8 @@ public:
|
||||
virtual std::vector<SearchMatch> getSearchMatchesForTokenIds(const std::vector<Id>& tokenIds) const;
|
||||
|
||||
virtual std::shared_ptr<Graph> getGraphForAll() const;
|
||||
virtual std::shared_ptr<Graph> getGraphForActiveTokenIds(const std::vector<Id>& tokenIds, bool activeOnly) const;
|
||||
virtual std::shared_ptr<Graph> getGraphForActiveTokenIds(const std::vector<Id>& tokenIds) const;
|
||||
|
||||
virtual std::vector<Id> getActiveTokenIdsForTokenIds(const std::vector<Id>& tokenIds) const;
|
||||
virtual std::vector<Id> getActiveTokenIdsForId(Id tokenId, Id* declarationId) const;
|
||||
|
||||
virtual std::vector<Id> getNodeIdsForLocationIds(const std::vector<Id>& locationIds) const;
|
||||
|
||||
@@ -34,7 +34,6 @@ public:
|
||||
}
|
||||
|
||||
const std::vector<Id> tokenIds;
|
||||
std::vector<Id> originalTokenIds;
|
||||
|
||||
bool isEdge;
|
||||
bool isAggregation;
|
||||
|
||||
@@ -105,7 +105,7 @@ bool QtGraphNode::setPosition(const Vec2i& position)
|
||||
Vec2i currentPosition = getPosition();
|
||||
Vec2i offset = position - currentPosition;
|
||||
|
||||
if (offset.getLength() > 0.0f)
|
||||
if (offset.x != 0 || offset.y != 0)
|
||||
{
|
||||
this->moveBy(offset.x, offset.y);
|
||||
notifyEdgesAfterMove();
|
||||
|
||||
Reference in New Issue
Block a user