Skip to content

Commit 3794aa4

Browse files
committed
feat: Display destination address in goto popup
1 parent a1ea8df commit 3794aa4

File tree

1 file changed

+29
-11
lines changed

1 file changed

+29
-11
lines changed

plugins/builtin/source/content/views/view_hex_editor.cpp

+29-11
Original file line numberDiff line numberDiff line change
@@ -59,37 +59,54 @@ namespace hex::plugin::builtin {
5959
ImGui::SetKeyboardFocusHere();
6060
m_requestFocus = false;
6161
}
62-
if (ImGuiExt::InputTextIcon("##input", ICON_VS_SYMBOL_OPERATOR, m_input, ImGuiInputTextFlags_EnterReturnsTrue | ImGuiInputTextFlags_AutoSelectAll)) {
62+
if (ImGuiExt::InputTextIcon("##input", ICON_VS_SYMBOL_OPERATOR, m_input)) {
6363
if (auto result = m_evaluator.evaluate(m_input); result.has_value()) {
6464
const auto inputResult = result.value();
65-
u64 newAddress = 0x00;
66-
6765
auto provider = ImHexApi::Provider::get();
6866

6967
switch (m_mode) {
7068
case Mode::Absolute: {
71-
newAddress = inputResult;
69+
m_newAddress = inputResult;
7270
}
7371
break;
7472
case Mode::Relative: {
7573
const auto selection = editor->getSelection();
76-
newAddress = selection.getStartAddress() + inputResult;
74+
m_newAddress = selection.getStartAddress() + inputResult;
7775
}
7876
break;
7977
case Mode::Begin: {
80-
newAddress = provider->getBaseAddress() + provider->getCurrentPageAddress() + inputResult;
78+
m_newAddress = provider->getBaseAddress() + provider->getCurrentPageAddress() + inputResult;
8179
}
8280
break;
8381
case Mode::End: {
84-
newAddress = provider->getActualSize() - inputResult;
82+
m_newAddress = provider->getActualSize() - inputResult;
8583
}
8684
break;
8785
}
86+
} else {
87+
m_newAddress.reset();
88+
}
89+
}
90+
91+
bool executeGoto = false;
92+
if (ImGui::IsItemFocused() && ImGui::IsKeyPressed(ImGuiKey_Enter)) {
93+
executeGoto = true;
94+
}
8895

89-
editor->setSelection(newAddress, newAddress);
90-
editor->jumpToSelection();
96+
ImGui::BeginDisabled(!m_newAddress.has_value());
97+
{
98+
const auto label = hex::format("{} {}", "hex.builtin.view.hex_editor.menu.file.goto"_lang, m_newAddress.has_value() ? hex::format("0x{:08X}", *m_newAddress) : "???");
99+
const auto buttonWidth = ImGui::GetWindowWidth() - ImGui::GetStyle().WindowPadding.x * 2;
100+
if (ImGuiExt::DimmedButton(label.c_str(), ImVec2(buttonWidth, 0))) {
101+
executeGoto = true;
91102
}
92103
}
104+
ImGui::EndDisabled();
105+
106+
if (executeGoto && m_newAddress.has_value()) {
107+
editor->setSelection(*m_newAddress, *m_newAddress);
108+
editor->jumpToSelection();
109+
}
93110

94111
ImGui::EndTabBar();
95112
}
@@ -104,9 +121,10 @@ namespace hex::plugin::builtin {
104121
};
105122

106123
Mode m_mode = Mode::Absolute;
124+
std::optional<u64> m_newAddress;
107125

108126
bool m_requestFocus = true;
109-
std::string m_input;
127+
std::string m_input = "0x";
110128
wolv::math_eval::MathEvaluator<i128> m_evaluator;
111129
};
112130

@@ -1101,7 +1119,7 @@ namespace hex::plugin::builtin {
11011119
ContentRegistry::Interface::addMenuItem({ "hex.builtin.menu.edit", "hex.builtin.view.hex_editor.menu.edit.resize" }, ICON_VS_ARROW_BOTH, 1700, Shortcut::None,
11021120
[this] {
11031121
auto provider = ImHexApi::Provider::get();
1104-
this->openPopup<PopupResize>(provider->getBaseAddress());
1122+
this->openPopup<PopupResize>(provider->getActualSize());
11051123
},
11061124
[] { return ImHexApi::Provider::isValid() && ImHexApi::Provider::get()->isResizable(); });
11071125

0 commit comments

Comments
 (0)