From 26de4c11e13e28ead1bddeee5e2204b2f251a6ec Mon Sep 17 00:00:00 2001 From: WerWolv Date: Sat, 12 Jul 2025 22:05:13 +0200 Subject: [PATCH] impr: Move pattern sections from pattern editor view to pattern data view --- .../content/views/view_pattern_data.hpp | 2 +- .../content/views/view_pattern_editor.hpp | 6 - plugins/builtin/romfs/lang/de_DE.json | 2 - plugins/builtin/romfs/lang/en_US.json | 6 +- plugins/builtin/romfs/lang/es_ES.json | 2 - plugins/builtin/romfs/lang/fr_FR.json | 4 - plugins/builtin/romfs/lang/hu_HU.json | 4 - plugins/builtin/romfs/lang/it_IT.json | 2 - plugins/builtin/romfs/lang/ja_JP.json | 2 - plugins/builtin/romfs/lang/ko_KR.json | 2 - plugins/builtin/romfs/lang/pl_PL.json | 4 - plugins/builtin/romfs/lang/pt_BR.json | 2 - plugins/builtin/romfs/lang/ru_RU.json | 4 - plugins/builtin/romfs/lang/zh_CN.json | 4 - plugins/builtin/romfs/lang/zh_TW.json | 2 - .../content/views/view_pattern_data.cpp | 128 +++++++++++++----- .../content/views/view_pattern_editor.cpp | 122 ----------------- 17 files changed, 95 insertions(+), 203 deletions(-) diff --git a/plugins/builtin/include/content/views/view_pattern_data.hpp b/plugins/builtin/include/content/views/view_pattern_data.hpp index 33dfae68c..b8eb0cf7e 100644 --- a/plugins/builtin/include/content/views/view_pattern_data.hpp +++ b/plugins/builtin/include/content/views/view_pattern_data.hpp @@ -18,7 +18,7 @@ namespace hex::plugin::builtin { u32 m_maxFilterItems = 128; ui::PatternDrawer::TreeStyle m_treeStyle = ui::PatternDrawer::TreeStyle::Default; - PerProvider> m_patternDrawer; + PerProvider>> m_patternDrawer; Region m_hoveredPatternRegion = Region::Invalid(); }; diff --git a/plugins/builtin/include/content/views/view_pattern_editor.hpp b/plugins/builtin/include/content/views/view_pattern_editor.hpp index 7429b7ba3..80e26244b 100644 --- a/plugins/builtin/include/content/views/view_pattern_editor.hpp +++ b/plugins/builtin/include/content/views/view_pattern_editor.hpp @@ -30,7 +30,6 @@ namespace hex::plugin::builtin { constexpr static auto consoleView = "/##console_"; constexpr static auto variablesView = "/##env_vars_"; constexpr static auto settingsView = "/##settings_"; - constexpr static auto sectionsView = "/##sections_table_"; constexpr static auto virtualFilesView = "/##Virtual_File_Tree_"; constexpr static auto debuggerView = "/##debugger_"; @@ -271,9 +270,6 @@ namespace hex::plugin::builtin { bool m_autoLoadPatterns = true; - std::map> m_sectionWindowDrawer; - - ui::HexEditor m_sectionHexEditor; PerProvider m_visualizerDrawer; bool m_tooltipJustOpened = false; @@ -297,7 +293,6 @@ namespace hex::plugin::builtin { PerProvider*> m_callStack; PerProvider> m_lastEvaluationOutVars; PerProvider> m_patternVariables; - PerProvider> m_sections; PerProvider> m_virtualFiles; @@ -339,7 +334,6 @@ namespace hex::plugin::builtin { void drawConsole(ImVec2 size); void drawEnvVars(ImVec2 size, std::list &envVars); void drawVariableSettings(ImVec2 size, std::map &patternVariables); - void drawSectionSelector(ImVec2 size, const std::map §ions); void drawVirtualFiles(ImVec2 size, const std::vector &virtualFiles) const; void drawDebugger(ImVec2 size); diff --git a/plugins/builtin/romfs/lang/de_DE.json b/plugins/builtin/romfs/lang/de_DE.json index d3fc5c1a0..760b33af4 100644 --- a/plugins/builtin/romfs/lang/de_DE.json +++ b/plugins/builtin/romfs/lang/de_DE.json @@ -903,8 +903,6 @@ "hex.builtin.view.pattern_editor.open_pattern": "Pattern öffnen", "hex.builtin.view.pattern_editor.replace_hint": "Ersetzen", "hex.builtin.view.pattern_editor.replace_hint_history": " für Historie)", - "hex.builtin.view.pattern_editor.section_popup": "Sektion", - "hex.builtin.view.pattern_editor.sections": "Sektionen", "hex.builtin.view.pattern_editor.settings": "Einstellungen", "hex.builtin.view.pattern_editor.shortcut.add_breakpoint": "Breakpoint hinzufügen", "hex.builtin.view.pattern_editor.shortcut.continue_debugger": "Debugger fortsetzen", diff --git a/plugins/builtin/romfs/lang/en_US.json b/plugins/builtin/romfs/lang/en_US.json index 1fdb0460e..170eee354 100644 --- a/plugins/builtin/romfs/lang/en_US.json +++ b/plugins/builtin/romfs/lang/en_US.json @@ -943,6 +943,8 @@ "hex.builtin.view.patches.patch": "Description", "hex.builtin.view.patches.remove": "Remove patch", "hex.builtin.view.pattern_data.name": "Pattern Data", + "hex.builtin.view.pattern_data.section.main": "Main", + "hex.builtin.view.pattern_data.section.view_raw": "View Raw Data", "hex.builtin.view.pattern_editor.accept_pattern": "Accept pattern", "hex.builtin.view.pattern_editor.accept_pattern.desc": "One or more Patterns compatible with this data type has been found", "hex.builtin.view.pattern_editor.accept_pattern.pattern_language": "Patterns", @@ -989,10 +991,6 @@ "hex.builtin.view.pattern_editor.open_pattern": "Open pattern", "hex.builtin.view.pattern_editor.replace_hint": "Replace", "hex.builtin.view.pattern_editor.replace_hint_history": " for history)", - "hex.builtin.view.pattern_editor.section_popup": "Section", - "hex.builtin.view.pattern_editor.sections": "Sections", - "hex.builtin.view.pattern_editor.sections.view": "View content", - "hex.builtin.view.pattern_editor.sections.export": "Export content", "hex.builtin.view.pattern_editor.settings": "Settings", "hex.builtin.view.pattern_editor.shortcut.goto_line": "Go to line ...", "hex.builtin.view.pattern_editor.shortcut.find": "Search ...", diff --git a/plugins/builtin/romfs/lang/es_ES.json b/plugins/builtin/romfs/lang/es_ES.json index 58bd6978b..0211c07f8 100644 --- a/plugins/builtin/romfs/lang/es_ES.json +++ b/plugins/builtin/romfs/lang/es_ES.json @@ -897,8 +897,6 @@ "hex.builtin.view.pattern_editor.open_pattern": "Abrir pattern", "hex.builtin.view.pattern_editor.replace_hint": "", "hex.builtin.view.pattern_editor.replace_hint_history": "", - "hex.builtin.view.pattern_editor.section_popup": "Sección", - "hex.builtin.view.pattern_editor.sections": "Secciones", "hex.builtin.view.pattern_editor.settings": "Ajustes", "hex.builtin.view.pattern_editor.shortcut.add_breakpoint": "", "hex.builtin.view.pattern_editor.shortcut.continue_debugger": "", diff --git a/plugins/builtin/romfs/lang/fr_FR.json b/plugins/builtin/romfs/lang/fr_FR.json index e07919515..7981d8245 100644 --- a/plugins/builtin/romfs/lang/fr_FR.json +++ b/plugins/builtin/romfs/lang/fr_FR.json @@ -982,10 +982,6 @@ "hex.builtin.view.pattern_editor.open_pattern": "Ouvrir le modèle", "hex.builtin.view.pattern_editor.replace_hint": "Remplacer", "hex.builtin.view.pattern_editor.replace_hint_history": " pour l'historique)", - "hex.builtin.view.pattern_editor.section_popup": "Section", - "hex.builtin.view.pattern_editor.sections": "Sections", - "hex.builtin.view.pattern_editor.sections.view": "Afficher le contenu", - "hex.builtin.view.pattern_editor.sections.export": "Exporter le contenu", "hex.builtin.view.pattern_editor.settings": "Paramètres", "hex.builtin.view.pattern_editor.shortcut.goto_line": "Aller à la ligne...", "hex.builtin.view.pattern_editor.shortcut.find": "Rechercher...", diff --git a/plugins/builtin/romfs/lang/hu_HU.json b/plugins/builtin/romfs/lang/hu_HU.json index 45ca872e5..9f01b4ccd 100644 --- a/plugins/builtin/romfs/lang/hu_HU.json +++ b/plugins/builtin/romfs/lang/hu_HU.json @@ -905,10 +905,6 @@ "hex.builtin.view.pattern_editor.open_pattern": "Sablon megnyitása", "hex.builtin.view.pattern_editor.replace_hint": "Csere", "hex.builtin.view.pattern_editor.replace_hint_history": " előzményekhez)", - "hex.builtin.view.pattern_editor.section_popup": "Szekció", - "hex.builtin.view.pattern_editor.sections": "Szekciók", - "hex.builtin.view.pattern_editor.sections.view": "Tartalom megtekintése", - "hex.builtin.view.pattern_editor.sections.export": "Tartalom exportálása", "hex.builtin.view.pattern_editor.settings": "Beállítások", "hex.builtin.view.pattern_editor.shortcut.run_pattern": "Sablon futtatása", "hex.builtin.view.pattern_editor.shortcut.step_debugger": "Debugger léptetése", diff --git a/plugins/builtin/romfs/lang/it_IT.json b/plugins/builtin/romfs/lang/it_IT.json index dad096f66..32a51d660 100644 --- a/plugins/builtin/romfs/lang/it_IT.json +++ b/plugins/builtin/romfs/lang/it_IT.json @@ -898,8 +898,6 @@ "hex.builtin.view.pattern_editor.open_pattern": "Apri pattern", "hex.builtin.view.pattern_editor.replace_hint": "", "hex.builtin.view.pattern_editor.replace_hint_history": "", - "hex.builtin.view.pattern_editor.section_popup": "", - "hex.builtin.view.pattern_editor.sections": "", "hex.builtin.view.pattern_editor.settings": "Impostazioni", "hex.builtin.view.pattern_editor.shortcut.add_breakpoint": "", "hex.builtin.view.pattern_editor.shortcut.continue_debugger": "", diff --git a/plugins/builtin/romfs/lang/ja_JP.json b/plugins/builtin/romfs/lang/ja_JP.json index 325c959ac..82e8adc0f 100644 --- a/plugins/builtin/romfs/lang/ja_JP.json +++ b/plugins/builtin/romfs/lang/ja_JP.json @@ -898,8 +898,6 @@ "hex.builtin.view.pattern_editor.open_pattern": "パターンを開く", "hex.builtin.view.pattern_editor.replace_hint": "", "hex.builtin.view.pattern_editor.replace_hint_history": "", - "hex.builtin.view.pattern_editor.section_popup": "", - "hex.builtin.view.pattern_editor.sections": "", "hex.builtin.view.pattern_editor.settings": "設定", "hex.builtin.view.pattern_editor.shortcut.add_breakpoint": "", "hex.builtin.view.pattern_editor.shortcut.continue_debugger": "", diff --git a/plugins/builtin/romfs/lang/ko_KR.json b/plugins/builtin/romfs/lang/ko_KR.json index c356de9fd..0b033fd2e 100644 --- a/plugins/builtin/romfs/lang/ko_KR.json +++ b/plugins/builtin/romfs/lang/ko_KR.json @@ -898,8 +898,6 @@ "hex.builtin.view.pattern_editor.open_pattern": "패턴 열기", "hex.builtin.view.pattern_editor.replace_hint": "", "hex.builtin.view.pattern_editor.replace_hint_history": "", - "hex.builtin.view.pattern_editor.section_popup": "섹션", - "hex.builtin.view.pattern_editor.sections": "섹션", "hex.builtin.view.pattern_editor.settings": "설정", "hex.builtin.view.pattern_editor.shortcut.add_breakpoint": "중단점 추가", "hex.builtin.view.pattern_editor.shortcut.continue_debugger": "컨티뉴 디버거", diff --git a/plugins/builtin/romfs/lang/pl_PL.json b/plugins/builtin/romfs/lang/pl_PL.json index b68c56064..fb5182404 100644 --- a/plugins/builtin/romfs/lang/pl_PL.json +++ b/plugins/builtin/romfs/lang/pl_PL.json @@ -1002,10 +1002,6 @@ "hex.builtin.view.pattern_editor.open_pattern": "Otwórz wzorzec", "hex.builtin.view.pattern_editor.replace_hint": "Zamień", "hex.builtin.view.pattern_editor.replace_hint_history": " dla historii)", - "hex.builtin.view.pattern_editor.section_popup": "Sekcja", - "hex.builtin.view.pattern_editor.sections": "Sekcje", - "hex.builtin.view.pattern_editor.sections.export": "Eksportuj zawartość", - "hex.builtin.view.pattern_editor.sections.view": "Wyświetl zawartość", "hex.builtin.view.pattern_editor.settings": "Ustawienia", "hex.builtin.view.pattern_editor.shortcut.add_breakpoint": "Dodaj punkt przerwania", "hex.builtin.view.pattern_editor.shortcut.backspace": "Usuń jeden znak na lewo od kursora", diff --git a/plugins/builtin/romfs/lang/pt_BR.json b/plugins/builtin/romfs/lang/pt_BR.json index 0131866fc..0ee90dce0 100644 --- a/plugins/builtin/romfs/lang/pt_BR.json +++ b/plugins/builtin/romfs/lang/pt_BR.json @@ -898,8 +898,6 @@ "hex.builtin.view.pattern_editor.open_pattern": "Abrir padrão", "hex.builtin.view.pattern_editor.replace_hint": "", "hex.builtin.view.pattern_editor.replace_hint_history": "", - "hex.builtin.view.pattern_editor.section_popup": "", - "hex.builtin.view.pattern_editor.sections": "", "hex.builtin.view.pattern_editor.settings": "Configurações", "hex.builtin.view.pattern_editor.shortcut.add_breakpoint": "", "hex.builtin.view.pattern_editor.shortcut.continue_debugger": "", diff --git a/plugins/builtin/romfs/lang/ru_RU.json b/plugins/builtin/romfs/lang/ru_RU.json index 08702cd62..1a8867b1b 100644 --- a/plugins/builtin/romfs/lang/ru_RU.json +++ b/plugins/builtin/romfs/lang/ru_RU.json @@ -954,10 +954,6 @@ "hex.builtin.view.pattern_editor.open_pattern": "Открыть шаблон", "hex.builtin.view.pattern_editor.replace_hint": "Заменить", "hex.builtin.view.pattern_editor.replace_hint_history": " для истории)", - "hex.builtin.view.pattern_editor.section_popup": "Секция", - "hex.builtin.view.pattern_editor.sections": "Секции", - "hex.builtin.view.pattern_editor.sections.view": "Просмотреть содержимое", - "hex.builtin.view.pattern_editor.sections.export": "Экспортировать содержимое", "hex.builtin.view.pattern_editor.settings": "Настройки", "hex.builtin.view.pattern_editor.shortcut.find": "Поиск", "hex.builtin.view.pattern_editor.shortcut.replace": "Заменить", diff --git a/plugins/builtin/romfs/lang/zh_CN.json b/plugins/builtin/romfs/lang/zh_CN.json index 9fa67632a..3721c4714 100644 --- a/plugins/builtin/romfs/lang/zh_CN.json +++ b/plugins/builtin/romfs/lang/zh_CN.json @@ -985,10 +985,6 @@ "hex.builtin.view.pattern_editor.open_pattern": "打开模式", "hex.builtin.view.pattern_editor.replace_hint": "替换", "hex.builtin.view.pattern_editor.replace_hint_history": "历史", - "hex.builtin.view.pattern_editor.section_popup": "段", - "hex.builtin.view.pattern_editor.sections": "段", - "hex.builtin.view.pattern_editor.sections.view": "查看内容", - "hex.builtin.view.pattern_editor.sections.export": "导出内容", "hex.builtin.view.pattern_editor.settings": "设置", "hex.builtin.view.pattern_editor.shortcut.goto_line": "跳转到行...", "hex.builtin.view.pattern_editor.shortcut.find": "查找...", diff --git a/plugins/builtin/romfs/lang/zh_TW.json b/plugins/builtin/romfs/lang/zh_TW.json index 4671eeb0c..f38554b4f 100644 --- a/plugins/builtin/romfs/lang/zh_TW.json +++ b/plugins/builtin/romfs/lang/zh_TW.json @@ -898,8 +898,6 @@ "hex.builtin.view.pattern_editor.open_pattern": "開啟模式", "hex.builtin.view.pattern_editor.replace_hint": "", "hex.builtin.view.pattern_editor.replace_hint_history": "", - "hex.builtin.view.pattern_editor.section_popup": "Section", - "hex.builtin.view.pattern_editor.sections": "Sections", "hex.builtin.view.pattern_editor.settings": "設定", "hex.builtin.view.pattern_editor.shortcut.add_breakpoint": "", "hex.builtin.view.pattern_editor.shortcut.continue_debugger": "", diff --git a/plugins/builtin/source/content/views/view_pattern_data.cpp b/plugins/builtin/source/content/views/view_pattern_data.cpp index 2f4035c1a..58304224f 100644 --- a/plugins/builtin/source/content/views/view_pattern_data.cpp +++ b/plugins/builtin/source/content/views/view_pattern_data.cpp @@ -17,56 +17,69 @@ namespace hex::plugin::builtin { ContentRegistry::Settings::onChange("hex.builtin.setting.interface", "hex.builtin.setting.interface.pattern_tree_style", [this](const ContentRegistry::Settings::SettingsValue &value) { m_treeStyle = ui::PatternDrawer::TreeStyle(value.get(0)); - for (auto &drawer : m_patternDrawer.all()) - drawer->setTreeStyle(m_treeStyle); + for (auto &drawers : m_patternDrawer.all()) + for (auto &[id, drawer] : drawers) + drawer->setTreeStyle(m_treeStyle); }); ContentRegistry::Settings::onChange("hex.builtin.setting.interface", "hex.builtin.setting.interface.pattern_data_row_bg", [this](const ContentRegistry::Settings::SettingsValue &value) { m_rowColoring = bool(value.get(false)); - for (auto &drawer : m_patternDrawer.all()) - drawer->enableRowColoring(m_rowColoring); + for (auto &drawers : m_patternDrawer.all()) + for (auto &[id, drawer] : drawers) + drawer->enableRowColoring(m_rowColoring); }); ContentRegistry::Settings::onChange("hex.builtin.setting.general", "hex.builtin.setting.general.pattern_data_max_filter_items", [this](const ContentRegistry::Settings::SettingsValue &value) { m_maxFilterItems = value.get(128); - for (auto &drawer : m_patternDrawer.all()) - drawer->setMaxFilterDisplayItems(m_maxFilterItems); + for (auto &drawers : m_patternDrawer.all()) + for (auto &[id, drawer] : drawers) + drawer->setMaxFilterDisplayItems(m_maxFilterItems); }); EventPatternEvaluating::subscribe(this, [this]{ - (*m_patternDrawer)->reset(); + for (auto &drawers : m_patternDrawer.all()) + for (auto &[id, drawer] : drawers) + drawer->reset(); }); EventPatternExecuted::subscribe(this, [this](const auto&){ - (*m_patternDrawer)->reset(); + for (auto &drawers : m_patternDrawer.all()) + for (auto &[id, drawer] : drawers) + drawer->reset(); + + const auto §ions = ContentRegistry::PatternLanguage::getRuntime().getSections(); + auto ids = sections | std::views::keys | std::ranges::to>(); + ids.push_back(0); + + for (const auto &id : ids) { + auto drawer = std::make_unique(); + + drawer->setSelectionCallback([](const pl::ptrn::Pattern *pattern) { + ImHexApi::HexEditor::setSelection(Region(pattern->getOffset(), pattern->getSize())); + RequestPatternEditorSelectionChange::post(pattern->getLine(), 0); + }); + + drawer->setHoverCallback([this](const pl::ptrn::Pattern *pattern) { + if (pattern == nullptr) + m_hoveredPatternRegion = Region::Invalid(); + else + m_hoveredPatternRegion = Region(pattern->getOffset(), pattern->getSize()); + }); + + drawer->setTreeStyle(m_treeStyle); + drawer->enableRowColoring(m_rowColoring); + + (*m_patternDrawer)[id] = std::move(drawer); + } }); RequestJumpToPattern::subscribe(this, [this](const pl::ptrn::Pattern *pattern) { - (*m_patternDrawer)->jumpToPattern(pattern); + (*m_patternDrawer)[0]->jumpToPattern(pattern); }); ImHexApi::HexEditor::addHoverHighlightProvider([this](const prv::Provider *, u64, size_t) -> std::set { return { m_hoveredPatternRegion }; }); - - m_patternDrawer.setOnCreateCallback([this](const prv::Provider *, auto &drawer) { - drawer = std::make_unique(); - - drawer->setSelectionCallback([](const pl::ptrn::Pattern *pattern) { - ImHexApi::HexEditor::setSelection(Region(pattern->getOffset(), pattern->getSize())); - RequestPatternEditorSelectionChange::post(pattern->getLine(), 0); - }); - - drawer->setHoverCallback([this](const pl::ptrn::Pattern *pattern) { - if (pattern == nullptr) - m_hoveredPatternRegion = Region::Invalid(); - else - m_hoveredPatternRegion = Region(pattern->getOffset(), pattern->getSize()); - }); - - drawer->setTreeStyle(m_treeStyle); - drawer->enableRowColoring(m_rowColoring); - }); } ViewPatternData::~ViewPatternData() { @@ -78,21 +91,64 @@ namespace hex::plugin::builtin { // Draw the pattern tree if the provider is valid if (ImHexApi::Provider::isValid()) { // Make sure the runtime has finished evaluating and produced valid patterns + bool patternsValid = false; auto &runtime = ContentRegistry::PatternLanguage::getRuntime(); + if (TRY_LOCK(ContentRegistry::PatternLanguage::getRuntimeLock())) { + patternsValid = runtime.arePatternsValid(); + } - const auto height = std::max(ImGui::GetContentRegionAvail().y - ImGui::GetTextLineHeightWithSpacing() - (ImGui::GetStyle().FramePadding.y * 2), ImGui::GetTextLineHeightWithSpacing() * 5); + if (ImGui::BeginTabBar("##SectionSelector")) { - if (*m_patternDrawer != nullptr) { - (*m_patternDrawer)->enablePatternEditing(ImHexApi::Provider::get()->isWritable()); - if (!runtime.arePatternsValid()) { - (*m_patternDrawer)->draw({ }, nullptr, height); + const auto height = std::max(ImGui::GetContentRegionAvail().y - ImGui::GetTextLineHeightWithSpacing() - (ImGui::GetStyle().FramePadding.y * 2), ImGui::GetTextLineHeightWithSpacing() * 5); + + if (!patternsValid) { + ImGui::BeginDisabled(); + if (ImGui::BeginTabItem("hex.builtin.view.pattern_data.section.main"_lang)) { + static ui::PatternDrawer emptyDrawer; + emptyDrawer.draw({ }, nullptr, height); + ImGui::EndTabItem(); + } + ImGui::EndDisabled(); } else { - // If the runtime has finished evaluating, draw the patterns - if (TRY_LOCK(ContentRegistry::PatternLanguage::getRuntimeLock())) { - (*m_patternDrawer)->draw(runtime.getPatterns(), &runtime, height); + static i32 selectedSection = -1; + for (auto &[id, drawer] : *m_patternDrawer) { + drawer->enablePatternEditing(ImHexApi::Provider::get()->isWritable()); + + // If the runtime has finished evaluating, draw the patterns + if (TRY_LOCK(ContentRegistry::PatternLanguage::getRuntimeLock())) { + const auto §ions = runtime.getSections(); + if (id != 0 && !sections.contains(id)) + continue; + + if (ImGui::BeginTabItem(id == 0 ? "hex.builtin.view.pattern_data.section.main"_lang : sections.at(id).name.c_str())) { + drawer->draw(runtime.getPatterns(id), &runtime, height); + ImGui::EndTabItem(); + } + + if (id != 0) { + if (ImGui::IsMouseDown(ImGuiMouseButton_Right) && ImGui::IsItemHovered() && !ImGui::IsMouseDragging(ImGuiMouseButton_Right)) { + ImGui::OpenPopup("##PatternDataContextMenu"); + selectedSection = id; + } + } + } + } + + if (ImGui::BeginPopup("##PatternDataContextMenu")) { + if (ImGui::MenuItemEx("hex.builtin.view.pattern_data.section.view_raw"_lang, ICON_VS_OPEN_PREVIEW)) { + const auto §ions = runtime.getSections(); + if (auto it = sections.find(selectedSection); it != sections.end()) { + const auto &[id, section] = *it; + ImHexApi::Provider::add(section.data, section.name); + } + } + ImGui::EndPopup(); } } + + ImGui::EndTabBar(); } + } } diff --git a/plugins/builtin/source/content/views/view_pattern_editor.cpp b/plugins/builtin/source/content/views/view_pattern_editor.cpp index efd58a69e..3c52afdfd 100644 --- a/plugins/builtin/source/content/views/view_pattern_editor.cpp +++ b/plugins/builtin/source/content/views/view_pattern_editor.cpp @@ -475,10 +475,6 @@ namespace hex::plugin::builtin { this->drawVariableSettings(settingsSize, *m_patternVariables); ImGui::EndTabItem(); } - if (ImGui::BeginTabItem("hex.builtin.view.pattern_editor.sections"_lang)) { - this->drawSectionSelector(settingsSize, *m_sections); - ImGui::EndTabItem(); - } if (ImGui::BeginTabItem("hex.builtin.view.pattern_editor.virtual_files"_lang)) { this->drawVirtualFiles(settingsSize, *m_virtualFiles); ImGui::EndTabItem(); @@ -1291,108 +1287,6 @@ namespace hex::plugin::builtin { ImGui::EndChild(); } - void ViewPatternEditor::drawSectionSelector(ImVec2 size, const std::map §ions) { - auto &runtime = ContentRegistry::PatternLanguage::getRuntime(); - - if (ImGui::BeginTable("##sections_table", 3, ImGuiTableFlags_SizingStretchProp | ImGuiTableFlags_Borders | ImGuiTableFlags_RowBg | ImGuiTableFlags_ScrollY, size)) { - if (sections.empty()) { - ImGuiExt::TextOverlay("hex.builtin.view.pattern_editor.no_sections"_lang, ImGui::GetWindowPos() + ImGui::GetWindowSize() / 2, ImGui::GetWindowWidth() * 0.7); - } - - ImGui::TableSetupScrollFreeze(0, 1); - ImGui::TableSetupColumn("hex.ui.common.name"_lang, ImGuiTableColumnFlags_WidthStretch, 0.5F); - ImGui::TableSetupColumn("hex.ui.common.size"_lang, ImGuiTableColumnFlags_WidthStretch, 0.5F); - ImGui::TableSetupColumn("##button", ImGuiTableColumnFlags_WidthFixed, 50_scaled); - - ImGui::TableHeadersRow(); - - if (TRY_LOCK(ContentRegistry::PatternLanguage::getRuntimeLock())) { - for (auto &[id, section] : sections) { - if (section.name.empty()) - continue; - - ImGui::PushID(id); - - ImGui::TableNextRow(); - ImGui::TableNextColumn(); - - ImGui::TextUnformatted(section.name.c_str()); - ImGui::TableNextColumn(); - ImGuiExt::TextFormatted("{} | 0x{:02X}", hex::toByteString(section.data.size()), section.data.size()); - ImGui::TableNextColumn(); - if (ImGuiExt::DimmedIconButton(ICON_VS_OPEN_PREVIEW, ImGui::GetStyleColorVec4(ImGuiCol_Text))) { - auto dataProvider = std::make_shared(section.data); - auto hexEditor = ui::HexEditor(m_sectionHexEditor); - - hexEditor.setBackgroundHighlightCallback([this, id, &runtime](u64 address, const u8 *, size_t) -> std::optional { - if (m_runningEvaluators != 0) - return std::nullopt; - if (!ImHexApi::Provider::isValid()) - return std::nullopt; - - std::optional color; - for (const auto &pattern : runtime.getPatternsAtAddress(address, id)) { - auto visibility = pattern->getVisibility(); - if (visibility == pl::ptrn::Visibility::Hidden || visibility == pl::ptrn::Visibility::HighlightHidden) - continue; - - if (color.has_value()) - color = ImAlphaBlendColors(*color, pattern->getColor()); - else - color = pattern->getColor(); - } - - return color; - }); - - auto patternProvider = ImHexApi::Provider::get(); - - - m_sectionWindowDrawer[patternProvider] = [this, id, patternProvider, dataProvider, hexEditor, patternDrawer = std::make_shared(), &runtime]() mutable { - hexEditor.setProvider(dataProvider.get()); - hexEditor.draw(ImGui::GetContentRegionAvail().y * 0.7); - patternDrawer->setSelectionCallback([&](const pl::ptrn::Pattern *pattern) { - hexEditor.setSelection(Region { pattern->getOffset(), pattern->getSize() }); - }); - - const auto &patterns = [&, this]() -> const auto& { - if (patternProvider->isReadable() && *m_executionDone) { - return runtime.getPatterns(id); - } else { - static const std::vector> empty; - return empty; - } - }(); - - if (*m_executionDone) - patternDrawer->draw(patterns, &runtime, ImGui::GetContentRegionAvail().y); - }; - } - ImGui::SetItemTooltip("%s", "hex.builtin.view.pattern_editor.sections.view"_lang.get()); - - ImGui::SameLine(); - - if (ImGuiExt::DimmedIconButton(ICON_VS_SAVE_AS, ImGui::GetStyleColorVec4(ImGuiCol_Text))) { - fs::openFileBrowser(fs::DialogMode::Save, {}, [id, &runtime](const auto &path) { - wolv::io::File file(path, wolv::io::File::Mode::Create); - if (!file.isValid()) { - ui::ToastError::open("hex.builtin.popup.error.create"_lang); - return; - } - - file.writeVector(runtime.getSection(id)); - }); - } - ImGui::SetItemTooltip("%s", "hex.builtin.view.pattern_editor.sections.export"_lang.get()); - - ImGui::PopID(); - } - } - - ImGui::EndTable(); - } - } - void ViewPatternEditor::drawVirtualFiles(ImVec2 size, const std::vector &virtualFiles) const { std::vector virtualFilePointers; @@ -1488,20 +1382,6 @@ namespace hex::plugin::builtin { if (provider == nullptr) return; - auto open = m_sectionWindowDrawer.contains(provider); - if (open) { - ImGui::SetNextWindowSize(scaled(ImVec2(600, 700)), ImGuiCond_Appearing); - if (ImGui::Begin("hex.builtin.view.pattern_editor.section_popup"_lang, &open, ImGuiWindowFlags_NoDocking | ImGuiWindowFlags_NoScrollbar | ImGuiWindowFlags_NoScrollWithMouse)) { - m_sectionWindowDrawer[provider](); - } - ImGui::End(); - } - - if (!open && m_sectionWindowDrawer.contains(provider)) { - ImHexApi::HexEditor::setSelection(Region::Invalid()); - m_sectionWindowDrawer.erase(provider); - } - if (!m_lastEvaluationProcessed) { if (!m_lastEvaluationResult) { const auto processMessage = [](const auto &message) { @@ -1929,7 +1809,6 @@ namespace hex::plugin::builtin { m_consoleLongestLineLength.get(provider) = 0; m_consoleNeedsUpdate = true; - m_sectionWindowDrawer.clear(); m_consoleEditor.get(provider).SetText(""); m_virtualFiles->clear(); @@ -2009,7 +1888,6 @@ namespace hex::plugin::builtin { ON_SCOPE_EXIT { runtime.getInternals().evaluator->setDebugMode(false); *m_lastEvaluationOutVars = runtime.getOutVariables(); - *m_sections = runtime.getSections(); m_runningEvaluators -= 1;