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