impr: Clean up diff view
This commit is contained in:
parent
6216d72aa6
commit
d9fa4b452c
@ -23,7 +23,7 @@ namespace hex::plugin::builtin {
|
|||||||
|
|
||||||
void drawContent() override;
|
void drawContent() override;
|
||||||
|
|
||||||
private:
|
public:
|
||||||
struct Column {
|
struct Column {
|
||||||
ui::HexEditor hexEditor;
|
ui::HexEditor hexEditor;
|
||||||
int provider = -1;
|
int provider = -1;
|
||||||
@ -41,10 +41,6 @@ namespace hex::plugin::builtin {
|
|||||||
DifferenceType type;
|
DifferenceType type;
|
||||||
};
|
};
|
||||||
|
|
||||||
bool drawDiffColumn(Column &column, float height) const;
|
|
||||||
void drawProviderSelector(Column &column);
|
|
||||||
std::string getProviderName(Column &column) const;
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::array<Column, 2> m_columns;
|
std::array<Column, 2> m_columns;
|
||||||
|
|
||||||
|
@ -53,9 +53,12 @@ namespace hex::plugin::builtin {
|
|||||||
}
|
}
|
||||||
|
|
||||||
ViewDiff::~ViewDiff() {
|
ViewDiff::~ViewDiff() {
|
||||||
|
EventManager::unsubscribe<EventProviderClosed>(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ViewDiff::drawDiffColumn(Column &column, float height) const {
|
namespace {
|
||||||
|
|
||||||
|
bool drawDiffColumn(ViewDiff::Column &column, float height) {
|
||||||
bool scrolled = false;
|
bool scrolled = false;
|
||||||
ImGui::PushID(&column);
|
ImGui::PushID(&column);
|
||||||
|
|
||||||
@ -73,7 +76,9 @@ namespace hex::plugin::builtin {
|
|||||||
return scrolled;
|
return scrolled;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ViewDiff::drawProviderSelector(Column &column) {
|
bool drawProviderSelector(ViewDiff::Column &column) {
|
||||||
|
bool shouldReanalyze = false;
|
||||||
|
|
||||||
ImGui::PushID(&column);
|
ImGui::PushID(&column);
|
||||||
|
|
||||||
auto &providers = ImHexApi::Provider::getProviders();
|
auto &providers = ImHexApi::Provider::getProviders();
|
||||||
@ -84,26 +89,23 @@ namespace hex::plugin::builtin {
|
|||||||
preview = providers[providerIndex]->getName();
|
preview = providers[providerIndex]->getName();
|
||||||
|
|
||||||
ImGui::SetNextItemWidth(ImGui::GetContentRegionAvail().x);
|
ImGui::SetNextItemWidth(ImGui::GetContentRegionAvail().x);
|
||||||
ImGui::BeginDisabled(this->m_diffTask.isRunning());
|
|
||||||
if (ImGui::BeginCombo("", preview.c_str())) {
|
if (ImGui::BeginCombo("", preview.c_str())) {
|
||||||
|
|
||||||
for (size_t i = 0; i < providers.size(); i++) {
|
for (size_t i = 0; i < providers.size(); i++) {
|
||||||
if (ImGui::Selectable(providers[i]->getName().c_str())) {
|
if (ImGui::Selectable(providers[i]->getName().c_str())) {
|
||||||
providerIndex = i;
|
providerIndex = i;
|
||||||
this->m_analyzed = false;
|
shouldReanalyze = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ImGui::EndCombo();
|
ImGui::EndCombo();
|
||||||
}
|
}
|
||||||
ImGui::EndDisabled();
|
|
||||||
|
|
||||||
ImGui::PopID();
|
ImGui::PopID();
|
||||||
|
|
||||||
|
return shouldReanalyze;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string ViewDiff::getProviderName(Column &column) const {
|
|
||||||
const auto &providers = ImHexApi::Provider::getProviders();
|
|
||||||
return ((column.provider >= 0 && size_t(column.provider) < providers.size()) ? providers[column.provider]->getName() : "???") + "##" + hex::format("{:X}", u64(&column));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ViewDiff::drawContent() {
|
void ViewDiff::drawContent() {
|
||||||
@ -137,9 +139,6 @@ namespace hex::plugin::builtin {
|
|||||||
|
|
||||||
auto commonSize = std::min(providerA->getActualSize(), providerB->getActualSize());
|
auto commonSize = std::min(providerA->getActualSize(), providerB->getActualSize());
|
||||||
this->m_diffTask = TaskManager::createTask("Diffing...", commonSize, [this, providerA, providerB](Task &task) {
|
this->m_diffTask = TaskManager::createTask("Diffing...", commonSize, [this, providerA, providerB](Task &task) {
|
||||||
std::vector<u8> bufferA(0x1000);
|
|
||||||
std::vector<u8> bufferB(0x1000);
|
|
||||||
|
|
||||||
std::vector<Diff> differences;
|
std::vector<Diff> differences;
|
||||||
|
|
||||||
auto readerA = prv::BufferedReader(providerA);
|
auto readerA = prv::BufferedReader(providerA);
|
||||||
@ -159,8 +158,11 @@ namespace hex::plugin::builtin {
|
|||||||
end++;
|
end++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
differences.push_back(Diff { Region{ start, end }, ViewDiff::DifferenceType::Modified });
|
differences.push_back(Diff { Region{ start, end }, ViewDiff::DifferenceType::Modified });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
task.update(itA.getAddress());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (providerA->getActualSize() != providerB->getActualSize()) {
|
if (providerA->getActualSize() != providerB->getActualSize()) {
|
||||||
@ -185,11 +187,13 @@ namespace hex::plugin::builtin {
|
|||||||
ImGui::TableSetupColumn("hex.builtin.view.diff.provider_b"_lang);
|
ImGui::TableSetupColumn("hex.builtin.view.diff.provider_b"_lang);
|
||||||
ImGui::TableHeadersRow();
|
ImGui::TableHeadersRow();
|
||||||
|
|
||||||
|
ImGui::BeginDisabled(this->m_diffTask.isRunning());
|
||||||
ImGui::TableNextColumn();
|
ImGui::TableNextColumn();
|
||||||
this->drawProviderSelector(a);
|
if (drawProviderSelector(a)) this->m_analyzed = false;
|
||||||
|
|
||||||
ImGui::TableNextColumn();
|
ImGui::TableNextColumn();
|
||||||
this->drawProviderSelector(b);
|
if (drawProviderSelector(b)) this->m_analyzed = false;
|
||||||
|
ImGui::EndDisabled();
|
||||||
|
|
||||||
ImGui::TableNextRow();
|
ImGui::TableNextRow();
|
||||||
|
|
||||||
@ -220,7 +224,7 @@ namespace hex::plugin::builtin {
|
|||||||
|
|
||||||
if (this->m_analyzed) {
|
if (this->m_analyzed) {
|
||||||
ImGuiListClipper clipper;
|
ImGuiListClipper clipper;
|
||||||
clipper.Begin(this->m_diffs.size());
|
clipper.Begin(int(this->m_diffs.size()));
|
||||||
|
|
||||||
while (clipper.Step())
|
while (clipper.Step())
|
||||||
for (int i = clipper.DisplayStart; i < clipper.DisplayEnd; i++) {
|
for (int i = clipper.DisplayStart; i < clipper.DisplayEnd; i++) {
|
||||||
|
Loading…
Reference in New Issue
Block a user