#include #include #include #include namespace hex::plugin::builtin { ViewPatternData::ViewPatternData() : View::Window("hex.builtin.view.pattern_data.name", ICON_VS_DATABASE) { m_patternDrawer = std::make_unique(); // Handle tree style setting changes EventSettingsChanged::subscribe(this, [this] { auto patternStyle = ContentRegistry::Settings::read("hex.builtin.setting.interface", "hex.builtin.setting.interface.pattern_tree_style", 0); m_patternDrawer->setTreeStyle(patternStyle); auto rowColoring = ContentRegistry::Settings::read("hex.builtin.setting.interface", "hex.builtin.setting.interface.pattern_data_row_bg", false); m_patternDrawer->enableRowColoring(rowColoring); }); // Reset the pattern drawer when the provider changes EventProviderChanged::subscribe(this, [this](auto, auto) { m_patternDrawer->reset(); }); EventPatternEvaluating::subscribe(this, [this]{ m_patternDrawer->reset(); }); EventPatternExecuted::subscribe(this, [this](auto){ m_patternDrawer->reset(); }); // Handle jumping to a pattern's location when it is clicked m_patternDrawer->setSelectionCallback([](Region region){ ImHexApi::HexEditor::setSelection(region); }); } ViewPatternData::~ViewPatternData() { EventSettingsChanged::unsubscribe(this); EventProviderChanged::unsubscribe(this); EventPatternEvaluating::unsubscribe(this); EventPatternExecuted::unsubscribe(this); } void ViewPatternData::drawContent() { // Draw the pattern tree if the provider is valid if (ImHexApi::Provider::isValid()) { // Make sure the runtime has finished evaluating and produced valid patterns auto &runtime = ContentRegistry::PatternLanguage::getRuntime(); const auto height = std::max(ImGui::GetContentRegionAvail().y - ImGui::GetTextLineHeightWithSpacing() - ImGui::GetStyle().FramePadding.y * 2, ImGui::GetTextLineHeightWithSpacing() * 5); if (!runtime.arePatternsValid()) { m_patternDrawer->draw({ }, nullptr, height); } else { // If the runtime has finished evaluating, draw the patterns if (TRY_LOCK(ContentRegistry::PatternLanguage::getRuntimeLock())) { m_patternDrawer->draw(runtime.getPatterns(), &runtime, height); } } } } }