1
0
mirror of synced 2024-11-24 15:50:16 +01:00

feat: Display destination address in goto popup

This commit is contained in:
WerWolv 2024-04-23 23:26:58 +02:00
parent a1ea8dfd84
commit 3794aa425d

View File

@ -59,38 +59,55 @@ namespace hex::plugin::builtin {
ImGui::SetKeyboardFocusHere(); ImGui::SetKeyboardFocusHere();
m_requestFocus = false; m_requestFocus = false;
} }
if (ImGuiExt::InputTextIcon("##input", ICON_VS_SYMBOL_OPERATOR, m_input, ImGuiInputTextFlags_EnterReturnsTrue | ImGuiInputTextFlags_AutoSelectAll)) { if (ImGuiExt::InputTextIcon("##input", ICON_VS_SYMBOL_OPERATOR, m_input)) {
if (auto result = m_evaluator.evaluate(m_input); result.has_value()) { if (auto result = m_evaluator.evaluate(m_input); result.has_value()) {
const auto inputResult = result.value(); const auto inputResult = result.value();
u64 newAddress = 0x00;
auto provider = ImHexApi::Provider::get(); auto provider = ImHexApi::Provider::get();
switch (m_mode) { switch (m_mode) {
case Mode::Absolute: { case Mode::Absolute: {
newAddress = inputResult; m_newAddress = inputResult;
} }
break; break;
case Mode::Relative: { case Mode::Relative: {
const auto selection = editor->getSelection(); const auto selection = editor->getSelection();
newAddress = selection.getStartAddress() + inputResult; m_newAddress = selection.getStartAddress() + inputResult;
} }
break; break;
case Mode::Begin: { case Mode::Begin: {
newAddress = provider->getBaseAddress() + provider->getCurrentPageAddress() + inputResult; m_newAddress = provider->getBaseAddress() + provider->getCurrentPageAddress() + inputResult;
} }
break; break;
case Mode::End: { case Mode::End: {
newAddress = provider->getActualSize() - inputResult; m_newAddress = provider->getActualSize() - inputResult;
} }
break; break;
} }
} else {
editor->setSelection(newAddress, newAddress); m_newAddress.reset();
editor->jumpToSelection();
} }
} }
bool executeGoto = false;
if (ImGui::IsItemFocused() && ImGui::IsKeyPressed(ImGuiKey_Enter)) {
executeGoto = true;
}
ImGui::BeginDisabled(!m_newAddress.has_value());
{
const auto label = hex::format("{} {}", "hex.builtin.view.hex_editor.menu.file.goto"_lang, m_newAddress.has_value() ? hex::format("0x{:08X}", *m_newAddress) : "???");
const auto buttonWidth = ImGui::GetWindowWidth() - ImGui::GetStyle().WindowPadding.x * 2;
if (ImGuiExt::DimmedButton(label.c_str(), ImVec2(buttonWidth, 0))) {
executeGoto = true;
}
}
ImGui::EndDisabled();
if (executeGoto && m_newAddress.has_value()) {
editor->setSelection(*m_newAddress, *m_newAddress);
editor->jumpToSelection();
}
ImGui::EndTabBar(); ImGui::EndTabBar();
} }
} }
@ -104,9 +121,10 @@ namespace hex::plugin::builtin {
}; };
Mode m_mode = Mode::Absolute; Mode m_mode = Mode::Absolute;
std::optional<u64> m_newAddress;
bool m_requestFocus = true; bool m_requestFocus = true;
std::string m_input; std::string m_input = "0x";
wolv::math_eval::MathEvaluator<i128> m_evaluator; wolv::math_eval::MathEvaluator<i128> m_evaluator;
}; };
@ -1101,7 +1119,7 @@ namespace hex::plugin::builtin {
ContentRegistry::Interface::addMenuItem({ "hex.builtin.menu.edit", "hex.builtin.view.hex_editor.menu.edit.resize" }, ICON_VS_ARROW_BOTH, 1700, Shortcut::None, ContentRegistry::Interface::addMenuItem({ "hex.builtin.menu.edit", "hex.builtin.view.hex_editor.menu.edit.resize" }, ICON_VS_ARROW_BOTH, 1700, Shortcut::None,
[this] { [this] {
auto provider = ImHexApi::Provider::get(); auto provider = ImHexApi::Provider::get();
this->openPopup<PopupResize>(provider->getBaseAddress()); this->openPopup<PopupResize>(provider->getActualSize());
}, },
[] { return ImHexApi::Provider::isValid() && ImHexApi::Provider::get()->isResizable(); }); [] { return ImHexApi::Provider::isValid() && ImHexApi::Provider::get()->isResizable(); });