2021-12-07 22:47:41 +01:00
|
|
|
#include "content/views/view_pattern_data.hpp"
|
2020-11-10 21:31:04 +01:00
|
|
|
|
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
|
|
|
|
2022-09-18 16:22:08 +02:00
|
|
|
#include <content/helpers/provider_extra_data.hpp>
|
2022-08-08 21:23:52 +02: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
|
|
|
|
2022-02-04 00:29:47 +01:00
|
|
|
EventManager::subscribe<EventHighlightingChanged>(this, [this]() {
|
2022-02-01 18:09:40 +01:00
|
|
|
if (!ImHexApi::Provider::isValid()) return;
|
|
|
|
|
|
|
|
this->m_sortedPatterns[ImHexApi::Provider::get()].clear();
|
2020-11-15 00:46:18 +01:00
|
|
|
});
|
2022-10-12 14:50:09 +02:00
|
|
|
|
|
|
|
EventManager::subscribe<EventProviderClosed>([this](auto *provider) {
|
|
|
|
this->m_sortedPatterns[provider].clear();
|
|
|
|
});
|
2020-11-10 21:31:04 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
ViewPatternData::~ViewPatternData() {
|
2022-02-04 00:29:47 +01:00
|
|
|
EventManager::unsubscribe<EventHighlightingChanged>(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()) {
|
|
|
|
auto provider = ImHexApi::Provider::get();
|
2022-10-03 10:36:19 +02:00
|
|
|
auto &patternLanguage = ProviderExtraData::get(provider).patternLanguage;
|
2020-11-10 21:31:04 +01:00
|
|
|
|
2022-10-06 13:24:22 +02: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;
|
|
|
|
}
|
|
|
|
}();
|
2020-11-19 21:59:27 +01:00
|
|
|
|
2022-11-08 21:43:22 +01:00
|
|
|
this->m_patternDrawer.draw(patterns);
|
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
|
|
|
}
|