diff --git a/lib/external/pattern_language b/lib/external/pattern_language index 3dff4201d..2578faba4 160000 --- a/lib/external/pattern_language +++ b/lib/external/pattern_language @@ -1 +1 @@ -Subproject commit 3dff4201d41efc7e0ebfdebc83d355bd6a5159c5 +Subproject commit 2578faba45e5361bf369297f2be22640e42bc07c diff --git a/plugins/ui/include/ui/pattern_drawer.hpp b/plugins/ui/include/ui/pattern_drawer.hpp index 3dc3e586f..63810e9cb 100644 --- a/plugins/ui/include/ui/pattern_drawer.hpp +++ b/plugins/ui/include/ui/pattern_drawer.hpp @@ -89,6 +89,8 @@ namespace hex::ui { void traversePatternTree(pl::ptrn::Pattern &pattern, std::vector &patternPath, const std::function &callback); [[nodiscard]] std::string getDisplayName(const pl::ptrn::Pattern& pattern) const; + [[nodiscard]] std::vector getPatternPath(const pl::ptrn::Pattern *pattern) const; + struct Filter { std::vector path; std::optional value; diff --git a/plugins/ui/source/ui/pattern_drawer.cpp b/plugins/ui/source/ui/pattern_drawer.cpp index 8a4f7551c..6ca26bd9f 100644 --- a/plugins/ui/source/ui/pattern_drawer.cpp +++ b/plugins/ui/source/ui/pattern_drawer.cpp @@ -396,6 +396,19 @@ namespace hex::ui { return pattern.getDisplayName(); } + [[nodiscard]] std::vector PatternDrawer::getPatternPath(const pl::ptrn::Pattern *pattern) const { + std::vector result; + + while (pattern != nullptr) { + result.emplace_back(pattern->getVariableName()); + pattern = pattern->getParent(); + } + + std::reverse(result.begin(), result.end()); + + return result; + } + bool PatternDrawer::createTreeNode(const pl::ptrn::Pattern& pattern, bool leaf) { ImGui::TableNextRow(); @@ -1367,33 +1380,33 @@ namespace hex::ui { m_filtersUpdated = true; if (!m_favoritesUpdateTask.isRunning()) { - m_favoritesUpdateTask = TaskManager::createTask("hex.ui.pattern_drawer.updating"_lang, TaskManager::NoProgress, [this, patterns](auto &task) { + m_favoritesUpdateTask = TaskManager::createTask("hex.ui.pattern_drawer.updating"_lang, TaskManager::NoProgress, [this, patterns, runtime](auto &task) { size_t updatedFavorites = 0; - const std::string favoriteAttribute = "hex::favorite"; - const std::string groupAttribute = "hex::group"; + { + const auto favorites = runtime->getPatternsWithAttribute("hex::favorite"); + for (const auto &pattern : favorites) { + m_favorites.insert({ getPatternPath(pattern), pattern->clone() }); + } + + const auto groupAttribute = "hex::group"; + const auto groups = runtime->getPatternsWithAttribute(groupAttribute); + for (const auto &pattern : groups) { + const auto arguments = pattern->getAttributeArguments(groupAttribute); + if (!arguments.empty()) { + const auto &groupName = arguments.front().toString(); + if (!m_groups.contains(groupName)) + m_groups.insert({ groupName, std::vector>() }); + + m_groups[groupName].push_back(pattern->clone()); + } + } + } + for (auto &pattern : patterns) { std::vector patternPath; size_t startFavoriteCount = m_favorites.size(); - traversePatternTree(*pattern, patternPath, [&, this](const pl::ptrn::Pattern &currPattern) { - if (currPattern.hasAttribute(favoriteAttribute)) - m_favorites.insert({ patternPath, currPattern.clone() }); - - if (const auto &args = currPattern.getAttributeArguments(groupAttribute); !args.empty()) { - auto groupName = args.front().toString(); - - if (!m_groups.contains(groupName)) - m_groups.insert({groupName, std::vector>()}); - - m_groups[groupName].push_back(currPattern.clone()); - } - - task.update(); - }); - - task.update(); - if (startFavoriteCount == m_favorites.size()) continue;