From 18bc5de169fd17abec2b3c6ac0c68096204fcfa8 Mon Sep 17 00:00:00 2001 From: WerWolv Date: Fri, 12 May 2023 08:38:07 +0200 Subject: [PATCH] fix: Copy-as options not being disabled correctly --- lib/libimhex/include/hex/api/imhex_api.hpp | 5 +++++ lib/libimhex/source/api/imhex_api.cpp | 4 ++++ plugins/builtin/source/content/views/view_hex_editor.cpp | 3 ++- 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/lib/libimhex/include/hex/api/imhex_api.hpp b/lib/libimhex/include/hex/api/imhex_api.hpp index 2ce07414e..bda9213c7 100644 --- a/lib/libimhex/include/hex/api/imhex_api.hpp +++ b/lib/libimhex/include/hex/api/imhex_api.hpp @@ -172,6 +172,11 @@ namespace hex { */ bool isSelectionValid(); + /** + * @brief Clears the current selection in the Hex Editor + */ + void clearSelection(); + /** * @brief Gets the current selection in the Hex Editor * @return The current selection diff --git a/lib/libimhex/source/api/imhex_api.cpp b/lib/libimhex/source/api/imhex_api.cpp index dc1a745c9..54407f3a7 100644 --- a/lib/libimhex/source/api/imhex_api.cpp +++ b/lib/libimhex/source/api/imhex_api.cpp @@ -177,6 +177,10 @@ namespace hex { return impl::s_currentSelection; } + void clearSelection() { + impl::s_currentSelection.reset(); + } + void setSelection(const Region ®ion, prv::Provider *provider) { setSelection(ProviderRegion { region, provider == nullptr ? Provider::get() : provider }); } diff --git a/plugins/builtin/source/content/views/view_hex_editor.cpp b/plugins/builtin/source/content/views/view_hex_editor.cpp index bbff972c5..853a5453d 100644 --- a/plugins/builtin/source/content/views/view_hex_editor.cpp +++ b/plugins/builtin/source/content/views/view_hex_editor.cpp @@ -1043,8 +1043,9 @@ namespace hex::plugin::builtin { auto selection = ImHexApi::HexEditor::getSelection(); auto provider = ImHexApi::Provider::get(); + bool enabled = ImHexApi::HexEditor::isSelectionValid(); for (const auto &[unlocalizedName, callback] : ContentRegistry::DataFormatter::impl::getEntries()) { - if (ImGui::MenuItem(LangEntry(unlocalizedName))) { + if (ImGui::MenuItem(LangEntry(unlocalizedName), nullptr, false, enabled)) { ImGui::SetClipboardText( callback( provider,