ui: Fixed activating history item from menu showed wrong symbol (issue #572)
* Refactored SearchMatch: removed delimiter, added tokenName * Refactored MessageActivateTokens: removed tokenNames * Restore from SearchMatches from NameHierarchies of tokens
This commit is contained in:
@@ -4,6 +4,7 @@
|
||||
#include "field.h"
|
||||
#include "game_object.h"
|
||||
|
||||
|
||||
class Player : public GameObject {
|
||||
public:
|
||||
Player( Field::Token token, const char* name );
|
||||
|
||||
@@ -52,7 +52,6 @@ void ActivationController::handleMessage(MessageActivateFile* message)
|
||||
{
|
||||
MessageActivateTokens messageActivateTokens(message);
|
||||
messageActivateTokens.tokenIds.push_back(fileId);
|
||||
messageActivateTokens.tokenNames.push_back(NameHierarchy(message->filePath.wstr(), NAME_DELIMITER_FILE));
|
||||
messageActivateTokens.searchMatches = m_storageAccess->getSearchMatchesForTokenIds({ fileId });
|
||||
messageActivateTokens.dispatchImmediately();
|
||||
}
|
||||
@@ -80,21 +79,15 @@ void ActivationController::handleMessage(MessageActivateNodes* message)
|
||||
for (const MessageActivateNodes::ActiveNode& node : message->nodes)
|
||||
{
|
||||
Id nodeId = node.nodeId;
|
||||
NameHierarchy name = node.nameHierarchy;
|
||||
if (!nodeId)
|
||||
{
|
||||
nodeId = m_storageAccess->getNodeIdForNameHierarchy(name);
|
||||
}
|
||||
else if (!name.size())
|
||||
{
|
||||
name = m_storageAccess->getNameHierarchyForNodeId(nodeId);
|
||||
nodeId = m_storageAccess->getNodeIdForNameHierarchy(node.nameHierarchy);
|
||||
}
|
||||
|
||||
if (nodeId > 0)
|
||||
{
|
||||
m.tokenIds.push_back(nodeId);
|
||||
}
|
||||
m.tokenNames.push_back(name);
|
||||
}
|
||||
m.searchMatches = m_storageAccess->getSearchMatchesForTokenIds(m.tokenIds);
|
||||
m.dispatchImmediately();
|
||||
@@ -105,7 +98,6 @@ void ActivationController::handleMessage(MessageActivateTokenIds* message)
|
||||
MessageActivateTokens m(message);
|
||||
m.tokenIds = message->tokenIds;
|
||||
m.searchMatches = m_storageAccess->getSearchMatchesForTokenIds(message->tokenIds);
|
||||
m.tokenNames = m_storageAccess->getNameHierarchiesForNodeIds(m.tokenIds);
|
||||
m.dispatchImmediately();
|
||||
}
|
||||
|
||||
@@ -160,10 +152,22 @@ void ActivationController::handleMessage(MessageSearch* message)
|
||||
}
|
||||
|
||||
MessageActivateTokens m(message);
|
||||
m.tokenIds = message->getTokenIdsOfMatches();
|
||||
m.searchMatches = matches;
|
||||
m.tokenNames = m_storageAccess->getNameHierarchiesForNodeIds(m.tokenIds);
|
||||
m.isFromSearch = message->isFromSearch;
|
||||
|
||||
if (message->isFromSearch)
|
||||
{
|
||||
m.tokenIds = message->getTokenIdsOfMatches();
|
||||
m.searchMatches = matches;
|
||||
}
|
||||
else
|
||||
{
|
||||
std::pair<std::vector<Id>, std::vector<SearchMatch>> ret =
|
||||
m_storageAccess->getNodeIdsAndSearchMatchesForNameHierarchies(message->getTokenNamesOfMatches());
|
||||
|
||||
m.tokenIds = ret.first;
|
||||
m.searchMatches = ret.second;
|
||||
}
|
||||
|
||||
m.dispatchImmediately();
|
||||
}
|
||||
|
||||
|
||||
@@ -190,9 +190,10 @@ void CodeController::handleMessage(MessageActivateTokens* message)
|
||||
|
||||
std::wstring status = L"";
|
||||
|
||||
if (message->tokenNames.size())
|
||||
std::vector<NameHierarchy> tokenNames = message->getTokenNamesOfMatches();
|
||||
if (tokenNames.size())
|
||||
{
|
||||
status += L"Activate \"" + message->tokenNames[0].getQualifiedName() + L"\": ";
|
||||
status += L"Activate \"" + tokenNames[0].getQualifiedName() + L"\": ";
|
||||
}
|
||||
|
||||
status += std::to_wstring(message->tokenIds.size()) + L" ";
|
||||
|
||||
@@ -49,23 +49,6 @@ void SearchController::handleMessage(MessageActivateTokens* message)
|
||||
{
|
||||
getView()->setMatches(m_storageAccess->getSearchMatchesForTokenIds(message->tokenIds));
|
||||
}
|
||||
else if (message->tokenNames.size())
|
||||
{
|
||||
std::vector<SearchMatch> matches;
|
||||
getView()->setMatches(matches);
|
||||
|
||||
for (const NameHierarchy& name : message->tokenNames)
|
||||
{
|
||||
matches.push_back(SearchMatch(name.getQualifiedName()));
|
||||
}
|
||||
|
||||
if (!matches.size())
|
||||
{
|
||||
matches.push_back(SearchMatch(L"<invalid>"));
|
||||
}
|
||||
|
||||
getView()->setMatches(matches);
|
||||
}
|
||||
}
|
||||
|
||||
void SearchController::handleMessage(MessageFind* message)
|
||||
|
||||
@@ -235,9 +235,7 @@ void UndoRedoController::handleMessage(MessageRefresh* message)
|
||||
|
||||
if (m_iterator == m_list.begin())
|
||||
{
|
||||
SearchMatch match = SearchMatch::createCommand(SearchMatch::COMMAND_ALL);
|
||||
MessageSearch msg(std::vector<SearchMatch>(1, match));
|
||||
msg.dispatch();
|
||||
MessageSearch({ SearchMatch::createCommand(SearchMatch::COMMAND_ALL) }).dispatch();
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -461,8 +459,11 @@ void UndoRedoController::replayCommand(std::list<Command>::iterator it)
|
||||
|
||||
if (!msg->isEdge && !msg->isAggregation)
|
||||
{
|
||||
msg->tokenIds = m_storageAccess->getNodeIdsForNameHierarchies(msg->tokenNames);
|
||||
msg->searchMatches = m_storageAccess->getSearchMatchesForTokenIds(msg->tokenIds);
|
||||
std::pair<std::vector<Id>, std::vector<SearchMatch>> ret =
|
||||
m_storageAccess->getNodeIdsAndSearchMatchesForNameHierarchies(msg->getTokenNamesOfMatches());
|
||||
|
||||
msg->tokenIds = ret.first;
|
||||
msg->searchMatches = ret.second;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,27 @@
|
||||
#include "data/access/StorageAccess.h"
|
||||
|
||||
StorageAccess::~StorageAccess()
|
||||
std::pair<std::vector<Id>, std::vector<SearchMatch>> StorageAccess::getNodeIdsAndSearchMatchesForNameHierarchies(
|
||||
const std::vector<NameHierarchy> nameHierarchies) const
|
||||
{
|
||||
std::vector<Id> tokenIds = getNodeIdsForNameHierarchies(nameHierarchies);
|
||||
std::vector<SearchMatch> matches;
|
||||
|
||||
if (tokenIds.size())
|
||||
{
|
||||
matches = getSearchMatchesForTokenIds(tokenIds);
|
||||
}
|
||||
else
|
||||
{
|
||||
for (const NameHierarchy& name : nameHierarchies)
|
||||
{
|
||||
matches.push_back(SearchMatch(name.getQualifiedName()));
|
||||
}
|
||||
|
||||
if (!matches.size())
|
||||
{
|
||||
matches.push_back(SearchMatch(L"<invalid>"));
|
||||
}
|
||||
}
|
||||
|
||||
return std::make_pair(tokenIds, matches);
|
||||
}
|
||||
|
||||
@@ -33,7 +33,7 @@ struct FileInfo;
|
||||
class StorageAccess
|
||||
{
|
||||
public:
|
||||
virtual ~StorageAccess();
|
||||
virtual ~StorageAccess() = default;
|
||||
|
||||
virtual Id getNodeIdForFileNode(const FilePath& filePath) const = 0;
|
||||
virtual Id getNodeIdForNameHierarchy(const NameHierarchy& nameHierarchy) const = 0;
|
||||
@@ -110,6 +110,9 @@ public:
|
||||
virtual TooltipInfo getTooltipInfoForTokenIds(const std::vector<Id>& tokenIds, TooltipOrigin origin) const = 0;
|
||||
virtual TooltipInfo getTooltipInfoForSourceLocationIdsAndLocalSymbolIds(
|
||||
const std::vector<Id>& locationIds, const std::vector<Id>& localSymbolIds) const = 0;
|
||||
|
||||
std::pair<std::vector<Id>, std::vector<SearchMatch>> getNodeIdsAndSearchMatchesForNameHierarchies(
|
||||
const std::vector<NameHierarchy> nameHierarchies) const;
|
||||
};
|
||||
|
||||
#endif // STORAGE_ACCESS_H
|
||||
|
||||
@@ -14,7 +14,7 @@ public:
|
||||
static std::wstring serialize(const NameHierarchy& nameHierarchy);
|
||||
static NameHierarchy deserialize(const std::wstring& serializedName);
|
||||
|
||||
NameHierarchy(const NameDelimiterType delimiter);
|
||||
NameHierarchy(const NameDelimiterType delimiter = NAME_DELIMITER_UNKNOWN);
|
||||
NameHierarchy(const std::wstring& name, const NameDelimiterType delimiter);
|
||||
NameHierarchy(const std::vector<std::wstring>& names, const NameDelimiterType delimiter);
|
||||
NameHierarchy(const NameHierarchy& other);
|
||||
|
||||
@@ -101,6 +101,7 @@ SearchMatch::SearchMatch()
|
||||
SearchMatch::SearchMatch(const std::wstring& query)
|
||||
: name(query)
|
||||
, text(query)
|
||||
, tokenName(query, NAME_DELIMITER_UNKNOWN)
|
||||
, typeName(L"")
|
||||
, nodeType(NodeType::NODE_SYMBOL)
|
||||
, searchType(SEARCH_NONE)
|
||||
|
||||
@@ -59,11 +59,13 @@ struct SearchMatch
|
||||
CommandType getCommandType() const;
|
||||
|
||||
std::wstring name;
|
||||
std::vector<Id> tokenIds;
|
||||
|
||||
std::wstring text;
|
||||
std::wstring subtext;
|
||||
|
||||
std::vector<Id> tokenIds;
|
||||
NameHierarchy tokenName;
|
||||
|
||||
NameDelimiterType delimiter;
|
||||
|
||||
std::wstring typeName;
|
||||
|
||||
@@ -680,7 +680,7 @@ std::vector<SearchMatch> PersistentStorage::getAutocompletionMatches(const std::
|
||||
}
|
||||
else if (lastMatch.score == match.score)
|
||||
{
|
||||
if (utility::isPrefix(nameDelimiterTypeToString(match.delimiter), match.name.substr(lastMatch.name.size())))
|
||||
if (utility::isPrefix(nameDelimiterTypeToString(match.tokenName.getDelimiter()), match.name.substr(lastMatch.name.size())))
|
||||
{
|
||||
match.score -= 10;
|
||||
}
|
||||
@@ -766,8 +766,7 @@ std::vector<SearchMatch> PersistentStorage::getAutocompletionSymbolMatches(
|
||||
match.subtext = name.getRange(0, idx).getQualifiedName();
|
||||
}
|
||||
|
||||
match.delimiter = name.getDelimiter();
|
||||
|
||||
match.tokenName = name;
|
||||
match.indices = result.indices;
|
||||
match.score = result.score;
|
||||
match.nodeType = utility::intToType(firstNode->type);
|
||||
@@ -801,13 +800,19 @@ std::vector<SearchMatch> PersistentStorage::getAutocompletionFileMatches(const s
|
||||
SearchMatch match;
|
||||
|
||||
match.name = result.text;
|
||||
|
||||
match.text = FilePath(match.name).fileName();
|
||||
match.subtext = match.name;
|
||||
|
||||
match.tokenIds = utility::toVector(result.elementIds);
|
||||
|
||||
const FilePath path(match.name);
|
||||
match.text = path.fileName();
|
||||
match.subtext = path.wstr();
|
||||
|
||||
match.delimiter = NAME_DELIMITER_FILE;
|
||||
if (match.tokenIds.size())
|
||||
{
|
||||
match.tokenName = NameHierarchy(getFileNodePath(match.tokenIds[0]).wstr(), NAME_DELIMITER_FILE);
|
||||
}
|
||||
else
|
||||
{
|
||||
match.tokenName = NameHierarchy(match.name, NAME_DELIMITER_FILE);
|
||||
}
|
||||
|
||||
match.indices = result.indices;
|
||||
match.score = result.score;
|
||||
@@ -838,8 +843,6 @@ std::vector<SearchMatch> PersistentStorage::getAutocompletionCommandMatches(
|
||||
match.name = result.text;
|
||||
match.text = result.text;
|
||||
|
||||
match.delimiter = NAME_DELIMITER_UNKNOWN;
|
||||
|
||||
match.indices = result.indices;
|
||||
match.score = result.score;
|
||||
|
||||
@@ -892,11 +895,10 @@ std::vector<SearchMatch> PersistentStorage::getSearchMatchesForTokenIds(const st
|
||||
match.text = nameHierarchy.getRawName();
|
||||
|
||||
match.tokenIds.push_back(elementId);
|
||||
match.tokenName = nameHierarchy;
|
||||
match.nodeType = utility::intToType(node.type);
|
||||
match.searchType = SearchMatch::SEARCH_TOKEN;
|
||||
|
||||
match.delimiter = nameHierarchy.getDelimiter();
|
||||
|
||||
if (match.nodeType.isFile())
|
||||
{
|
||||
match.text = FilePath(match.text).fileName();
|
||||
|
||||
@@ -10,6 +10,11 @@ class MessageActivateTokens
|
||||
: public Message<MessageActivateTokens>
|
||||
{
|
||||
public:
|
||||
static const std::string getStaticType()
|
||||
{
|
||||
return "MessageActivateTokens";
|
||||
}
|
||||
|
||||
MessageActivateTokens(const MessageBase* other)
|
||||
: isEdge(false)
|
||||
, isAggregation(false)
|
||||
@@ -19,11 +24,6 @@ public:
|
||||
setKeepContent(other->keepContent());
|
||||
}
|
||||
|
||||
static const std::string getStaticType()
|
||||
{
|
||||
return "MessageActivateTokens";
|
||||
}
|
||||
|
||||
virtual void print(std::wostream& os) const
|
||||
{
|
||||
for (const Id& id : tokenIds)
|
||||
@@ -32,8 +32,17 @@ public:
|
||||
}
|
||||
}
|
||||
|
||||
std::vector<NameHierarchy> getTokenNamesOfMatches() const
|
||||
{
|
||||
std::vector<NameHierarchy> tokenNames;
|
||||
for (const SearchMatch& match : searchMatches)
|
||||
{
|
||||
tokenNames.push_back(match.tokenName);
|
||||
}
|
||||
return tokenNames;
|
||||
}
|
||||
|
||||
std::vector<Id> tokenIds;
|
||||
std::vector<NameHierarchy> tokenNames;
|
||||
std::vector<SearchMatch> searchMatches;
|
||||
|
||||
bool isEdge;
|
||||
|
||||
@@ -10,43 +10,16 @@ class MessageSearch
|
||||
: public Message<MessageSearch>
|
||||
{
|
||||
public:
|
||||
MessageSearch(const std::vector<SearchMatch>& matches, NodeTypeSet acceptedNodeTypes = NodeTypeSet::all())
|
||||
: isFromSearch(true)
|
||||
, acceptedNodeTypes(acceptedNodeTypes)
|
||||
, m_matches(matches)
|
||||
{
|
||||
}
|
||||
|
||||
static const std::string getStaticType()
|
||||
{
|
||||
return "MessageSearch";
|
||||
}
|
||||
|
||||
std::wstring getMatchesAsString() const
|
||||
MessageSearch(const std::vector<SearchMatch>& matches, NodeTypeSet acceptedNodeTypes = NodeTypeSet::all())
|
||||
: isFromSearch(true)
|
||||
, acceptedNodeTypes(acceptedNodeTypes)
|
||||
, m_matches(matches)
|
||||
{
|
||||
std::wstringstream ss;
|
||||
|
||||
for (size_t i = 0; i < m_matches.size(); i++)
|
||||
{
|
||||
ss << '@';
|
||||
if (m_matches[i].nodeType.isFile())
|
||||
{
|
||||
ss << m_matches[i].subtext;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!m_matches[i].subtext.empty())
|
||||
{
|
||||
ss << m_matches[i].subtext << nameDelimiterTypeToString(m_matches[i].delimiter) << m_matches[i].text;
|
||||
}
|
||||
else
|
||||
{
|
||||
ss << m_matches[i].name;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return ss.str();
|
||||
}
|
||||
|
||||
const std::vector<SearchMatch>& getMatches() const
|
||||
@@ -70,9 +43,22 @@ public:
|
||||
return tokenIds;
|
||||
}
|
||||
|
||||
std::vector<NameHierarchy> getTokenNamesOfMatches() const
|
||||
{
|
||||
std::vector<NameHierarchy> tokenNames;
|
||||
for (const SearchMatch& match : m_matches)
|
||||
{
|
||||
tokenNames.push_back(match.tokenName);
|
||||
}
|
||||
return tokenNames;
|
||||
}
|
||||
|
||||
virtual void print(std::wostream& os) const
|
||||
{
|
||||
os << getMatchesAsString();
|
||||
for (const SearchMatch& match : m_matches)
|
||||
{
|
||||
os << " @" << match.name << "-" << match.tokenName.getQualifiedName();
|
||||
}
|
||||
}
|
||||
|
||||
bool isFromSearch;
|
||||
|
||||
@@ -23,7 +23,7 @@ QtHistoryItem::QtHistoryItem(const SearchMatch& match, size_t index, bool isCurr
|
||||
layout->setContentsMargins(0, 0, 0, 0);
|
||||
layout->setAlignment(Qt::AlignTop);
|
||||
|
||||
const std::wstring name = utility::elide(match.nodeType.isFile() ? match.text : match.name, utility::ELIDE_RIGHT, 100);
|
||||
const std::wstring name = utility::elide(match.getFullName(), utility::ELIDE_RIGHT, 100);
|
||||
|
||||
m_name = new QLabel(QString::fromStdWString(name), this);
|
||||
m_name->setAttribute(Qt::WA_MacShowFocusRect, 0);
|
||||
|
||||
@@ -96,5 +96,5 @@ void QtSearchBar::refreshStyle()
|
||||
|
||||
void QtSearchBar::homeButtonClicked()
|
||||
{
|
||||
MessageSearch(std::vector<SearchMatch>(1, SearchMatch::createCommand(SearchMatch::COMMAND_ALL))).dispatch();
|
||||
MessageSearch({ SearchMatch::createCommand(SearchMatch::COMMAND_ALL) }).dispatch();
|
||||
}
|
||||
|
||||
@@ -66,9 +66,7 @@ void QtSmartSearchBox::search()
|
||||
}
|
||||
}
|
||||
|
||||
std::vector<SearchMatch> matches = utility::toVector(m_matches);
|
||||
|
||||
MessageSearch(matches, getMatchAcceptedNodeTypes()).dispatch();
|
||||
MessageSearch(utility::toVector(m_matches), getMatchAcceptedNodeTypes()).dispatch();
|
||||
}
|
||||
|
||||
void QtSmartSearchBox::fullTextSearch()
|
||||
@@ -194,7 +192,8 @@ bool QtSmartSearchBox::event(QEvent *event)
|
||||
}
|
||||
else if (m_highlightedMatch.hasChildren)
|
||||
{
|
||||
setEditText(QString::fromStdWString(m_highlightedMatch.getFullName() + nameDelimiterTypeToString(m_highlightedMatch.delimiter)));
|
||||
setEditText(QString::fromStdWString(
|
||||
m_highlightedMatch.getFullName() + nameDelimiterTypeToString(m_highlightedMatch.tokenName.getDelimiter())));
|
||||
requestAutoCompletions();
|
||||
}
|
||||
else
|
||||
|
||||
@@ -118,6 +118,5 @@ void QtStatusBar::showStatus()
|
||||
|
||||
void QtStatusBar::showErrors()
|
||||
{
|
||||
SearchMatch match = SearchMatch::createCommand(SearchMatch::COMMAND_ERROR);
|
||||
MessageSearch(std::vector<SearchMatch>(1, match)).dispatch();
|
||||
MessageSearch({ SearchMatch::createCommand(SearchMatch::COMMAND_ERROR) }).dispatch();
|
||||
}
|
||||
|
||||
@@ -626,7 +626,7 @@ void QtMainWindow::codeReferenceNext()
|
||||
|
||||
void QtMainWindow::overview()
|
||||
{
|
||||
MessageSearch(std::vector<SearchMatch>(1, SearchMatch::createCommand(SearchMatch::COMMAND_ALL))).dispatch();
|
||||
MessageSearch({ SearchMatch::createCommand(SearchMatch::COMMAND_ALL) }).dispatch();
|
||||
}
|
||||
|
||||
void QtMainWindow::closeWindow()
|
||||
@@ -755,9 +755,7 @@ void QtMainWindow::openHistoryAction()
|
||||
QAction* action = qobject_cast<QAction*>(sender());
|
||||
if (action)
|
||||
{
|
||||
SearchMatch& match = m_history[action->data().toInt()];
|
||||
|
||||
MessageSearch msg({ match });
|
||||
MessageSearch msg({ m_history[action->data().toInt()] });
|
||||
msg.isFromSearch = false;
|
||||
msg.dispatch();
|
||||
}
|
||||
@@ -889,7 +887,7 @@ void QtMainWindow::setupHistoryMenu()
|
||||
for (size_t i = 0; i < m_history.size(); i++)
|
||||
{
|
||||
SearchMatch& match = m_history[i];
|
||||
const std::wstring name = utility::elide(match.nodeType.isFile() ? match.text : match.name, utility::ELIDE_RIGHT, 50);
|
||||
const std::wstring name = utility::elide(match.getFullName(), utility::ELIDE_RIGHT, 50);
|
||||
|
||||
QAction* action = new QAction();
|
||||
action->setText(QString::fromStdWString(name));
|
||||
|
||||
Reference in New Issue
Block a user