impr: Save most of the hex editor settings

#2398
This commit is contained in:
WerWolv
2025-08-11 21:03:18 +02:00
parent e9d95c78f6
commit 09b2e20a3d
5 changed files with 125 additions and 4 deletions

View File

@@ -37,7 +37,13 @@ namespace hex {
OnChangeCallback callback;
};
struct OnSave {
u64 id;
OnSaveCallback callback;
};
static AutoReset<std::map<std::string, std::map<std::string, std::vector<OnChange>>>> s_onChangeCallbacks;
static AutoReset<std::vector<OnSave>> s_onSaveCallbacks;
static void runAllOnChangeCallbacks() {
for (const auto &[category, rest] : *impl::s_onChangeCallbacks) {
@@ -152,6 +158,20 @@ namespace hex {
}
void store() {
thread_local bool isRunningCallbacks = false;
if (isRunningCallbacks)
return;
isRunningCallbacks = true;
for (const auto &[id, callback] : *s_onSaveCallbacks) {
try {
callback();
} catch (const std::exception &e) {
log::error("Failed to run onSave handler for setting: {}", e.what());
}
}
isRunningCallbacks = false;
if (!s_settings.isValid())
return;
@@ -281,6 +301,16 @@ namespace hex {
}
}
u64 onSave(const OnSaveCallback &callback) {
static u64 id = 1;
impl::s_onSaveCallbacks->emplace_back(id, callback);
auto result = id;
id += 1;
return result;
}
namespace Widgets {
bool Checkbox::draw(const std::string &name) {