impr: Rewrote entire settings API and UI (#1378)

This commit is contained in:
Nik
2023-10-21 23:07:33 +02:00
committed by GitHub
parent f114239f51
commit 7fe9a768d4
26 changed files with 818 additions and 781 deletions

View File

@@ -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<char, MAX_PATH> 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);
@@ -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();
namespace Widgets = ContentRegistry::Settings::Widgets;
if (ImGui::Checkbox(name.data(), &enabled)) {
ContentRegistry::Settings::add<Widgets::Checkbox>("hex.builtin.setting.general", "", "hex.builtin.setting.general.context_menu_entry", false)
.setChangedCallback([](auto &widget) {
auto checked = static_cast<Widgets::Checkbox &>(widget).isChecked();
if (enabled)
addImHexContextMenuEntry();
else
removeImHexContextMenuEntry();
if (checked)
addImHexContextMenuEntry();
else
removeImHexContextMenuEntry();
enabled = hasImHexContextMenuEntry();
setting = enabled;
return true;
}
return false;
});
widget.load(hasImHexContextMenuEntry());
});
}
}