ui/logic/data: refreshing only source files that have been updated

This change adds the refresh component that allows for refreshing the source code via UI or shortcut. If automatic
refreshing is activated via the UI, the code is refreshed anytime the window gets focus. The contents of all the
updated source files get removed from Storage, before reparsing them. File dependencies are not respected yet.
This commit is contained in:
Eberhard Graether
2015-02-03 14:27:39 +01:00
parent e17341fc43
commit 1690479b0e
52 changed files with 1145 additions and 92 deletions
+51
View File
@@ -3,6 +3,8 @@
#include <algorithm>
#include <cctype>
#include "utility/logging/logging.h"
#include "data/search/SearchMatch.h"
std::vector<SearchMatch> SearchIndex::getMatches(
@@ -34,6 +36,11 @@ void SearchIndex::clear()
m_root.m_nodes.clear();
}
size_t SearchIndex::getNodeCount() const
{
return m_root.getNodeCount() - 1;
}
Id SearchIndex::getWordId(const std::string& word)
{
return m_dictionary.getWordId(word);
@@ -71,6 +78,50 @@ SearchNode* SearchIndex::getNode(const std::string& fullName) const
return nullptr;
}
SearchNode* SearchIndex::getNode(const SearchNode* searchNode) const
{
std::deque<Id> nameIds = searchNode->getNameIdsRecursive();
if (nameIds.size())
{
return m_root.getNodeRecursive(&nameIds).get();
}
return nullptr;
}
void SearchIndex::removeNode(SearchNode* searchNode)
{
SearchNode* parent = searchNode->getParent();
if (!parent)
{
LOG_ERROR_STREAM(<< "SearchNode to be removed has no parent: " << searchNode->getFullName());
return;
}
parent->removeSearchNode(searchNode);
}
bool SearchIndex::removeNodeIfUnreferencedRecursive(SearchNode* searchNode)
{
if (!searchNode->hasTokenIdsRecursive())
{
SearchNode* parent = searchNode->getParent();
removeNode(searchNode);
if (parent && parent != &m_root)
{
removeNodeIfUnreferencedRecursive(parent);
}
return true;
}
return false;
}
SearchResults SearchIndex::runFuzzySearch(const std::string& query) const
{
return m_root.runFuzzySearch(query);
+6
View File
@@ -20,11 +20,17 @@ public:
void clear();
size_t getNodeCount() const;
Id getWordId(const std::string& word);
const std::string& getWord(Id wordId) const;
SearchNode* addNode(std::vector<std::string> nameHierarchy);
SearchNode* getNode(const std::string& fullName) const;
SearchNode* getNode(const SearchNode* searchNode) const;
void removeNode(SearchNode* searchNode);
bool removeNodeIfUnreferencedRecursive(SearchNode* searchNode);
SearchResults runFuzzySearch(const std::string& query) const;
std::vector<SearchMatch> runFuzzySearchAndGetMatches(const std::string& query) const;
+65 -2
View File
@@ -19,6 +19,18 @@ SearchNode::~SearchNode()
{
}
size_t SearchNode::getNodeCount() const
{
size_t count = 1;
for (std::shared_ptr<SearchNode> n: m_nodes)
{
count += n->getNodeCount();
}
return count;
}
const std::string& SearchNode::getName() const
{
return m_name;
@@ -28,7 +40,7 @@ std::vector<std::string> SearchNode::getNameHierarchy() const
{
std::vector<std::string> nameHierarchy;
const SearchNode* parent = getParent();
if (parent)
if (parent && parent->m_nameId)
{
nameHierarchy = parent->getNameHierarchy();
}
@@ -53,6 +65,22 @@ Id SearchNode::getNameId() const
return m_nameId;
}
std::deque<Id> SearchNode::getNameIdsRecursive() const
{
std::deque<Id> ids;
ids.push_front(m_nameId);
SearchNode* parent = m_parent;
while (parent && parent->m_nameId)
{
ids.push_front(parent->getNameId());
parent = parent->getParent();
}
return ids;
}
Id SearchNode::getFirstTokenId() const
{
if (m_tokenIds.size())
@@ -68,14 +96,37 @@ const std::set<Id>& SearchNode::getTokenIds() const
return m_tokenIds;
}
bool SearchNode::hasTokenIdsRecursive() const
{
if (m_tokenIds.size())
{
return true;
}
for (std::shared_ptr<SearchNode> n: m_nodes)
{
if (n->hasTokenIdsRecursive())
{
return true;
}
}
return false;
}
void SearchNode::addTokenId(Id tokenId)
{
m_tokenIds.insert(tokenId);
}
void SearchNode::removeTokenId(Id tokenId)
{
m_tokenIds.erase(tokenId);
}
SearchNode* SearchNode::getParent() const
{
if (m_parent && m_parent->m_nameId)
if (m_parent)
{
return m_parent;
}
@@ -183,6 +234,18 @@ std::shared_ptr<SearchNode> SearchNode::getNodeRecursive(std::deque<Id>* nameIds
return nullptr;
}
void SearchNode::removeSearchNode(SearchNode* node)
{
for (std::set<std::shared_ptr<SearchNode>>::iterator it = m_nodes.begin(); it != m_nodes.end(); it++)
{
if ((*it)->m_nameId == node->m_nameId)
{
m_nodes.erase(it);
return;
}
}
}
SearchMatch SearchNode::fuzzyMatchData(const std::string& query, const SearchNode* parent) const
{
SearchMatch data;
+8 -1
View File
@@ -22,15 +22,21 @@ public:
SearchNode(SearchNode* parent, const std::string& name, Id nameId);
~SearchNode();
size_t getNodeCount() const;
const std::string& getName() const;
std::vector<std::string> getNameHierarchy() const;
std::string getFullName() const;
Id getNameId() const;
std::deque<Id> getNameIdsRecursive() const;
Id getFirstTokenId() const;
const std::set<Id>& getTokenIds() const;
bool hasTokenIdsRecursive() const;
void addTokenId(Id tokenId);
void removeTokenId(Id tokenId);
SearchNode* getParent() const;
std::deque<SearchNode*> getParentsWithoutTokenId();
@@ -46,11 +52,12 @@ private:
typedef std::multimap<size_t, const SearchNode*> FuzzyMap;
typedef FuzzyMap::const_iterator FuzzyMapIterator;
// Accessed by SearchIndex
std::shared_ptr<SearchNode> addNodeRecursive(std::deque<Id>* nameIds, const Dictionary& dictionary);
std::shared_ptr<SearchNode> getNodeRecursive(std::deque<Id>* nameIds) const;
void removeSearchNode(SearchNode* node);
SearchMatch fuzzyMatchData(const std::string& query, const SearchNode* parent) const;
friend class SearchIndex;