diff --git a/lib/libimhex/include/hex/api/event_manager.hpp b/lib/libimhex/include/hex/api/event_manager.hpp index c8b04c9a7..1fc3c253b 100644 --- a/lib/libimhex/include/hex/api/event_manager.hpp +++ b/lib/libimhex/include/hex/api/event_manager.hpp @@ -258,7 +258,6 @@ namespace hex { EVENT_DEF(EventSearchBoxClicked, u32); EVENT_DEF(EventViewOpened, View*); EVENT_DEF(EventFirstLaunch); - EVENT_DEF(EventAnySettingChanged); EVENT_DEF(EventFileDragged, bool); EVENT_DEF(EventFileDropped, std::fs::path); diff --git a/lib/libimhex/source/api/content_registry.cpp b/lib/libimhex/source/api/content_registry.cpp index 79bf0800b..6a9e25665 100644 --- a/lib/libimhex/source/api/content_registry.cpp +++ b/lib/libimhex/source/api/content_registry.cpp @@ -191,6 +191,17 @@ namespace hex { const auto entry = insertOrGetEntry(subCategory->entries, unlocalizedName); entry->widget = std::move(widget); + if (entry->widget != nullptr) { + onChange(unlocalizedCategory, unlocalizedName, [widget = entry->widget.get(), unlocalizedCategory, unlocalizedName](const SettingsValue &) { + try { + auto defaultValue = widget->store(); + widget->load(ContentRegistry::Settings::impl::getSetting(unlocalizedCategory, unlocalizedName, defaultValue)); + widget->onChanged(); + } catch (const std::exception &e) { + log::error("Failed to load setting [{} / {}]: {}", unlocalizedCategory.get(), unlocalizedName.get(), e.what()); + } + }); + } return entry->widget.get(); } @@ -211,8 +222,6 @@ namespace hex { } } } - - EventAnySettingChanged::post(); } } diff --git a/plugins/builtin/source/content/views/view_settings.cpp b/plugins/builtin/source/content/views/view_settings.cpp index 7d367cc94..4b1d622a9 100644 --- a/plugins/builtin/source/content/views/view_settings.cpp +++ b/plugins/builtin/source/content/views/view_settings.cpp @@ -26,7 +26,7 @@ namespace hex::plugin::builtin { this->getWindowOpenState() = true; }); - EventAnySettingChanged::subscribe(this, [] { + EventImHexStartupFinished::subscribe(this, []{ for (const auto &[unlocalizedCategory, unlocalizedDescription, subCategories] : ContentRegistry::Settings::impl::getSettings()) { for (const auto &[unlocalizedSubCategory, entries] : subCategories) { for (const auto &[unlocalizedName, widget] : entries) { @@ -41,13 +41,10 @@ namespace hex::plugin::builtin { } } }); - - EventImHexStartupFinished::subscribe(this, []{ EventAnySettingChanged::post(); }); } ViewSettings::~ViewSettings() { RequestOpenWindow::unsubscribe(this); - EventAnySettingChanged::unsubscribe(this); EventImHexStartupFinished::unsubscribe(this); }