ObservatoryCore
ObservatoryCore copied to clipboard
Settings improvement: Notify plugins of settings change; mark settings as "requiring read-all to take effect" in settings UI
Related to #121: Today, plugins cannot detect when settings are changed. Furthermore, some settings, may require a read-all to take effect.
Changes requested:
- Add an "OnSettingsChanged" event which provides plugins with an indication that settings have changed and, ideally, provide a before/after values so the plugin can determine what has changed. This would help inform whether a plugin requires a read-all. Ideally, this fires when the settings view for the plugin is closed, not on every individual value change (ie. on every single value change like in a number scroller or something) in order to suppress notifications for intermediate/non-committed values, thereby reducing false-positives.
- Add a setting annotation which plugin authors can use to mark a setting as requiring a read-all if changed. When present, core will render the setting with a visual style which indicates that changing the setting will not take immediate effect. It is a visual indication ONLY. When the plugin receives the new "OnSettingsChanged" event, proposed above, and detects if the setting has in fact changed (because it may have been changed, then changed back), it can set the "RequiresReadAll" property, proposed in #121, in order to request the read-all.
For request 1: This can be accomplished with accessors in your settings class.
e.g.:
class PluginSettings
{
[SettingDisplayName("Cool Setting")]
public bool CoolSetting
{
get => _cool;
set
{
SomethingINeedToDoWhenThisIsChanged();
_cool = value;
}
}
[SettingIgnore]
private bool _cool;
}
A more formal way to be notified of setting value changes would be to implement INotifyPropertyChanged
and the interested parties can subscribe to the PropertyChanged event...