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

50 lines
1.7 KiB
C++
Raw Normal View History

2021-12-07 22:47:41 +01:00
#include "content/views/view_pattern_data.hpp"
2020-11-10 21:31:04 +01:00
#include <hex/providers/provider.hpp>
#include <pl/patterns/pattern.hpp>
#include <content/helpers/provider_extra_data.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<EventHighlightingChanged>(this, [this]() {
if (!ImHexApi::Provider::isValid()) return;
this->m_sortedPatterns[ImHexApi::Provider::get()].clear();
2020-11-15 00:46:18 +01:00
});
EventManager::subscribe<EventProviderClosed>([this](auto *provider) {
this->m_sortedPatterns[provider].clear();
});
2020-11-10 21:31:04 +01:00
}
ViewPatternData::~ViewPatternData() {
EventManager::unsubscribe<EventHighlightingChanged>(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 provider = ImHexApi::Provider::get();
auto &patternLanguage = ProviderExtraData::get(provider).patternLanguage;
2020-11-10 21:31:04 +01:00
const auto &patterns = [&] -> const auto& {
if (provider->isReadable() && patternLanguage.runtime != nullptr && patternLanguage.executionDone)
return ProviderExtraData::get(provider).patternLanguage.runtime->getAllPatterns();
else {
static const std::vector<std::shared_ptr<pl::ptrn::Pattern>> empty;
return empty;
}
}();
this->m_patternDrawer.draw(patterns);
2020-11-10 21:31:04 +01:00
}
}
ImGui::End();
2020-11-10 21:31:04 +01:00
}
}