fix: Only update widgets of settings that were changed
Fixed crashing on exit and speeds up settings writes
This commit is contained in:
parent
9303025427
commit
5fcb737559
@ -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);
|
||||
|
@ -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();
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user