1
0
mirror of synced 2024-11-27 17:10:51 +01:00
ImHex/plugins/builtin/source/content/views/view_pattern_data.cpp

56 lines
2.1 KiB
C++
Raw Normal View History

#include <content/views/view_pattern_data.hpp>
2020-11-10 21:31:04 +01:00
#include <hex/api/content_registry.hpp>
#include <hex/providers/provider.hpp>
#include <pl/patterns/pattern.hpp>
#include <wolv/utils/lock.hpp>
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
EventManager::subscribe<EventSettingsChanged>(this, [this]() {
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));
});
EventManager::subscribe<EventProviderChanged>(this, [this](auto, auto) {
this->m_patternDrawer.reset();
});
this->m_patternDrawer.setSelectionCallback([](Region region){ ImHexApi::HexEditor::setSelection(region); });
EventManager::subscribe<EventPatternExecuted>([this](const auto&){
this->m_shouldReset = true;
});
2020-11-10 21:31:04 +01:00
}
ViewPatternData::~ViewPatternData() {
EventManager::unsubscribe<EventSettingsChanged>(this);
EventManager::unsubscribe<EventProviderChanged>(this);
2020-11-10 21:31:04 +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)) {
if (ImHexApi::Provider::isValid()) {
auto &runtime = ContentRegistry::PatternLanguage::getRuntime();
2023-05-13 15:43:37 +02:00
if (!runtime.arePatternsValid()) {
this->m_patternDrawer.draw({});
} else {
2023-05-13 15:43:37 +02:00
if (TRY_LOCK(ContentRegistry::PatternLanguage::getRuntimeLock())) {
if (this->m_shouldReset) {
this->m_patternDrawer.reset();
this->m_shouldReset = false;
}
2023-05-13 15:43:37 +02:00
this->m_patternDrawer.draw(runtime.getPatterns());
}
}
2020-11-10 21:31:04 +01:00
}
}
ImGui::End();
2020-11-10 21:31:04 +01:00
}
}