From ccb8684c01cac7b8fdb6a201ff6ef2c7ec53f6a6 Mon Sep 17 00:00:00 2001 From: WerWolv Date: Sat, 21 Oct 2023 15:30:37 +0200 Subject: [PATCH] feat: Add back Windows-specific settings --- lib/libimhex/source/api/content_registry.cpp | 1 - main/gui/source/init/tasks.cpp | 2 +- .../source/content/settings_entries.cpp | 33 ++++++++----------- 3 files changed, 15 insertions(+), 21 deletions(-) diff --git a/lib/libimhex/source/api/content_registry.cpp b/lib/libimhex/source/api/content_registry.cpp index 0bb6e5452cd51..2bdb817dcba4c 100644 --- a/lib/libimhex/source/api/content_registry.cpp +++ b/lib/libimhex/source/api/content_registry.cpp @@ -156,7 +156,6 @@ namespace hex { entry->widget = std::move(widget); entry->widget->load(getSetting(unlocalizedCategory, unlocalizedName, entry->widget->store())); - return entry->widget.get(); } diff --git a/main/gui/source/init/tasks.cpp b/main/gui/source/init/tasks.cpp index f2f47aa09166d..8cea336829376 100644 --- a/main/gui/source/init/tasks.cpp +++ b/main/gui/source/init/tasks.cpp @@ -586,7 +586,7 @@ namespace hex::init { return true; } - // run all exit taks, and print to console + // Run all exit tasks, and print to console void runExitTasks() { for (const auto &[name, task, async] : init::getExitTasks()) { task(); diff --git a/plugins/windows/source/content/settings_entries.cpp b/plugins/windows/source/content/settings_entries.cpp index 3f65fb7e0e8cc..c6bf8b3c86995 100644 --- a/plugins/windows/source/content/settings_entries.cpp +++ b/plugins/windows/source/content/settings_entries.cpp @@ -13,7 +13,7 @@ namespace hex::plugin::windows { namespace { - /*constexpr auto ImHexContextMenuKey = R"(Software\Classes\*\shell\ImHex)"; + constexpr auto ImHexContextMenuKey = R"(Software\Classes\*\shell\ImHex)"; void addImHexContextMenuEntry() { // Create ImHex Root Key @@ -21,13 +21,13 @@ namespace hex::plugin::windows { RegCreateKeyExA(HKEY_CURRENT_USER, ImHexContextMenuKey, 0x00, nullptr, REG_OPTION_NON_VOLATILE, KEY_SET_VALUE, nullptr, &imHexRootKey, nullptr); RegSetValueA(imHexRootKey, nullptr, REG_SZ, "Open with ImHex", 0x00); - // Add Icon key to use first icon embedded in exe + // Add 'Icon' key to use first icon embedded in exe std::array imHexPath = { 0 }; GetModuleFileNameA(nullptr, imHexPath.data(), imHexPath.size()); auto iconValue = hex::format(R"("{}",0)", imHexPath.data()); RegSetKeyValueA(imHexRootKey, nullptr, "Icon", REG_SZ, iconValue.c_str(), iconValue.size() + 1); - // Add command key to pass file path as first argument to ImHex + // Add 'command' key to pass the right-clicked file path as first argument to ImHex auto commandValue = hex::format(R"("{}" "%1")", imHexPath.data()); RegSetValueA(imHexRootKey, "command", REG_SZ, commandValue.c_str(), commandValue.size() + 1); RegCloseKey(imHexRootKey); @@ -43,7 +43,7 @@ namespace hex::plugin::windows { RegCloseKey(key); return keyExists; - }*/ + } } @@ -51,24 +51,19 @@ namespace hex::plugin::windows { /* General */ - /*ContentRegistry::Settings::add("hex.builtin.setting.general", "hex.builtin.setting.general.context_menu_entry", 0, [](auto name, nlohmann::json &setting) { - static bool enabled = hasImHexContextMenuEntry(); - - if (ImGui::Checkbox(name.data(), &enabled)) { - - if (enabled) - addImHexContextMenuEntry(); - else - removeImHexContextMenuEntry(); + namespace Widgets = ContentRegistry::Settings::Widgets; - enabled = hasImHexContextMenuEntry(); - setting = enabled; + ContentRegistry::Settings::add("hex.builtin.setting.general", "", "hex.builtin.setting.general.context_menu_entry", false) + .setChangedCallback([](auto &widget) { + auto checked = static_cast(widget).isChecked(); - return true; - } + if (checked) + addImHexContextMenuEntry(); + else + removeImHexContextMenuEntry(); - return false; - });*/ + widget.load(hasImHexContextMenuEntry()); + }); } } \ No newline at end of file