sys/ux: Improved selection requests
This commit is contained in:
parent
e918a594f3
commit
abd3fe6ed1
@ -232,7 +232,7 @@ struct MemoryEditor
|
||||
if (ImGui::Begin(title, p_open, ImGuiWindowFlags_NoScrollbar | ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoNavInputs))
|
||||
{
|
||||
if (DataPreviewAddr != DataPreviewAddrOld || DataPreviewAddrEnd != DataPreviewAddrEndOld) {
|
||||
hex::Region selectionRegion = { std::min(DataPreviewAddr, DataPreviewAddrEnd) + base_display_addr, std::max(DataPreviewAddr, DataPreviewAddrEnd) - std::min(DataPreviewAddr, DataPreviewAddrEnd) };
|
||||
hex::Region selectionRegion = { std::min(DataPreviewAddr, DataPreviewAddrEnd) + base_display_addr, (std::max(DataPreviewAddr, DataPreviewAddrEnd) - std::min(DataPreviewAddr, DataPreviewAddrEnd)) + 1 };
|
||||
hex::EventManager::post<hex::EventRegionSelected>(selectionRegion);
|
||||
}
|
||||
|
||||
@ -335,7 +335,7 @@ struct MemoryEditor
|
||||
else if (ImGui::IsKeyPressed(ImGui::GetKeyIndex(ImGuiKey_End)) && DataPreviewAddr < mem_size - 1) { DataPreviewAddr = data_preview_addr_next = mem_size - 1; if (!ImGui::GetIO().KeyShift) DataPreviewAddrEnd = DataPreviewAddr; }
|
||||
}
|
||||
} else if (ImGui::IsKeyPressed(ImGui::GetKeyIndex(ImGuiKey_Escape))) {
|
||||
DataPreviewAddr = data_preview_addr_next = DataPreviewAddrEnd = (size_t)-1;
|
||||
DataPreviewAddr = DataPreviewAddrOld = DataPreviewAddrEnd = DataPreviewAddrEndOld = data_preview_addr_next = (size_t)-1;
|
||||
HighlightMin = HighlightMax = (size_t)-1;
|
||||
|
||||
hex::EventManager::post<hex::EventRegionSelected>(hex::Region{ (size_t)-1, 0 });
|
||||
|
@ -59,7 +59,7 @@ namespace hex {
|
||||
using EventList = std::list<std::pair<EventId, EventBase *>>;
|
||||
|
||||
template<typename E>
|
||||
[[nodiscard]] static EventList::iterator subscribe(typename E::Callback function) {
|
||||
static EventList::iterator subscribe(typename E::Callback function) {
|
||||
return s_events.insert(s_events.end(), std::make_pair(E::id, new E(function)));
|
||||
}
|
||||
|
||||
|
@ -48,6 +48,10 @@ namespace hex {
|
||||
void removeHighlight(u32 id);
|
||||
std::map<u32, Highlighting> &getHighlights();
|
||||
|
||||
Region getSelection();
|
||||
void setSelection(const Region ®ion);
|
||||
void setSelection(u64 address, size_t size);
|
||||
|
||||
}
|
||||
|
||||
namespace Bookmarks {
|
||||
|
@ -54,6 +54,23 @@ namespace hex {
|
||||
return s_highlights;
|
||||
}
|
||||
|
||||
Region getSelection() {
|
||||
static Region selectedRegion;
|
||||
EventManager::subscribe<EventRegionSelected>([](const Region ®ion) {
|
||||
selectedRegion = region;
|
||||
});
|
||||
|
||||
return selectedRegion;
|
||||
}
|
||||
|
||||
void setSelection(const Region ®ion) {
|
||||
EventManager::post<RequestSelectionChange>(region);
|
||||
}
|
||||
|
||||
void setSelection(u64 address, size_t size) {
|
||||
setSelection({ address, size });
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
@ -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))
|
||||
|
@ -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);
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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());
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -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();
|
||||
|
@ -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");
|
||||
|
@ -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);
|
||||
|
@ -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();
|
||||
|
Loading…
Reference in New Issue
Block a user