diff --git a/bin/app/user/projects/tictactoe/src/player.h b/bin/app/user/projects/tictactoe/src/player.h index 2124fc59..700b3e5e 100644 --- a/bin/app/user/projects/tictactoe/src/player.h +++ b/bin/app/user/projects/tictactoe/src/player.h @@ -4,6 +4,7 @@ #include "field.h" #include "game_object.h" + class Player : public GameObject { public: Player( Field::Token token, const char* name ); diff --git a/src/lib/component/controller/ActivationController.cpp b/src/lib/component/controller/ActivationController.cpp index b3c0de69..dfd520b9 100644 --- a/src/lib/component/controller/ActivationController.cpp +++ b/src/lib/component/controller/ActivationController.cpp @@ -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> ret = + m_storageAccess->getNodeIdsAndSearchMatchesForNameHierarchies(message->getTokenNamesOfMatches()); + + m.tokenIds = ret.first; + m.searchMatches = ret.second; + } + m.dispatchImmediately(); } diff --git a/src/lib/component/controller/CodeController.cpp b/src/lib/component/controller/CodeController.cpp index bcd5c0b9..2d946690 100644 --- a/src/lib/component/controller/CodeController.cpp +++ b/src/lib/component/controller/CodeController.cpp @@ -190,9 +190,10 @@ void CodeController::handleMessage(MessageActivateTokens* message) std::wstring status = L""; - if (message->tokenNames.size()) + std::vector 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" "; diff --git a/src/lib/component/controller/SearchController.cpp b/src/lib/component/controller/SearchController.cpp index be8b822c..7723d882 100644 --- a/src/lib/component/controller/SearchController.cpp +++ b/src/lib/component/controller/SearchController.cpp @@ -49,23 +49,6 @@ void SearchController::handleMessage(MessageActivateTokens* message) { getView()->setMatches(m_storageAccess->getSearchMatchesForTokenIds(message->tokenIds)); } - else if (message->tokenNames.size()) - { - std::vector matches; - getView()->setMatches(matches); - - for (const NameHierarchy& name : message->tokenNames) - { - matches.push_back(SearchMatch(name.getQualifiedName())); - } - - if (!matches.size()) - { - matches.push_back(SearchMatch(L"")); - } - - getView()->setMatches(matches); - } } void SearchController::handleMessage(MessageFind* message) diff --git a/src/lib/component/controller/UndoRedoController.cpp b/src/lib/component/controller/UndoRedoController.cpp index bf4581b5..57239f4c 100644 --- a/src/lib/component/controller/UndoRedoController.cpp +++ b/src/lib/component/controller/UndoRedoController.cpp @@ -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(1, match)); - msg.dispatch(); + MessageSearch({ SearchMatch::createCommand(SearchMatch::COMMAND_ALL) }).dispatch(); } else { @@ -461,8 +459,11 @@ void UndoRedoController::replayCommand(std::list::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> ret = + m_storageAccess->getNodeIdsAndSearchMatchesForNameHierarchies(msg->getTokenNamesOfMatches()); + + msg->tokenIds = ret.first; + msg->searchMatches = ret.second; } } diff --git a/src/lib/data/access/StorageAccess.cpp b/src/lib/data/access/StorageAccess.cpp index 7e5df89d..b88fa852 100644 --- a/src/lib/data/access/StorageAccess.cpp +++ b/src/lib/data/access/StorageAccess.cpp @@ -1,5 +1,27 @@ #include "data/access/StorageAccess.h" -StorageAccess::~StorageAccess() +std::pair, std::vector> StorageAccess::getNodeIdsAndSearchMatchesForNameHierarchies( + const std::vector nameHierarchies) const { + std::vector tokenIds = getNodeIdsForNameHierarchies(nameHierarchies); + std::vector 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"")); + } + } + + return std::make_pair(tokenIds, matches); } diff --git a/src/lib/data/access/StorageAccess.h b/src/lib/data/access/StorageAccess.h index ec23ea13..10315202 100644 --- a/src/lib/data/access/StorageAccess.h +++ b/src/lib/data/access/StorageAccess.h @@ -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& tokenIds, TooltipOrigin origin) const = 0; virtual TooltipInfo getTooltipInfoForSourceLocationIdsAndLocalSymbolIds( const std::vector& locationIds, const std::vector& localSymbolIds) const = 0; + + std::pair, std::vector> getNodeIdsAndSearchMatchesForNameHierarchies( + const std::vector nameHierarchies) const; }; #endif // STORAGE_ACCESS_H diff --git a/src/lib/data/name/NameHierarchy.h b/src/lib/data/name/NameHierarchy.h index 8b3a3d76..ef8f0796 100644 --- a/src/lib/data/name/NameHierarchy.h +++ b/src/lib/data/name/NameHierarchy.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& names, const NameDelimiterType delimiter); NameHierarchy(const NameHierarchy& other); diff --git a/src/lib/data/search/SearchMatch.cpp b/src/lib/data/search/SearchMatch.cpp index 60287c63..dc7a7fd1 100644 --- a/src/lib/data/search/SearchMatch.cpp +++ b/src/lib/data/search/SearchMatch.cpp @@ -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) diff --git a/src/lib/data/search/SearchMatch.h b/src/lib/data/search/SearchMatch.h index a4284f4f..dd55289e 100644 --- a/src/lib/data/search/SearchMatch.h +++ b/src/lib/data/search/SearchMatch.h @@ -59,11 +59,13 @@ struct SearchMatch CommandType getCommandType() const; std::wstring name; - std::vector tokenIds; std::wstring text; std::wstring subtext; + std::vector tokenIds; + NameHierarchy tokenName; + NameDelimiterType delimiter; std::wstring typeName; diff --git a/src/lib/data/storage/PersistentStorage.cpp b/src/lib/data/storage/PersistentStorage.cpp index 56283cd4..2328c579 100644 --- a/src/lib/data/storage/PersistentStorage.cpp +++ b/src/lib/data/storage/PersistentStorage.cpp @@ -680,7 +680,7 @@ std::vector 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 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 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 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 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(); diff --git a/src/lib/utility/messaging/type/MessageActivateTokens.h b/src/lib/utility/messaging/type/MessageActivateTokens.h index 76824329..ce4b43d1 100644 --- a/src/lib/utility/messaging/type/MessageActivateTokens.h +++ b/src/lib/utility/messaging/type/MessageActivateTokens.h @@ -10,6 +10,11 @@ class MessageActivateTokens : public Message { 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 getTokenNamesOfMatches() const + { + std::vector tokenNames; + for (const SearchMatch& match : searchMatches) + { + tokenNames.push_back(match.tokenName); + } + return tokenNames; + } + std::vector tokenIds; - std::vector tokenNames; std::vector searchMatches; bool isEdge; diff --git a/src/lib/utility/messaging/type/MessageSearch.h b/src/lib/utility/messaging/type/MessageSearch.h index fbe4bcf4..6e3b84f3 100644 --- a/src/lib/utility/messaging/type/MessageSearch.h +++ b/src/lib/utility/messaging/type/MessageSearch.h @@ -10,43 +10,16 @@ class MessageSearch : public Message { public: - MessageSearch(const std::vector& 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& 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& getMatches() const @@ -70,9 +43,22 @@ public: return tokenIds; } + std::vector getTokenNamesOfMatches() const + { + std::vector 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; diff --git a/src/lib_gui/qt/element/QtHistoryList.cpp b/src/lib_gui/qt/element/QtHistoryList.cpp index 05f43809..1bb04c02 100644 --- a/src/lib_gui/qt/element/QtHistoryList.cpp +++ b/src/lib_gui/qt/element/QtHistoryList.cpp @@ -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); diff --git a/src/lib_gui/qt/element/QtSearchBar.cpp b/src/lib_gui/qt/element/QtSearchBar.cpp index e2a18a30..41339780 100644 --- a/src/lib_gui/qt/element/QtSearchBar.cpp +++ b/src/lib_gui/qt/element/QtSearchBar.cpp @@ -96,5 +96,5 @@ void QtSearchBar::refreshStyle() void QtSearchBar::homeButtonClicked() { - MessageSearch(std::vector(1, SearchMatch::createCommand(SearchMatch::COMMAND_ALL))).dispatch(); + MessageSearch({ SearchMatch::createCommand(SearchMatch::COMMAND_ALL) }).dispatch(); } diff --git a/src/lib_gui/qt/element/QtSmartSearchBox.cpp b/src/lib_gui/qt/element/QtSmartSearchBox.cpp index 14a541f3..43cf3658 100644 --- a/src/lib_gui/qt/element/QtSmartSearchBox.cpp +++ b/src/lib_gui/qt/element/QtSmartSearchBox.cpp @@ -66,9 +66,7 @@ void QtSmartSearchBox::search() } } - std::vector 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 diff --git a/src/lib_gui/qt/element/QtStatusBar.cpp b/src/lib_gui/qt/element/QtStatusBar.cpp index 146e3cae..8487c040 100644 --- a/src/lib_gui/qt/element/QtStatusBar.cpp +++ b/src/lib_gui/qt/element/QtStatusBar.cpp @@ -118,6 +118,5 @@ void QtStatusBar::showStatus() void QtStatusBar::showErrors() { - SearchMatch match = SearchMatch::createCommand(SearchMatch::COMMAND_ERROR); - MessageSearch(std::vector(1, match)).dispatch(); + MessageSearch({ SearchMatch::createCommand(SearchMatch::COMMAND_ERROR) }).dispatch(); } diff --git a/src/lib_gui/qt/window/QtMainWindow.cpp b/src/lib_gui/qt/window/QtMainWindow.cpp index 8e93c785..3d1acc6a 100644 --- a/src/lib_gui/qt/window/QtMainWindow.cpp +++ b/src/lib_gui/qt/window/QtMainWindow.cpp @@ -626,7 +626,7 @@ void QtMainWindow::codeReferenceNext() void QtMainWindow::overview() { - MessageSearch(std::vector(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(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));