2023-01-08 16:06:26 +01:00
|
|
|
#include <content/views/view_pattern_data.hpp>
|
2020-11-10 21:31:04 +01:00
|
|
|
|
2023-01-08 16:06:26 +01:00
|
|
|
#include <hex/api/content_registry.hpp>
|
2021-01-13 17:28:27 +01:00
|
|
|
#include <hex/providers/provider.hpp>
|
2022-02-27 23:25:39 +01:00
|
|
|
|
2022-04-17 16:57:30 +02:00
|
|
|
#include <pl/patterns/pattern.hpp>
|
2020-11-11 10:47:02 +01:00
|
|
|
|
2021-12-07 22:47:41 +01:00
|
|
|
namespace hex::plugin::builtin {
|
2020-11-10 21:31:04 +01:00
|
|
|
|
2021-12-07 22:47:41 +01:00
|
|
|
ViewPatternData::ViewPatternData() : View("hex.builtin.view.pattern_data.name") {
|
2020-11-10 21:31:04 +01:00
|
|
|
|
2023-01-24 23:27:15 +01:00
|
|
|
EventManager::subscribe<EventSettingsChanged>(this, [this]() {
|
2023-03-21 15:33:43 +01:00
|
|
|
auto patternStyle = ContentRegistry::Settings::read("hex.builtin.setting.interface", "hex.builtin.setting.interface.pattern_tree_style", 0);
|
|
|
|
this->m_patternDrawer.setTreeStyle(static_cast<ui::PatternDrawer::TreeStyle>(patternStyle));
|
2023-01-08 16:06:26 +01:00
|
|
|
});
|
2023-01-24 23:27:15 +01:00
|
|
|
|
|
|
|
EventManager::subscribe<EventProviderChanged>(this, [this](auto, auto) {
|
|
|
|
this->m_patternDrawer.reset();
|
|
|
|
});
|
2023-02-17 14:53:15 +01:00
|
|
|
|
|
|
|
this->m_patternDrawer.setSelectionCallback([](Region region){ ImHexApi::HexEditor::setSelection(region); });
|
2023-04-17 17:02:10 +02:00
|
|
|
|
|
|
|
EventManager::subscribe<EventPatternExecuted>([this](const auto&){
|
|
|
|
this->m_shouldReset = true;
|
|
|
|
});
|
2020-11-10 21:31:04 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
ViewPatternData::~ViewPatternData() {
|
2023-01-24 23:27:15 +01:00
|
|
|
EventManager::unsubscribe<EventSettingsChanged>(this);
|
|
|
|
EventManager::unsubscribe<EventProviderChanged>(this);
|
2020-11-10 21:31:04 +01:00
|
|
|
}
|
|
|
|
|
2020-12-22 18:10:01 +01:00
|
|
|
void ViewPatternData::drawContent() {
|
2021-12-07 22:47:41 +01:00
|
|
|
if (ImGui::Begin(View::toWindowName("hex.builtin.view.pattern_data.name").c_str(), &this->getWindowOpenState(), ImGuiWindowFlags_NoCollapse)) {
|
2022-09-19 16:09:22 +02:00
|
|
|
if (ImHexApi::Provider::isValid()) {
|
2023-04-17 16:18:48 +02:00
|
|
|
auto &runtime = ContentRegistry::PatternLanguage::getRuntime();
|
2023-04-17 17:02:10 +02:00
|
|
|
if (!runtime.arePatternsValid()) {
|
|
|
|
this->m_patternDrawer.draw({});
|
|
|
|
} else {
|
|
|
|
auto lock = ContentRegistry::PatternLanguage::getRuntimeLock();
|
|
|
|
|
|
|
|
if (this->m_shouldReset) {
|
|
|
|
this->m_patternDrawer.reset();
|
|
|
|
this->m_shouldReset = false;
|
2022-10-06 13:24:22 +02:00
|
|
|
}
|
2023-01-24 23:27:15 +01:00
|
|
|
|
2023-04-18 10:06:47 +02:00
|
|
|
this->m_patternDrawer.draw(runtime.getPatterns());
|
2023-04-17 17:02:10 +02:00
|
|
|
}
|
2020-11-10 21:31:04 +01:00
|
|
|
}
|
|
|
|
}
|
2020-11-11 10:47:02 +01:00
|
|
|
ImGui::End();
|
2020-11-10 21:31:04 +01:00
|
|
|
}
|
|
|
|
|
2022-08-19 23:01:57 +02:00
|
|
|
}
|