Disable notifications when disabling an option temporarly
This commit is contained in:
parent
58101645ab
commit
ea02467564
|
@ -1163,9 +1163,9 @@ struct DisableOption {
|
|||
DisableOption(Context& context, const char* name)
|
||||
: m_option(context.options()[name]),
|
||||
m_prev_value(m_option.get<T>())
|
||||
{ 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;
|
||||
|
|
|
@ -44,7 +44,7 @@ public:
|
|||
virtual ~Option() = default;
|
||||
|
||||
template<typename T> const T& get() const;
|
||||
template<typename T> void set(const T& val);
|
||||
template<typename T> void set(const T& val, bool notify=true);
|
||||
template<typename T> bool is_of_type() const;
|
||||
|
||||
virtual String get_as_string() const = 0;
|
||||
|
@ -116,11 +116,12 @@ 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);
|
||||
if (notify)
|
||||
manager().on_option_changed(*this);
|
||||
}
|
||||
}
|
||||
|
@ -172,12 +173,12 @@ template<typename T> const T& Option::get() const
|
|||
return typed_opt->get();
|
||||
}
|
||||
|
||||
template<typename T> void Option::set(const T& val)
|
||||
template<typename T> void Option::set(const T& val, bool notify)
|
||||
{
|
||||
auto* typed_opt = dynamic_cast<TypedOption<T>*>(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<typename T> bool Option::is_of_type() const
|
||||
|
|
Loading…
Reference in New Issue
Block a user