sys/ux: Improved selection requests

This commit is contained in:
WerWolv
2022-02-08 18:38:54 +01:00
parent e918a594f3
commit abd3fe6ed1
12 changed files with 37 additions and 16 deletions

View File

@@ -124,7 +124,7 @@ namespace hex::plugin::builtin {
ImGui::EndChild();
if (ImGui::Button("hex.builtin.view.bookmarks.button.jump"_lang))
EventManager::post<RequestSelectionChange>(region);
ImHexApi::HexEditor::setSelection(region);
ImGui::SameLine(0, 15);
if (ImGui::Button("hex.builtin.view.bookmarks.button.remove"_lang))

View File

@@ -21,7 +21,7 @@ namespace hex::plugin::builtin {
this->m_codeRegion[0] = this->m_codeRegion[1] = 0;
} else {
this->m_codeRegion[0] = region.address;
this->m_codeRegion[1] = region.address + region.size;
this->m_codeRegion[1] = region.address + region.size - 1;
}
}
});
@@ -115,7 +115,7 @@ namespace hex::plugin::builtin {
ImGui::Checkbox("hex.builtin.common.match_selection"_lang, &this->m_shouldMatchSelection);
if (ImGui::IsItemEdited()) {
// Force execution of Region Selection Event
EventManager::post<RequestSelectionChange>(Region { 0, 0 });
ImHexApi::HexEditor::setSelection(0, 0);
}
ImGui::NewLine();
@@ -356,7 +356,7 @@ namespace hex::plugin::builtin {
ImGui::TableNextRow();
ImGui::TableNextColumn();
if (ImGui::Selectable(("##DisassemblyLine"s + std::to_string(i)).c_str(), false, ImGuiSelectableFlags_SpanAllColumns)) {
EventManager::post<RequestSelectionChange>(Region { instruction.offset, instruction.size });
ImHexApi::HexEditor::setSelection(instruction.offset, instruction.size);
}
ImGui::SameLine();
ImGui::TextFormatted("0x{0:X}", instruction.address);

View File

@@ -19,7 +19,7 @@ namespace hex::plugin::builtin {
this->m_hashRegion[0] = this->m_hashRegion[1] = 0;
} else {
this->m_hashRegion[0] = region.address;
this->m_hashRegion[1] = region.size + 1; // WARNING: get size - 1 as region size
this->m_hashRegion[1] = region.size;
}
this->m_shouldInvalidate = true;
}
@@ -55,7 +55,7 @@ namespace hex::plugin::builtin {
ImGui::Checkbox("hex.builtin.common.match_selection"_lang, &this->m_shouldMatchSelection);
if (ImGui::IsItemEdited()) {
// Force execution of Region Selection Event
EventManager::post<RequestSelectionChange>(Region { 0, 0 });
ImHexApi::HexEditor::setSelection(0, 0);
this->m_shouldInvalidate = true;
}

View File

@@ -726,7 +726,7 @@ namespace hex::plugin::builtin {
if (ImGui::Button("hex.builtin.view.hex_editor.menu.file.goto"_lang) || runGoto) {
provider->setCurrentPage(std::floor(double(newOffset - baseAddress) / hex::prv::Provider::PageSize));
EventManager::post<RequestSelectionChange>(Region { newOffset, 1 });
ImHexApi::HexEditor::setSelection(newOffset, 1);
}
ImGui::EndTabBar();
@@ -775,7 +775,7 @@ namespace hex::plugin::builtin {
this->pasteBytes();
if (ImGui::MenuItem("hex.builtin.view.hex_editor.menu.edit.select_all"_lang, "CTRL + A", false, providerValid))
EventManager::post<RequestSelectionChange>(Region { provider->getBaseAddress(), provider->getActualSize() });
ImHexApi::HexEditor::setSelection(provider->getBaseAddress(), provider->getActualSize());
ImGui::Separator();
@@ -992,7 +992,7 @@ namespace hex::plugin::builtin {
ShortcutManager::addShortcut(this, CTRL + Keys::A, [] {
auto provider = ImHexApi::Provider::get();
EventManager::post<RequestSelectionChange>(Region { provider->getBaseAddress(), provider->getActualSize() });
ImHexApi::HexEditor::setSelection(provider->getBaseAddress(), provider->getActualSize());
});
}

View File

@@ -209,7 +209,7 @@ namespace hex::plugin::builtin {
if (ImPlot::DragLineX("Position", &this->m_entropyHandlePosition, false)) {
u64 address = u64(this->m_entropyHandlePosition * this->m_blockSize) + provider->getBaseAddress();
address = std::min(address, provider->getBaseAddress() + provider->getSize() - 1);
EventManager::post<RequestSelectionChange>(Region { address, 1 });
ImHexApi::HexEditor::setSelection(address, 1);
}
ImPlot::EndPlot();

View File

@@ -60,7 +60,7 @@ namespace hex::plugin::builtin {
ImGui::TableNextColumn();
if (ImGui::Selectable(("##patchLine" + std::to_string(index)).c_str(), false, ImGuiSelectableFlags_SpanAllColumns)) {
EventManager::post<RequestSelectionChange>(Region { address, 1 });
ImHexApi::HexEditor::setSelection(address, 1);
}
if (ImGui::IsMouseReleased(1) && ImGui::IsItemHovered()) {
ImGui::OpenPopup("PatchContextMenu");

View File

@@ -202,7 +202,7 @@ namespace hex::plugin::builtin {
ImGui::TableNextRow();
ImGui::TableNextColumn();
if (ImGui::Selectable(("##StringLine"s + std::to_string(i)).c_str(), false, ImGuiSelectableFlags_SpanAllColumns)) {
EventManager::post<RequestSelectionChange>(Region { foundString.offset, foundString.size });
ImHexApi::HexEditor::setSelection(foundString.offset, foundString.size);
}
ImGui::PushID(i + 1);
createStringContextMenu(foundString);

View File

@@ -101,7 +101,7 @@ namespace hex::plugin::builtin {
ImGui::TableNextColumn();
ImGui::PushID(i);
if (ImGui::Selectable("match", false, ImGuiSelectableFlags_SpanAllColumns | ImGuiSelectableFlags_AllowItemOverlap)) {
EventManager::post<RequestSelectionChange>(Region { u64(address), size_t(size) });
ImHexApi::HexEditor::setSelection(address, size);
}
ImGui::PopID();
ImGui::SameLine();