public OptionsViewModel(OptionsPageData data, ObservableValue<IEnumerable<string>> exceptionNames) { _data = data; IgnoredPatterns = new PatternCollectionViewModel(data.Ignored); AllExceptions = exceptionNames.GetObservable(v => new ReadOnlyCollection<ExceptionViewModel>( v.Select(n => new ExceptionViewModel(n, IgnoredPatterns.Selected)).ToArray() )); _exceptionsMatchingIgnored = new ObservableCollection<ExceptionViewModel>(); ExceptionsMatchingIgnored = new ReadOnlyObservableCollection<ExceptionViewModel>(_exceptionsMatchingIgnored); AllExceptions.ValueChanged += (sender, e) => RecalculateExceptionsMatchingIgnored(); IgnoredPatterns.Values.CollectionChanged += (sender, e) => RecalculateExceptionsMatchingIgnored(); var ignoredChangeHandler = (EventHandler) delegate { RecalculateExceptionsMatchingIgnored(); }; IgnoredPatterns.Values.AddHandlers( added => { added.Pattern.ValueChanged += ignoredChangeHandler; added.Enabled.ValueChanged += ignoredChangeHandler; }, removed => { removed.Pattern.ValueChanged -= ignoredChangeHandler; removed.Enabled.ValueChanged -= ignoredChangeHandler; } ); RecalculateExceptionsMatchingIgnored(); }
public OptionsViewModel(OptionsPageData data, ObservableValue <IEnumerable <string> > exceptionNames) { _data = data; IgnoredPatterns = new PatternCollectionViewModel(data.Ignored); AllExceptions = exceptionNames.GetObservable(v => new ReadOnlyCollection <ExceptionViewModel>( v.Select(n => new ExceptionViewModel(n, IgnoredPatterns.Selected)).ToArray() )); _exceptionsMatchingIgnored = new ObservableCollection <ExceptionViewModel>(); ExceptionsMatchingIgnored = new ReadOnlyObservableCollection <ExceptionViewModel>(_exceptionsMatchingIgnored); AllExceptions.ValueChanged += (sender, e) => RecalculateExceptionsMatchingIgnored(); IgnoredPatterns.Values.CollectionChanged += (sender, e) => RecalculateExceptionsMatchingIgnored(); var ignoredChangeHandler = (EventHandler) delegate { RecalculateExceptionsMatchingIgnored(); }; IgnoredPatterns.Values.AddHandlers( added => { added.Pattern.ValueChanged += ignoredChangeHandler; added.Enabled.ValueChanged += ignoredChangeHandler; }, removed => { removed.Pattern.ValueChanged -= ignoredChangeHandler; removed.Enabled.ValueChanged -= ignoredChangeHandler; } ); RecalculateExceptionsMatchingIgnored(); }
public void XmlSettings_CanBeReloaded() { var data = new OptionsPageData { Ignored = { new PatternData(new Regex("test")) } }; var settings = new Dictionary<string, string>(); var writer = MockDictionarySettingsWriter(settings); data.SaveSettingsToXml(writer.Object); var reloaded = new OptionsPageData(); var reader = MockDictionarySettingsReader(settings); reloaded.LoadSettingsFromXml(reader.Object); Assert.Equal( data.Ignored.Select(p => new { Regex = p.Regex.ToString(), p.Enabled }), reloaded.Ignored.Select(p => new { Regex = p.Regex.ToString(), p.Enabled }) ); }