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
|
|
|
|
|
|
|
#include <hex/pattern_language/pattern_language.hpp>
|
|
|
|
#include <hex/pattern_language/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
|
|
|
|
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
|
|
|
});
|
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
|
|
|
}
|
|
|
|
|
2022-02-27 23:25:39 +01:00
|
|
|
static bool beginPatternTable(prv::Provider *&provider, const std::vector<std::shared_ptr<pl::Pattern>> &patterns, std::vector<std::shared_ptr<pl::Pattern>> &sortedPatterns) {
|
|
|
|
if (ImGui::BeginTable("##Patterntable", 6, ImGuiTableFlags_Borders | ImGuiTableFlags_Resizable | ImGuiTableFlags_Sortable | ImGuiTableFlags_Hideable | ImGuiTableFlags_Reorderable | ImGuiTableFlags_RowBg | ImGuiTableFlags_ScrollY)) {
|
2020-11-23 15:22:26 +01:00
|
|
|
ImGui::TableSetupScrollFreeze(0, 1);
|
2022-01-24 20:53:17 +01:00
|
|
|
ImGui::TableSetupColumn("hex.builtin.view.pattern_data.var_name"_lang, 0, 0, ImGui::GetID("name"));
|
|
|
|
ImGui::TableSetupColumn("hex.builtin.view.pattern_data.color"_lang, 0, 0, ImGui::GetID("color"));
|
|
|
|
ImGui::TableSetupColumn("hex.builtin.view.pattern_data.offset"_lang, 0, 0, ImGui::GetID("offset"));
|
|
|
|
ImGui::TableSetupColumn("hex.builtin.view.pattern_data.size"_lang, 0, 0, ImGui::GetID("size"));
|
|
|
|
ImGui::TableSetupColumn("hex.builtin.view.pattern_data.type"_lang, 0, 0, ImGui::GetID("type"));
|
|
|
|
ImGui::TableSetupColumn("hex.builtin.view.pattern_data.value"_lang, 0, 0, ImGui::GetID("value"));
|
2020-11-19 21:19:03 +01:00
|
|
|
|
|
|
|
auto sortSpecs = ImGui::TableGetSortSpecs();
|
|
|
|
|
|
|
|
if (sortSpecs->SpecsDirty || sortedPatterns.empty()) {
|
|
|
|
sortedPatterns = patterns;
|
|
|
|
|
2022-02-27 23:25:39 +01:00
|
|
|
std::sort(sortedPatterns.begin(), sortedPatterns.end(), [&sortSpecs, &provider](const std::shared_ptr<pl::Pattern> &left, const std::shared_ptr<pl::Pattern> &right) -> bool {
|
|
|
|
return pl::Pattern::sortPatternTable(sortSpecs, provider, left.get(), right.get());
|
2020-11-19 21:19:03 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
for (auto &pattern : sortedPatterns)
|
|
|
|
pattern->sort(sortSpecs, provider);
|
|
|
|
|
|
|
|
sortSpecs->SpecsDirty = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
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)) {
|
2021-09-21 02:29:54 +02:00
|
|
|
auto provider = ImHexApi::Provider::get();
|
|
|
|
if (ImHexApi::Provider::isValid() && provider->isReadable()) {
|
2020-11-10 21:31:04 +01:00
|
|
|
|
2022-02-01 18:09:40 +01:00
|
|
|
auto &sortedPatterns = this->m_sortedPatterns[ImHexApi::Provider::get()];
|
2022-02-27 23:25:39 +01:00
|
|
|
if (beginPatternTable(provider, provider->getPatternLanguageRuntime().getPatterns(), sortedPatterns)) {
|
2021-01-11 09:53:20 +01:00
|
|
|
ImGui::TableHeadersRow();
|
2022-02-01 18:09:40 +01:00
|
|
|
if (!sortedPatterns.empty()) {
|
2020-11-19 21:59:27 +01:00
|
|
|
|
2022-03-21 13:52:07 +01:00
|
|
|
m_drawer.setProvider(provider);
|
2022-02-27 23:25:39 +01:00
|
|
|
for (auto &patterns : sortedPatterns)
|
2022-03-21 13:52:07 +01:00
|
|
|
patterns->accept(m_drawer);
|
2020-11-15 00:46:18 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
ImGui::EndTable();
|
2020-11-11 09:18:35 +01: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
|
|
|
}
|
|
|
|
|
|
|
|
}
|