diff --git a/src/commands.cc b/src/commands.cc index ab791f66..921b5c35 100644 --- a/src/commands.cc +++ b/src/commands.cc @@ -1163,9 +1163,9 @@ struct DisableOption { DisableOption(Context& context, const char* name) : m_option(context.options()[name]), m_prev_value(m_option.get()) - { m_option.set(T{}); } + { m_option.set(T{}, false); } - ~DisableOption() { m_option.set(m_prev_value); } + ~DisableOption() { m_option.set(m_prev_value, false); } private: Option& m_option; diff --git a/src/option_manager.hh b/src/option_manager.hh index 23a801f3..830098f9 100644 --- a/src/option_manager.hh +++ b/src/option_manager.hh @@ -44,7 +44,7 @@ public: virtual ~Option() = default; template const T& get() const; - template void set(const T& val); + template void set(const T& val, bool notify=true); template bool is_of_type() const; virtual String get_as_string() const = 0; @@ -116,12 +116,13 @@ public: TypedOption(OptionManager& manager, const OptionDesc& desc, const T& value) : Option(desc, manager), m_value(value) {} - void set(T value) + void set(T value, bool notify = true) { if (m_value != value) { m_value = std::move(value); - manager().on_option_changed(*this); + if (notify) + manager().on_option_changed(*this); } } const T& get() const { return m_value; } @@ -172,12 +173,12 @@ template const T& Option::get() const return typed_opt->get(); } -template void Option::set(const T& val) +template void Option::set(const T& val, bool notify) { auto* typed_opt = dynamic_cast*>(this); if (not typed_opt) throw runtime_error(format("option '{}' is not of type '{}'", name(), typeid(T).name())); - return typed_opt->set(val); + return typed_opt->set(val, notify); } template bool Option::is_of_type() const