diff --git a/src/Models/CodexProperties/CodexProperty.cs b/src/Models/CodexProperties/CodexProperty.cs index 6d17ef8..5dbf314 100644 --- a/src/Models/CodexProperties/CodexProperty.cs +++ b/src/Models/CodexProperties/CodexProperty.cs @@ -1,13 +1,14 @@ using CommunityToolkit.Mvvm.ComponentModel; using COMPASS.Tools; using COMPASS.ViewModels.Sources; +using System; using System.Collections.Generic; using System.Collections.ObjectModel; using System.Linq; namespace COMPASS.Models.CodexProperties { - public abstract class CodexProperty : ObservableObject + public abstract class CodexProperty : ObservableObject, IDisposable { protected CodexProperty(string propName, string? label = null) { @@ -15,8 +16,14 @@ protected CodexProperty(string propName, string? label = null) Label = label ?? propName; _defaultSourcePriority = GetDefaultSources(propName); UpdateSources(); + + SourcePriorityNamed = new(SourcePriority.Select(source => new NamedMetaDataSource(source))); + SourcePriorityNamed.CollectionChanged += SourcePriorityNamed_CollectionChanged; } + private void SourcePriorityNamed_CollectionChanged(object? sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e) + => SourcePriority = SourcePriorityNamed.Select(spn => spn.Source).ToList(); + #region Properties public string Name { get; init; } @@ -45,12 +52,10 @@ protected CodexProperty(string propName, string? label = null) private readonly List _defaultSourcePriority; - private ObservableCollection? _sourcePriorityNamed; /// /// Ordered List of sources that can set this prop, named for data binding /// - public ObservableCollection SourcePriorityNamed => - _sourcePriorityNamed ??= new(SourcePriority.Select(source => new NamedMetaDataSource(source))); + public ObservableCollection SourcePriorityNamed { get; } private List _sourcePriority = new(); /// @@ -176,6 +181,7 @@ public void UpdateSources() }, _ => new(), }; + public void Dispose() => SourcePriorityNamed.CollectionChanged -= SourcePriorityNamed_CollectionChanged; #endregion } diff --git a/src/ViewModels/FilterViewModel.cs b/src/ViewModels/FilterViewModel.cs index c61da4a..1a5775e 100644 --- a/src/ViewModels/FilterViewModel.cs +++ b/src/ViewModels/FilterViewModel.cs @@ -176,7 +176,7 @@ public CodexProperty SelectedNotEmptyProperty } } - public List PossibleEmptyProperties { get; } = new() + public static List PossibleEmptyProperties { get; } = new() { CodexProperty.GetInstance(nameof(Codex.Authors))!, CodexProperty.GetInstance(nameof(Codex.CoverArt))!,