Skip to content

Commit a2688d2

Browse files
committed
Add option to apply temporary config changes.
1 parent 489038e commit a2688d2

File tree

2 files changed

+20
-4
lines changed

2 files changed

+20
-4
lines changed

librecomp/include/librecomp/config.hpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -296,6 +296,10 @@ namespace recomp {
296296
add_option_hidden_dependency(dependent_option_id, source_option_id, values);
297297
};
298298

299+
// Apply any temporary values to the option.
300+
void apply_option_value(const ConfigOption &option);
301+
void apply_option_value(const std::string &option_id);
302+
299303
bool load_config(std::function<bool(nlohmann::json &)> validate_callback = nullptr);
300304
bool save_config();
301305
bool save_config_json(nlohmann::json config_json) const;

librecomp/src/config.cpp

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -409,13 +409,25 @@ bool Config::save_config_json(nlohmann::json config_json) const {
409409
return result;
410410
}
411411

412+
void Config::apply_option_value(const ConfigOption &option) {
413+
ConfigValueVariant prev_value = get_option_value(option.id);
414+
ConfigValueVariant cur_value = get_temp_option_value(option.id);
415+
storage.value_map[option.id] = cur_value;
416+
try_call_option_change_callback(option.id, cur_value, prev_value, OptionChangeContext::Permanent);
417+
}
418+
419+
void Config::apply_option_value(const std::string &option_id) {
420+
auto option_by_id_it = schema.options_by_id.find(option_id);
421+
if (option_by_id_it != schema.options_by_id.end()) {
422+
apply_option_value(schema.options[option_by_id_it->second]);
423+
modified_options.erase(option_by_id_it->second);
424+
}
425+
}
426+
412427
bool Config::save_config() {
413428
if (requires_confirmation) {
414429
for (const auto& option : schema.options) {
415-
ConfigValueVariant prev_value = get_option_value(option.id);
416-
ConfigValueVariant cur_value = get_temp_option_value(option.id);
417-
storage.value_map[option.id] = cur_value;
418-
try_call_option_change_callback(option.id, cur_value, prev_value, OptionChangeContext::Permanent);
430+
apply_option_value(option);
419431
}
420432

421433
modified_options.clear();

0 commit comments

Comments
 (0)