From 1249eb326112a8caa518151f0d82fbb7619938c0 Mon Sep 17 00:00:00 2001 From: WerWolv Date: Sat, 18 Nov 2023 14:34:33 +0100 Subject: [PATCH] impr: Optimize includes in often used header files --- .../include/hex/api/content_registry.hpp | 20 +++++------ lib/libimhex/include/hex/api/imhex_api.hpp | 2 -- lib/libimhex/include/hex/api/keybinding.hpp | 8 ++--- .../include/hex/api/project_file_manager.hpp | 9 +++-- .../include/hex/data_processor/node.hpp | 1 - .../include/hex/helpers/encoding_file.hpp | 2 +- .../include/hex/helpers/http_requests.hpp | 3 -- .../hex/helpers/http_requests_native.hpp | 15 +++++---- lib/libimhex/include/hex/plugin.hpp | 6 ++-- .../include/hex/providers/provider.hpp | 1 - .../include/hex/providers/provider_data.hpp | 7 ++-- lib/libimhex/include/hex/ui/popup.hpp | 2 +- lib/libimhex/include/hex/ui/view.hpp | 3 +- lib/libimhex/source/api/content_registry.cpp | 33 +++++++++++++------ lib/libimhex/source/helpers/fs.cpp | 2 +- .../source/ui/imgui_imhex_extensions.cpp | 1 + .../imgui/include/imgui_impl_opengl3_loader.h | 2 ++ main/gui/source/window/window.cpp | 9 ++--- .../include/content/helpers/diagrams.hpp | 33 ++++++++++--------- .../content/popups/popup_text_input.hpp | 1 + plugins/builtin/include/ui/pattern_drawer.hpp | 2 ++ .../content/command_palette_commands.cpp | 2 +- .../content/communication_interface.cpp | 1 + .../source/content/pl_builtin_functions.cpp | 1 + plugins/builtin/source/content/pl_pragmas.cpp | 1 + .../builtin/source/content/pl_visualizers.cpp | 2 +- .../source/content/settings_entries.cpp | 32 ++++++++++++++---- .../script_loader/source/script_api/v1/ui.cpp | 2 ++ .../providers/process_memory_provider.hpp | 1 + 29 files changed, 123 insertions(+), 81 deletions(-) diff --git a/lib/libimhex/include/hex/api/content_registry.hpp b/lib/libimhex/include/hex/api/content_registry.hpp index c66074080..06fb6c8c6 100644 --- a/lib/libimhex/include/hex/api/content_registry.hpp +++ b/lib/libimhex/include/hex/api/content_registry.hpp @@ -4,8 +4,6 @@ #include #include -#include -#include #include #include @@ -27,6 +25,7 @@ namespace hex { class View; class LanguageDefinition; + class Shortcut; namespace dp { class Node; @@ -625,7 +624,8 @@ namespace hex { struct MenuItem { std::vector unlocalizedNames; - Shortcut shortcut; + std::unique_ptr shortcut; + View *view; MenuCallback callback; EnabledCallback enabledCallback; }; @@ -734,6 +734,9 @@ namespace hex { void addProviderName(const std::string &unlocalizedName); + using ProviderCreationFunction = prv::Provider*(*)(); + void add(const std::string &typeName, ProviderCreationFunction creationFunction); + std::vector &getEntries(); } @@ -747,15 +750,8 @@ namespace hex { void add(bool addToList = true) { auto typeName = T().getTypeName(); - (void)EventManager::subscribe([expectedName = typeName](const std::string &name, bool skipLoadInterface, bool selectProvider, prv::Provider **provider) { - if (name != expectedName) return; - - prv::Provider *newProvider = new T(); - - ImHexApi::Provider::add(newProvider, skipLoadInterface, selectProvider); - - if (provider != nullptr) - *provider = newProvider; + impl::add(typeName, [] -> prv::Provider* { + return new T(); }); if (addToList) diff --git a/lib/libimhex/include/hex/api/imhex_api.hpp b/lib/libimhex/include/hex/api/imhex_api.hpp index 374c89e71..6caa95c7b 100644 --- a/lib/libimhex/include/hex/api/imhex_api.hpp +++ b/lib/libimhex/include/hex/api/imhex_api.hpp @@ -7,8 +7,6 @@ #include #include -#include - #include using ImGuiID = unsigned int; diff --git a/lib/libimhex/include/hex/api/keybinding.hpp b/lib/libimhex/include/hex/api/keybinding.hpp index 9c8db5ca6..81a4c08d5 100644 --- a/lib/libimhex/include/hex/api/keybinding.hpp +++ b/lib/libimhex/include/hex/api/keybinding.hpp @@ -443,12 +443,12 @@ namespace hex { static void resumeShortcuts(); static void pauseShortcuts(); - static std::optional getPreviousShortcut(); + [[nodiscard]] static std::optional getPreviousShortcut(); - static std::vector getGlobalShortcuts(); - static std::vector getViewShortcuts(View *view); + [[nodiscard]] static std::vector getGlobalShortcuts(); + [[nodiscard]] static std::vector getViewShortcuts(View *view); - static void updateShortcut(const Shortcut &oldShortcut, const Shortcut &newShortcut, View *view = nullptr); + [[nodiscard]] static bool updateShortcut(const Shortcut &oldShortcut, const Shortcut &newShortcut, View *view = nullptr); }; } \ No newline at end of file diff --git a/lib/libimhex/include/hex/api/project_file_manager.hpp b/lib/libimhex/include/hex/api/project_file_manager.hpp index ab1808439..2d476db90 100644 --- a/lib/libimhex/include/hex/api/project_file_manager.hpp +++ b/lib/libimhex/include/hex/api/project_file_manager.hpp @@ -1,10 +1,5 @@ #pragma once -#include -#include - -#include -#include #include /** @@ -16,6 +11,10 @@ */ namespace hex { + namespace prv { + class Provider; + } + class ProjectFile { public: struct Handler { diff --git a/lib/libimhex/include/hex/data_processor/node.hpp b/lib/libimhex/include/hex/data_processor/node.hpp index 2ecb04514..f803ec2ee 100644 --- a/lib/libimhex/include/hex/data_processor/node.hpp +++ b/lib/libimhex/include/hex/data_processor/node.hpp @@ -7,7 +7,6 @@ #include #include -#include #include #include diff --git a/lib/libimhex/include/hex/helpers/encoding_file.hpp b/lib/libimhex/include/hex/helpers/encoding_file.hpp index b6e83a7a4..b7ae410bd 100644 --- a/lib/libimhex/include/hex/helpers/encoding_file.hpp +++ b/lib/libimhex/include/hex/helpers/encoding_file.hpp @@ -7,7 +7,7 @@ #include #include -#include +#include namespace hex { diff --git a/lib/libimhex/include/hex/helpers/http_requests.hpp b/lib/libimhex/include/hex/helpers/http_requests.hpp index 01b5591af..076a639c6 100644 --- a/lib/libimhex/include/hex/helpers/http_requests.hpp +++ b/lib/libimhex/include/hex/helpers/http_requests.hpp @@ -7,11 +7,8 @@ #include #include -#include - #include #include -#include #if defined(OS_WEB) #include diff --git a/lib/libimhex/include/hex/helpers/http_requests_native.hpp b/lib/libimhex/include/hex/helpers/http_requests_native.hpp index 866643696..c135695cb 100644 --- a/lib/libimhex/include/hex/helpers/http_requests_native.hpp +++ b/lib/libimhex/include/hex/helpers/http_requests_native.hpp @@ -6,6 +6,9 @@ #include #include +#include + +#include namespace hex { @@ -34,22 +37,22 @@ namespace hex { curl_mime_data_cb(part, file.getSize(), [](char *buffer, size_t size, size_t nitems, void *arg) -> size_t { - auto file = static_cast(arg); + auto handle = static_cast(arg); - return fread(buffer, size, nitems, file); + return fread(buffer, size, nitems, handle); }, [](void *arg, curl_off_t offset, int origin) -> int { - auto file = static_cast(arg); + auto handle = static_cast(arg); - if (fseek(file, offset, origin) != 0) + if (fseek(handle, offset, origin) != 0) return CURL_SEEKFUNC_CANTSEEK; else return CURL_SEEKFUNC_OK; }, [](void *arg) { - auto file = static_cast(arg); + auto handle = static_cast(arg); - fclose(file); + fclose(handle); }, file.getHandle()); curl_mime_filename(part, fileName.c_str()); diff --git a/lib/libimhex/include/hex/plugin.hpp b/lib/libimhex/include/hex/plugin.hpp index ac0c265a0..7dd30cccb 100644 --- a/lib/libimhex/include/hex/plugin.hpp +++ b/lib/libimhex/include/hex/plugin.hpp @@ -1,13 +1,13 @@ #pragma once +#include +#include + #include #include #include -#include -#include - #include #include diff --git a/lib/libimhex/include/hex/providers/provider.hpp b/lib/libimhex/include/hex/providers/provider.hpp index dbc098881..8bcec9ae2 100644 --- a/lib/libimhex/include/hex/providers/provider.hpp +++ b/lib/libimhex/include/hex/providers/provider.hpp @@ -9,7 +9,6 @@ #include #include -#include #include #include diff --git a/lib/libimhex/include/hex/providers/provider_data.hpp b/lib/libimhex/include/hex/providers/provider_data.hpp index 4c5088eb8..444c01bf4 100644 --- a/lib/libimhex/include/hex/providers/provider_data.hpp +++ b/lib/libimhex/include/hex/providers/provider_data.hpp @@ -2,13 +2,16 @@ #include #include -#include #include #include namespace hex { + namespace prv { + class Provider; + } + template class PerProvider { public: @@ -16,7 +19,7 @@ namespace hex { PerProvider(const PerProvider&) = delete; PerProvider(PerProvider&&) = delete; PerProvider& operator=(const PerProvider&) = delete; - PerProvider& operator=(PerProvider&&) = delete; + PerProvider& operator=(PerProvider &&) = delete; PerProvider(T data) : m_data({ { ImHexApi::Provider::get(), std::move(data) } }) { this->onCreate(); } diff --git a/lib/libimhex/include/hex/ui/popup.hpp b/lib/libimhex/include/hex/ui/popup.hpp index 679303f36..71ed7cd2f 100644 --- a/lib/libimhex/include/hex/ui/popup.hpp +++ b/lib/libimhex/include/hex/ui/popup.hpp @@ -8,9 +8,9 @@ #include #include -#include #include +#include namespace hex { diff --git a/lib/libimhex/include/hex/ui/view.hpp b/lib/libimhex/include/hex/ui/view.hpp index 1ad6cf05f..bd490e3c8 100644 --- a/lib/libimhex/include/hex/ui/view.hpp +++ b/lib/libimhex/include/hex/ui/view.hpp @@ -10,6 +10,7 @@ #include #include +#include #include #include #include @@ -19,8 +20,6 @@ #include #include -#include - namespace hex { diff --git a/lib/libimhex/source/api/content_registry.cpp b/lib/libimhex/source/api/content_registry.cpp index 9f0793b2e..225894a22 100644 --- a/lib/libimhex/source/api/content_registry.cpp +++ b/lib/libimhex/source/api/content_registry.cpp @@ -1,4 +1,5 @@ #include +#include #include #include @@ -711,7 +712,7 @@ namespace hex { log::debug("Added new menu item to menu {} with priority {}", wolv::util::combineStrings(unlocalizedMainMenuNames, " -> "), priority); impl::getMenuItems().insert({ - priority, { unlocalizedMainMenuNames, shortcut, function, enabledCallback } + priority, impl::MenuItem { unlocalizedMainMenuNames, std::make_unique(shortcut), view, function, enabledCallback } }); if (shortcut != Shortcut::None) { @@ -727,14 +728,14 @@ namespace hex { unlocalizedMainMenuNames.emplace_back(impl::SubMenuValue); impl::getMenuItems().insert({ - priority, { unlocalizedMainMenuNames, {}, function, enabledCallback } + priority, impl::MenuItem { unlocalizedMainMenuNames, std::make_unique(), nullptr, function, enabledCallback } }); } void addMenuItemSeparator(std::vector unlocalizedMainMenuNames, u32 priority) { unlocalizedMainMenuNames.emplace_back(impl::SeparatorValue); impl::getMenuItems().insert({ - priority, { unlocalizedMainMenuNames, {}, []{}, []{ return true; } } + priority, impl::MenuItem { unlocalizedMainMenuNames, std::make_unique(), nullptr, []{}, []{ return true; } } }); } @@ -803,21 +804,33 @@ namespace hex { namespace ContentRegistry::Provider { - void impl::addProviderName(const std::string &unlocalizedName) { - log::debug("Registered new provider: {}", unlocalizedName); - - getEntries().push_back(unlocalizedName); - } - - namespace impl { + void add(const std::string &typeName, ProviderCreationFunction creationFunction) { + (void)EventManager::subscribe([expectedName = typeName, creationFunction](const std::string &name, bool skipLoadInterface, bool selectProvider, prv::Provider **provider) { + if (name != expectedName) return; + + prv::Provider *newProvider = creationFunction(); + + ImHexApi::Provider::add(newProvider, skipLoadInterface, selectProvider); + + if (provider != nullptr) + *provider = newProvider; + }); + } + std::vector &getEntries() { static std::vector providerNames; return providerNames; } + void addProviderName(const std::string &unlocalizedName) { + log::debug("Registered new provider: {}", unlocalizedName); + + getEntries().push_back(unlocalizedName); + } + } diff --git a/lib/libimhex/source/helpers/fs.cpp b/lib/libimhex/source/helpers/fs.cpp index 3e0734a44..e6feaef0c 100644 --- a/lib/libimhex/source/helpers/fs.cpp +++ b/lib/libimhex/source/helpers/fs.cpp @@ -1,6 +1,6 @@ #include -#include +#include #include #include #include diff --git a/lib/libimhex/source/ui/imgui_imhex_extensions.cpp b/lib/libimhex/source/ui/imgui_imhex_extensions.cpp index 94e4c68f5..11ee03706 100644 --- a/lib/libimhex/source/ui/imgui_imhex_extensions.cpp +++ b/lib/libimhex/source/ui/imgui_imhex_extensions.cpp @@ -2,6 +2,7 @@ #include #include +#include #undef IMGUI_DEFINE_MATH_OPERATORS #define STB_IMAGE_IMPLEMENTATION diff --git a/lib/third_party/imgui/include/imgui_impl_opengl3_loader.h b/lib/third_party/imgui/include/imgui_impl_opengl3_loader.h index 662e83a0e..137dc9c21 100644 --- a/lib/third_party/imgui/include/imgui_impl_opengl3_loader.h +++ b/lib/third_party/imgui/include/imgui_impl_opengl3_loader.h @@ -32,6 +32,8 @@ #ifndef __gl3w_h_ #define __gl3w_h_ +#include + #if __has_include() #include #else diff --git a/main/gui/source/window/window.cpp b/main/gui/source/window/window.cpp index 810cadc5a..ffd51a9c0 100644 --- a/main/gui/source/window/window.cpp +++ b/main/gui/source/window/window.cpp @@ -6,6 +6,7 @@ #include #include #include +#include #include #include @@ -559,8 +560,8 @@ namespace hex { } for (auto &[priority, menuItem] : ContentRegistry::Interface::impl::getMenuItems()) { - const auto &[unlocalizedNames, shortcut, callback, enabledCallback] = menuItem; - createNestedMenu(unlocalizedNames, shortcut, callback, enabledCallback); + const auto &[unlocalizedNames, shortcut, view, callback, enabledCallback] = menuItem; + createNestedMenu(unlocalizedNames, *shortcut, callback, enabledCallback); } }; @@ -790,10 +791,10 @@ namespace hex { // Draw main menu popups for (auto &[priority, menuItem] : ContentRegistry::Interface::impl::getMenuItems()) { - const auto &[unlocalizedNames, shortcut, callback, enabledCallback] = menuItem; + const auto &[unlocalizedNames, shortcut, view, callback, enabledCallback] = menuItem; if (ImGui::BeginPopup(unlocalizedNames.front().c_str())) { - createNestedMenu({ unlocalizedNames.begin() + 1, unlocalizedNames.end() }, shortcut, callback, enabledCallback); + createNestedMenu({ unlocalizedNames.begin() + 1, unlocalizedNames.end() }, *shortcut, callback, enabledCallback); ImGui::EndPopup(); } } diff --git a/plugins/builtin/include/content/helpers/diagrams.hpp b/plugins/builtin/include/content/helpers/diagrams.hpp index 10f8f7d27..a3c7f5795 100644 --- a/plugins/builtin/include/content/helpers/diagrams.hpp +++ b/plugins/builtin/include/content/helpers/diagrams.hpp @@ -5,13 +5,14 @@ #include #include -#include +#include #include + +#include #include #include -#include #include namespace hex { @@ -114,7 +115,8 @@ namespace hex { if (!this->m_processing) for (size_t i = 0; i < (this->m_buffer.empty() ? 0 : this->m_buffer.size() - 1); i++) { - const auto &[x, y] = std::pair { this->m_buffer[i] * xStep, this->m_buffer[i + 1] * yStep }; + auto x = this->m_buffer[i] * xStep; + auto y = this->m_buffer[i + 1] * yStep; auto color = ImLerp(ImColor(0xFF, 0x6D, 0x01).Value, ImColor(0x01, 0x93, 0xFF).Value, float(i) / this->m_buffer.size()) + ImVec4(this->m_glowBuffer[i], this->m_glowBuffer[i], this->m_glowBuffer[i], 0.0F); color.w = this->m_opacity; @@ -209,7 +211,8 @@ namespace hex { if (!this->m_processing) for (size_t i = 0; i < (this->m_buffer.empty() ? 0 : this->m_buffer.size()); i++) { - const auto &[x, y] = std::pair { this->m_buffer[i] * xStep, yStep * ((float(i) / this->m_buffer.size()) * 0xFF) }; + auto x = this->m_buffer[i] * xStep; + auto y = yStep * ((float(i) / this->m_buffer.size()) * 0xFF); auto color = ImLerp(ImColor(0xFF, 0x6D, 0x01).Value, ImColor(0x01, 0x93, 0xFF).Value, float(i) / this->m_buffer.size()) + ImVec4(this->m_glowBuffer[i], this->m_glowBuffer[i], this->m_glowBuffer[i], 0.0F); color.w = this->m_opacity; @@ -549,29 +552,29 @@ namespace hex { // Variables used to store the parameters to process // Chunk's size for entropy analysis - u64 m_chunkSize; - u64 m_startAddress; - u64 m_endAddress; + u64 m_chunkSize = 0; + u64 m_startAddress = 0x00; + u64 m_endAddress = 0x00; // Start / size of the file - u64 m_baseAddress; - u64 m_fileSize; + u64 m_baseAddress = 0x00; + u64 m_fileSize = 0; // The size of the blocks (for diagram drawing) - u64 m_blockSize; + u64 m_blockSize = 0; // Position of the handle inside the plot double m_handlePosition = 0.0; // Hold the number of blocks that have been processed // during the chunk-based entropy analysis - u64 m_blockCount; + u64 m_blockCount = 0; // Hold the number of bytes that have been processed // during the analysis (useful for the iterative analysis) - u64 m_byteCount; + u64 m_byteCount = 0; // Array used to hold the occurrences of each byte // (useful for the iterative analysis) - std::array m_blockValueCounts; + std::array m_blockValueCounts = {}; // Variable to hold the result of the chunk-based // entropy analysis @@ -580,7 +583,7 @@ namespace hex { // Sampling size, number of elements displayed in the plot, // avoid showing to many data because it decreased the frame rate - size_t m_sampleSize; + size_t m_sampleSize = 0; std::atomic m_processing = false; }; @@ -950,7 +953,7 @@ namespace hex { // Array used to hold the occurrences of each byte // (useful for the iterative analysis) - std::array m_blockValueCounts; + std::array m_blockValueCounts = {}; // The m_xBlockTypeDistributions attributes are used to specify the position of // the values in the plot when the Y axis doesn't start at 0 diff --git a/plugins/builtin/include/content/popups/popup_text_input.hpp b/plugins/builtin/include/content/popups/popup_text_input.hpp index 500bc425f..ce4a162ab 100644 --- a/plugins/builtin/include/content/popups/popup_text_input.hpp +++ b/plugins/builtin/include/content/popups/popup_text_input.hpp @@ -2,6 +2,7 @@ #include +#include #include #include diff --git a/plugins/builtin/include/ui/pattern_drawer.hpp b/plugins/builtin/include/ui/pattern_drawer.hpp index 96356817b..ec67803cc 100644 --- a/plugins/builtin/include/ui/pattern_drawer.hpp +++ b/plugins/builtin/include/ui/pattern_drawer.hpp @@ -11,6 +11,8 @@ #include +#include + struct ImGuiTableSortSpecs; namespace hex::plugin::builtin::ui { diff --git a/plugins/builtin/source/content/command_palette_commands.cpp b/plugins/builtin/source/content/command_palette_commands.cpp index b4dfe8abe..d9f81ef42 100644 --- a/plugins/builtin/source/content/command_palette_commands.cpp +++ b/plugins/builtin/source/content/command_palette_commands.cpp @@ -69,7 +69,7 @@ namespace hex::plugin::builtin { if (auto combined = wolv::util::combineStrings(names, " -> "); hex::containsIgnoreCase(combined, input) && !combined.contains(ContentRegistry::Interface::impl::SeparatorValue) && !combined.contains(ContentRegistry::Interface::impl::SubMenuValue)) { result.emplace_back(ContentRegistry::CommandPaletteCommands::impl::QueryResult { std::move(combined), - [entry](const auto&) { entry.callback(); } + [&entry](const auto&) { entry.callback(); } }); } } diff --git a/plugins/builtin/source/content/communication_interface.cpp b/plugins/builtin/source/content/communication_interface.cpp index 8d8412ed5..a4890e263 100644 --- a/plugins/builtin/source/content/communication_interface.cpp +++ b/plugins/builtin/source/content/communication_interface.cpp @@ -1,4 +1,5 @@ #include +#include #include diff --git a/plugins/builtin/source/content/pl_builtin_functions.cpp b/plugins/builtin/source/content/pl_builtin_functions.cpp index f8cbc754e..5c6cab9be 100644 --- a/plugins/builtin/source/content/pl_builtin_functions.cpp +++ b/plugins/builtin/source/content/pl_builtin_functions.cpp @@ -1,3 +1,4 @@ +#include #include #include diff --git a/plugins/builtin/source/content/pl_pragmas.cpp b/plugins/builtin/source/content/pl_pragmas.cpp index 280762e37..c9b4bd94a 100644 --- a/plugins/builtin/source/content/pl_pragmas.cpp +++ b/plugins/builtin/source/content/pl_pragmas.cpp @@ -1,3 +1,4 @@ +#include #include #include #include diff --git a/plugins/builtin/source/content/pl_visualizers.cpp b/plugins/builtin/source/content/pl_visualizers.cpp index 9e0a61944..35b022541 100644 --- a/plugins/builtin/source/content/pl_visualizers.cpp +++ b/plugins/builtin/source/content/pl_visualizers.cpp @@ -2,10 +2,10 @@ #include #include +#include #include #include #include -#include #include #include diff --git a/plugins/builtin/source/content/settings_entries.cpp b/plugins/builtin/source/content/settings_entries.cpp index 5fe0157d6..52c9b710c 100644 --- a/plugins/builtin/source/content/settings_entries.cpp +++ b/plugins/builtin/source/content/settings_entries.cpp @@ -2,6 +2,8 @@ #include #include #include +#include +#include #include #include @@ -190,7 +192,7 @@ namespace hex::plugin::builtin { class KeybindingWidget : public ContentRegistry::Settings::Widgets::Widget { public: - KeybindingWidget(View *view, Shortcut shortcut) : m_view(view), m_shortcut(std::move(shortcut)) {} + KeybindingWidget(View *view, const Shortcut &shortcut) : m_view(view), m_shortcut(shortcut), m_defaultShortcut(shortcut) {} bool draw(const std::string &name) override { std::string label; @@ -203,8 +205,12 @@ namespace hex::plugin::builtin { if (label.empty()) label = "???"; + + if (this->m_hasDuplicate) + ImGui::PushStyleColor(ImGuiCol_Text, ImGuiExt::GetCustomColorVec4(ImGuiCustomCol_LoggerError)); + ImGui::PushID(this); - if (ImGui::Button(label.c_str(), ImVec2(150_scaled, 0))) { + if (ImGui::Button(label.c_str(), ImVec2(250_scaled, 0))) { this->m_editing = !this->m_editing; if (this->m_editing) @@ -212,7 +218,18 @@ namespace hex::plugin::builtin { else ShortcutManager::resumeShortcuts(); } - ImGui::PopID(); + + ImGui::SameLine(); + + if (this->m_hasDuplicate) + ImGui::PopStyleColor(); + + ImGui::BeginDisabled(this->m_shortcut == this->m_defaultShortcut); + if (ImGuiExt::IconButton(ICON_VS_X, ImGui::GetStyleColorVec4(ImGuiCol_Text))) { + this->m_hasDuplicate = !ShortcutManager::updateShortcut(this->m_shortcut, this->m_defaultShortcut, this->m_view); + this->m_shortcut = this->m_defaultShortcut; + } + ImGui::EndDisabled(); if (!ImGui::IsItemHovered() && ImGui::IsMouseClicked(ImGuiMouseButton_Left)) { this->m_editing = false; @@ -223,6 +240,8 @@ namespace hex::plugin::builtin { ImGuiExt::TextFormatted("{}", name); + ImGui::PopID(); + if (this->m_editing) { if (this->detectShortcut()) { this->m_editing = false; @@ -245,7 +264,7 @@ namespace hex::plugin::builtin { return; auto newShortcut = Shortcut(keys); - ShortcutManager::updateShortcut(this->m_shortcut, newShortcut, this->m_view); + this->m_hasDuplicate = !ShortcutManager::updateShortcut(this->m_shortcut, newShortcut, this->m_view); this->m_shortcut = std::move(newShortcut); } @@ -274,7 +293,7 @@ namespace hex::plugin::builtin { } auto newShortcut = Shortcut(std::move(keys)); - ShortcutManager::updateShortcut(this->m_shortcut, newShortcut, this->m_view); + this->m_hasDuplicate = !ShortcutManager::updateShortcut(this->m_shortcut, newShortcut, this->m_view); this->m_shortcut = std::move(newShortcut); return true; @@ -285,8 +304,9 @@ namespace hex::plugin::builtin { private: View *m_view = nullptr; - Shortcut m_shortcut; + Shortcut m_shortcut, m_defaultShortcut; bool m_editing = false; + bool m_hasDuplicate = false; }; } diff --git a/plugins/script_loader/source/script_api/v1/ui.cpp b/plugins/script_loader/source/script_api/v1/ui.cpp index 2802cc2da..25485b88b 100644 --- a/plugins/script_loader/source/script_api/v1/ui.cpp +++ b/plugins/script_loader/source/script_api/v1/ui.cpp @@ -6,6 +6,8 @@ #include +#include + using namespace hex; #define VERSION V1 diff --git a/plugins/windows/include/content/providers/process_memory_provider.hpp b/plugins/windows/include/content/providers/process_memory_provider.hpp index 4b1c790db..78d45a723 100644 --- a/plugins/windows/include/content/providers/process_memory_provider.hpp +++ b/plugins/windows/include/content/providers/process_memory_provider.hpp @@ -10,6 +10,7 @@ #include #include +#include namespace hex::plugin::windows {