From 2c740cab06505c0970f24ebeb1052a7debcfd178 Mon Sep 17 00:00:00 2001 From: WerWolv Date: Mon, 8 Aug 2022 12:47:49 +0200 Subject: [PATCH] sys: Added select region command --- lib/libimhex/include/hex/api/keybinding.hpp | 4 +- .../source/content/views/view_hex_editor.cpp | 66 +++++++++++++++++-- plugins/builtin/source/lang/de_DE.cpp | 6 ++ plugins/builtin/source/lang/en_US.cpp | 6 ++ plugins/builtin/source/lang/it_IT.cpp | 6 ++ plugins/builtin/source/lang/ja_JP.cpp | 6 ++ plugins/builtin/source/lang/pt_BR.cpp | 6 ++ plugins/builtin/source/lang/zh_CN.cpp | 6 ++ plugins/builtin/source/lang/zh_TW.cpp | 6 ++ 9 files changed, 105 insertions(+), 7 deletions(-) diff --git a/lib/libimhex/include/hex/api/keybinding.hpp b/lib/libimhex/include/hex/api/keybinding.hpp index 449ecfde6..85e89b843 100644 --- a/lib/libimhex/include/hex/api/keybinding.hpp +++ b/lib/libimhex/include/hex/api/keybinding.hpp @@ -181,8 +181,8 @@ namespace hex { static constexpr auto CTRL = Key(static_cast(0x1000'0000)); static constexpr auto ALT = Key(static_cast(0x2000'0000)); - static constexpr auto SHIFT = Key(static_cast(0x3000'0000)); - static constexpr auto SUPER = Key(static_cast(0x4000'0000)); + static constexpr auto SHIFT = Key(static_cast(0x4000'0000)); + static constexpr auto SUPER = Key(static_cast(0x8000'0000)); class ShortcutManager { public: diff --git a/plugins/builtin/source/content/views/view_hex_editor.cpp b/plugins/builtin/source/content/views/view_hex_editor.cpp index 6e5f4ca52..ab67ab008 100644 --- a/plugins/builtin/source/content/views/view_hex_editor.cpp +++ b/plugins/builtin/source/content/views/view_hex_editor.cpp @@ -9,7 +9,6 @@ #include "math_evaluator.hpp" #include -#include #include @@ -20,8 +19,8 @@ namespace hex::plugin::builtin { void draw(ViewHexEditor *editor) override { ImGui::TextUnformatted("hex.builtin.view.hex_editor.menu.file.goto"_lang); - if (ImGui::BeginTabBar("hex.builtin.view.hex_editor.goto.offset.absolute"_lang)) { - if (ImGui::BeginTabItem("Absolute")) { + if (ImGui::BeginTabBar("goto_tabs")) { + if (ImGui::BeginTabItem("hex.builtin.view.hex_editor.goto.offset.absolute"_lang)) { this->m_mode = Mode::Absolute; ImGui::EndTabItem(); } @@ -95,6 +94,53 @@ namespace hex::plugin::builtin { MathEvaluator m_evaluator; }; + class PopupSelect : public ViewHexEditor::Popup { + public: + + void draw(ViewHexEditor *editor) override { + ImGui::TextUnformatted("hex.builtin.view.hex_editor.menu.file.select"_lang); + if (ImGui::BeginTabBar("select_tabs")) { + + if (ImGui::BeginTabItem("hex.builtin.view.hex_editor.select.offset.region"_lang)) { + u64 inputA = this->m_region.getStartAddress(); + u64 inputB = this->m_region.getEndAddress(); + ImGui::InputHexadecimal("hex.builtin.view.hex_editor.select.offset.begin"_lang, &inputA, ImGuiInputTextFlags_AutoSelectAll); + ImGui::InputHexadecimal("hex.builtin.view.hex_editor.select.offset.end"_lang, &inputB, ImGuiInputTextFlags_AutoSelectAll); + + if (inputB < inputA) + inputB = inputA; + + this->m_region = { inputA, (inputB - inputA) + 1 }; + + ImGui::EndTabItem(); + } + + if (ImGui::BeginTabItem("hex.builtin.view.hex_editor.select.offset.size"_lang)) { + u64 inputA = this->m_region.getStartAddress(); + u64 inputB = this->m_region.getSize(); + ImGui::InputHexadecimal("hex.builtin.view.hex_editor.select.offset.begin"_lang, &inputA, ImGuiInputTextFlags_AutoSelectAll); + ImGui::InputHexadecimal("hex.builtin.view.hex_editor.select.offset.size"_lang, &inputB, ImGuiInputTextFlags_AutoSelectAll); + + if (inputB <= 0) + inputB = 1; + + this->m_region = { inputA, inputB }; + ImGui::EndTabItem(); + } + + if (ImGui::Button("hex.builtin.view.hex_editor.select.select"_lang) || (ImGui::IsItemFocused() && (ImGui::IsKeyPressed(ImGuiKey_Enter) || ImGui::IsKeyPressed(ImGuiKey_Enter)))) { + editor->setSelection(this->m_region.getStartAddress(), this->m_region.getEndAddress()); + editor->jumpToSelection(); + } + + ImGui::EndTabBar(); + } + } + + private: + Region m_region = { 0, 1 }; + }; + class PopupFind : public ViewHexEditor::Popup { public: void draw(ViewHexEditor *editor) override { @@ -252,7 +298,7 @@ namespace hex::plugin::builtin { ImGui::TextUnformatted("hex.builtin.view.hex_editor.menu.edit.set_base"_lang); ImGui::InputHexadecimal("##base_address", &this->m_baseAddress); - if (ImGui::IsItemFocused() && ImGui::IsKeyPressed(ImGuiKey_Enter)) { + if (ImGui::IsItemFocused() && (ImGui::IsKeyPressed(ImGuiKey_Enter) || ImGui::IsKeyPressed(ImGuiKey_Enter))) { setBaseAddress(this->m_baseAddress); editor->closePopup(); } @@ -285,7 +331,7 @@ namespace hex::plugin::builtin { ImGui::TextUnformatted("hex.builtin.view.hex_editor.menu.edit.resize"_lang); ImGui::InputHexadecimal("##resize", &this->m_size); - if (ImGui::IsItemFocused() && ImGui::IsKeyPressed(ImGuiKey_Enter)) { + if (ImGui::IsItemFocused() && (ImGui::IsKeyPressed(ImGuiKey_Enter) || ImGui::IsKeyPressed(ImGuiKey_Enter))) { resize(static_cast(this->m_size)); editor->closePopup(); } @@ -1137,6 +1183,12 @@ namespace hex::plugin::builtin { this->setSelection(size_t(0), ImHexApi::Provider::get()->getActualSize()); }); + // Select range + ShortcutManager::addShortcut(this, CTRL + SHIFT + Keys::A, [this] { + if (ImHexApi::Provider::isValid()) + this->openPopup(); + }); + // Remove selection ShortcutManager::addShortcut(this, Keys::Escape, [this] { this->m_selectionStart = InvalidSelection; @@ -1393,6 +1445,10 @@ namespace hex::plugin::builtin { if (ImGui::MenuItem("hex.builtin.view.hex_editor.menu.file.goto"_lang, "CTRL + G", false, providerValid)) { this->openPopup(); } + + if (ImGui::MenuItem("hex.builtin.view.hex_editor.menu.file.select"_lang, "CTRL + SHIFT + A", false, providerValid)) { + this->openPopup(); + } }); diff --git a/plugins/builtin/source/lang/de_DE.cpp b/plugins/builtin/source/lang/de_DE.cpp index e693d20b8..a42c81f0a 100644 --- a/plugins/builtin/source/lang/de_DE.cpp +++ b/plugins/builtin/source/lang/de_DE.cpp @@ -269,6 +269,12 @@ namespace hex::plugin::builtin { { "hex.builtin.view.hex_editor.goto.offset.current", "Momentan" }, { "hex.builtin.view.hex_editor.goto.offset.begin", "Beginn" }, { "hex.builtin.view.hex_editor.goto.offset.end", "Ende" }, + { "hex.builtin.view.hex_editor.menu.file.select", "Auswählen" }, + { "hex.builtin.view.hex_editor.select.offset.region", "Region" }, + { "hex.builtin.view.hex_editor.select.offset.begin", "Beginn" }, + { "hex.builtin.view.hex_editor.select.offset.end", "Ende" }, + { "hex.builtin.view.hex_editor.select.offset.size", "Grösse" }, + { "hex.builtin.view.hex_editor.select.select", "Select" }, { "hex.builtin.view.hex_editor.file.save", "Speichern" }, { "hex.builtin.view.hex_editor.file.save_as", "Speichern unter..." }, { "hex.builtin.view.hex_editor.menu.edit.copy", "Kopieren" }, diff --git a/plugins/builtin/source/lang/en_US.cpp b/plugins/builtin/source/lang/en_US.cpp index c22237acd..7bbcd1021 100644 --- a/plugins/builtin/source/lang/en_US.cpp +++ b/plugins/builtin/source/lang/en_US.cpp @@ -271,6 +271,12 @@ namespace hex::plugin::builtin { { "hex.builtin.view.hex_editor.goto.offset.relative", "Relative" }, { "hex.builtin.view.hex_editor.goto.offset.begin", "Begin" }, { "hex.builtin.view.hex_editor.goto.offset.end", "End" }, + { "hex.builtin.view.hex_editor.menu.file.select", "Select" }, + { "hex.builtin.view.hex_editor.select.offset.region", "Region" }, + { "hex.builtin.view.hex_editor.select.offset.begin", "Begin" }, + { "hex.builtin.view.hex_editor.select.offset.end", "End" }, + { "hex.builtin.view.hex_editor.select.offset.size", "Size" }, + { "hex.builtin.view.hex_editor.select.select", "Select" }, { "hex.builtin.view.hex_editor.menu.file.save", "Save" }, { "hex.builtin.view.hex_editor.menu.file.save_as", "Save As..." }, { "hex.builtin.view.hex_editor.menu.edit.copy", "Copy" }, diff --git a/plugins/builtin/source/lang/it_IT.cpp b/plugins/builtin/source/lang/it_IT.cpp index 69c918bce..9b873c020 100644 --- a/plugins/builtin/source/lang/it_IT.cpp +++ b/plugins/builtin/source/lang/it_IT.cpp @@ -272,6 +272,12 @@ namespace hex::plugin::builtin { //{ "hex.builtin.view.hex_editor.goto.offset.current", "Relative" }, { "hex.builtin.view.hex_editor.goto.offset.begin", "Inizo" }, { "hex.builtin.view.hex_editor.goto.offset.end", "Fine" }, + //{ "hex.builtin.view.hex_editor.menu.file.select", "Select" }, + // { "hex.builtin.view.hex_editor.select.offset.region", "Region" }, + // { "hex.builtin.view.hex_editor.select.offset.begin", "Begin" }, + // { "hex.builtin.view.hex_editor.select.offset.end", "End" }, + // { "hex.builtin.view.hex_editor.select.offset.size", "Size" }, + // { "hex.builtin.view.hex_editor.select.select", "Select" }, { "hex.builtin.view.hex_editor.menu.file.save", "Salva" }, { "hex.builtin.view.hex_editor.menu.file.save_as", "Salva come..." }, { "hex.builtin.view.hex_editor.menu.edit.copy", "Copia" }, diff --git a/plugins/builtin/source/lang/ja_JP.cpp b/plugins/builtin/source/lang/ja_JP.cpp index 3b2a2487b..6550667e9 100644 --- a/plugins/builtin/source/lang/ja_JP.cpp +++ b/plugins/builtin/source/lang/ja_JP.cpp @@ -271,6 +271,12 @@ namespace hex::plugin::builtin { { "hex.builtin.view.hex_editor.goto.offset.relative", "相対アドレス" }, { "hex.builtin.view.hex_editor.goto.offset.begin", "開始" }, //? { "hex.builtin.view.hex_editor.goto.offset.end", "終了" }, //? + //{ "hex.builtin.view.hex_editor.menu.file.select", "Select" }, + // { "hex.builtin.view.hex_editor.select.offset.region", "Region" }, + // { "hex.builtin.view.hex_editor.select.offset.begin", "Begin" }, + // { "hex.builtin.view.hex_editor.select.offset.end", "End" }, + // { "hex.builtin.view.hex_editor.select.offset.size", "Size" }, + // { "hex.builtin.view.hex_editor.select.select", "Select" }, { "hex.builtin.view.hex_editor.menu.file.save", "保存" }, { "hex.builtin.view.hex_editor.menu.file.save_as", "名前をつけて保存…" }, { "hex.builtin.view.hex_editor.menu.edit.copy", "コピー" }, diff --git a/plugins/builtin/source/lang/pt_BR.cpp b/plugins/builtin/source/lang/pt_BR.cpp index 9bf852e5f..ba541327a 100644 --- a/plugins/builtin/source/lang/pt_BR.cpp +++ b/plugins/builtin/source/lang/pt_BR.cpp @@ -269,6 +269,12 @@ namespace hex::plugin::builtin { { "hex.builtin.view.hex_editor.goto.offset.relative", "Relativo" }, { "hex.builtin.view.hex_editor.goto.offset.begin", "Começo" }, { "hex.builtin.view.hex_editor.goto.offset.end", "Fim" }, + //{ "hex.builtin.view.hex_editor.menu.file.select", "Select" }, + // { "hex.builtin.view.hex_editor.select.offset.region", "Region" }, + // { "hex.builtin.view.hex_editor.select.offset.begin", "Begin" }, + // { "hex.builtin.view.hex_editor.select.offset.end", "End" }, + // { "hex.builtin.view.hex_editor.select.offset.size", "Size" }, + // { "hex.builtin.view.hex_editor.select.select", "Select" }, { "hex.builtin.view.hex_editor.menu.file.save", "Salvar" }, { "hex.builtin.view.hex_editor.menu.file.save_as", "Salvar como..." }, { "hex.builtin.view.hex_editor.menu.edit.copy", "Copiar" }, diff --git a/plugins/builtin/source/lang/zh_CN.cpp b/plugins/builtin/source/lang/zh_CN.cpp index 6c59bd025..741ff4e02 100644 --- a/plugins/builtin/source/lang/zh_CN.cpp +++ b/plugins/builtin/source/lang/zh_CN.cpp @@ -272,6 +272,12 @@ namespace hex::plugin::builtin { { "hex.builtin.view.hex_editor.goto.offset.relative", "相对" }, { "hex.builtin.view.hex_editor.goto.offset.begin", "起始" }, { "hex.builtin.view.hex_editor.goto.offset.end", "末尾" }, + //{ "hex.builtin.view.hex_editor.menu.file.select", "Select" }, + // { "hex.builtin.view.hex_editor.select.offset.region", "Region" }, + // { "hex.builtin.view.hex_editor.select.offset.begin", "Begin" }, + // { "hex.builtin.view.hex_editor.select.offset.end", "End" }, + // { "hex.builtin.view.hex_editor.select.offset.size", "Size" }, + // { "hex.builtin.view.hex_editor.select.select", "Select" }, { "hex.builtin.view.hex_editor.menu.file.save", "保存" }, { "hex.builtin.view.hex_editor.menu.file.save_as", "另存为..." }, { "hex.builtin.view.hex_editor.menu.edit.copy", "复制" }, diff --git a/plugins/builtin/source/lang/zh_TW.cpp b/plugins/builtin/source/lang/zh_TW.cpp index 2e58557f0..f176e6337 100644 --- a/plugins/builtin/source/lang/zh_TW.cpp +++ b/plugins/builtin/source/lang/zh_TW.cpp @@ -269,6 +269,12 @@ namespace hex::plugin::builtin { { "hex.builtin.view.hex_editor.goto.offset.relative", "相對" }, { "hex.builtin.view.hex_editor.goto.offset.begin", "開始" }, { "hex.builtin.view.hex_editor.goto.offset.end", "結束" }, + //{ "hex.builtin.view.hex_editor.menu.file.select", "Select" }, + // { "hex.builtin.view.hex_editor.select.offset.region", "Region" }, + // { "hex.builtin.view.hex_editor.select.offset.begin", "Begin" }, + // { "hex.builtin.view.hex_editor.select.offset.end", "End" }, + // { "hex.builtin.view.hex_editor.select.offset.size", "Size" }, + // { "hex.builtin.view.hex_editor.select.select", "Select" }, { "hex.builtin.view.hex_editor.menu.file.save", "儲存" }, { "hex.builtin.view.hex_editor.menu.file.save_as", "另存為..." }, { "hex.builtin.view.hex_editor.menu.edit.copy", "複製" },