This commit is contained in:
neuecc 2024-08-22 17:19:28 +09:00
parent 4aacf11bee
commit abed307158
2 changed files with 23 additions and 31 deletions

View File

@ -81,7 +81,7 @@ namespace ObservableCollections
filteredCount--; filteredCount--;
if (ev != null) if (ev != null)
{ {
ev.Invoke(new SynchronizedViewChangedEventArgs<T, TView>(NotifyCollectionChangedAction.Remove, isMatch, oldValue: value, oldView: view, oldViewIndex: oldIndex)); ev.Invoke(new SynchronizedViewChangedEventArgs<T, TView>(NotifyCollectionChangedAction.Remove, oldValue: value, oldView: view, oldViewIndex: oldIndex));
} }
} }
} }
@ -115,26 +115,31 @@ namespace ObservableCollections
var newMatched = collection.CurrentFilter.IsMatch(value); var newMatched = collection.CurrentFilter.IsMatch(value);
var bothMatched = oldMatched && newMatched; var bothMatched = oldMatched && newMatched;
// TODO:...!
if (bothMatched) if (bothMatched)
{ {
if (ev != null)
{
ev.Invoke(new SynchronizedViewChangedEventArgs<T, TView>(NotifyCollectionChangedAction.Replace, newValue: value, newView: view, oldValue: oldValue, oldView: oldView, newViewIndex: index, oldViewIndex: oldIndex >= 0 ? oldIndex : index));
}
} }
else if (oldMatched) else if (oldMatched)
{ {
// only-old is remove // only-old is remove
filteredCount--;
if (ev != null)
{
ev.Invoke(new SynchronizedViewChangedEventArgs<T, TView>(NotifyCollectionChangedAction.Remove, oldValue: value, oldView: view, oldViewIndex: oldIndex));
}
} }
else if (newMatched) else if (newMatched)
{ {
// only-new is add // only-new is add
} filteredCount++;
if (ev != null)
{
ev.Invoke(new SynchronizedViewChangedEventArgs<T, TView>(NotifyCollectionChangedAction.Add, newValue: value, newView: view, newViewIndex: index));
}
if (ev != null)
{
var isMatch = collection.CurrentFilter.IsMatch(value);
ev.Invoke(new SynchronizedViewChangedEventArgs<T, TView>(NotifyCollectionChangedAction.Replace, isMatch, newValue: value, newView: view, oldValue: oldValue, oldView: oldView, newViewIndex: index, oldViewIndex: oldIndex >= 0 ? oldIndex : index));
} }
} }
@ -143,19 +148,7 @@ namespace ObservableCollections
filteredCount = 0; filteredCount = 0;
if (ev != null) if (ev != null)
{ {
ev.Invoke(new SynchronizedViewChangedEventArgs<T, TView>(NotifyCollectionChangedAction.Reset, true)); ev.Invoke(new SynchronizedViewChangedEventArgs<T, TView>(NotifyCollectionChangedAction.Reset));
}
}
internal static void InvokeOnAttach<T, TView>(this ISynchronizedViewFilter<T, TView> filter, T value, TView view)
{
if (filter.IsMatch(value, view))
{
filter.WhenTrue(value, view);
}
else
{
filter.WhenFalse(value, view);
} }
} }
} }

View File

@ -16,7 +16,7 @@ namespace ObservableCollections
internal sealed class View<TView> : ISynchronizedView<T, TView> internal sealed class View<TView> : ISynchronizedView<T, TView>
{ {
public ISynchronizedViewFilter<T, TView> CurrentFilter public ISynchronizedViewFilter<T> CurrentFilter
{ {
get get
{ {
@ -30,10 +30,9 @@ namespace ObservableCollections
readonly List<(T, TView)> list; readonly List<(T, TView)> list;
int filteredCount; int filteredCount;
ISynchronizedViewFilter<T, TView> filter; ISynchronizedViewFilter<T> filter;
public event Action<SynchronizedViewChangedEventArgs<T, TView>>? ViewChanged; public event Action<SynchronizedViewChangedEventArgs<T, TView>>? ViewChanged;
// public event NotifyCollectionChangedEventHandler<T>? RoutingCollectionChanged;
public event Action<NotifyCollectionChangedAction>? CollectionStateChanged; public event Action<NotifyCollectionChangedAction>? CollectionStateChanged;
public object SyncRoot { get; } public object SyncRoot { get; }
@ -43,7 +42,7 @@ namespace ObservableCollections
this.source = source; this.source = source;
this.selector = selector; this.selector = selector;
this.reverse = reverse; this.reverse = reverse;
this.filter = SynchronizedViewFilter<T, TView>.Null; this.filter = SynchronizedViewFilter<T>.Null;
this.SyncRoot = new object(); this.SyncRoot = new object();
lock (source.SyncRoot) lock (source.SyncRoot)
{ {
@ -64,7 +63,7 @@ namespace ObservableCollections
} }
} }
public void AttachFilter(ISynchronizedViewFilter<T, TView> filter, bool invokeAddEventForCurrentElements = false) public void AttachFilter(ISynchronizedViewFilter<T> filter, bool invokeAddEventForCurrentElements = false)
{ {
lock (SyncRoot) lock (SyncRoot)
{ {
@ -84,11 +83,11 @@ namespace ObservableCollections
} }
} }
public void ResetFilter(Action<T, TView>? resetAction) public void ResetFilter(Action<T>? resetAction)
{ {
lock (SyncRoot) lock (SyncRoot)
{ {
this.filter = SynchronizedViewFilter<T, TView>.Null; this.filter = SynchronizedViewFilter<T>.Null;
if (resetAction != null) if (resetAction != null)
{ {
foreach (var (item, view) in list) foreach (var (item, view) in list)