Move is Move

This commit is contained in:
neuecc 2021-08-12 18:04:47 +09:00
parent f8ba09ac23
commit b577d9a226
3 changed files with 38 additions and 14 deletions

View File

@ -12,7 +12,7 @@ namespace ObservableCollections
public enum ChangedKind
{
Add, Remove
Add, Remove, Move
}
public class SynchronizedViewFilter<T, TView> : ISynchronizedViewFilter<T, TView>
@ -96,6 +96,16 @@ namespace ObservableCollections
filter.OnCollectionChanged(ChangedKind.Remove, value, view);
}
internal static void InvokeOnMove<T, TView>(this ISynchronizedViewFilter<T, TView> filter, (T value, TView view) value)
{
InvokeOnMove(filter, value.value, value.view);
}
internal static void InvokeOnMove<T, TView>(this ISynchronizedViewFilter<T, TView> filter, T value, TView view)
{
filter.OnCollectionChanged(ChangedKind.Move, value, view);
}
internal static void InvokeOnAttach<T, TView>(this ISynchronizedViewFilter<T, TView> filter, T value, TView view)
{
if (filter.IsMatch(value, view))

View File

@ -145,7 +145,6 @@ namespace ObservableCollections
}
}
break;
case NotifyCollectionChangedAction.Move:
case NotifyCollectionChangedAction.Replace:
{
if (dict.Remove(e.OldItem.Key, out var oldView))
@ -171,6 +170,7 @@ namespace ObservableCollections
dict.Clear();
}
break;
case NotifyCollectionChangedAction.Move: // ObservableDictionary have no Move operation.
default:
break;
}
@ -295,7 +295,6 @@ namespace ObservableCollections
}
}
break;
case NotifyCollectionChangedAction.Move:
case NotifyCollectionChangedAction.Replace:
{
var k = new KeyValuePair<TKey, TValue>(e.OldItem.Key, e.OldItem.Value);
@ -322,6 +321,7 @@ namespace ObservableCollections
dict.Clear();
}
break;
case NotifyCollectionChangedAction.Move: // ObservableDictionary have no Move operation.
default:
break;
}
@ -454,7 +454,6 @@ namespace ObservableCollections
}
}
break;
case NotifyCollectionChangedAction.Move:
case NotifyCollectionChangedAction.Replace:
{
if (viewMap.Remove(e.OldItem.Key, out var view))
@ -485,6 +484,7 @@ namespace ObservableCollections
viewMap.Clear();
}
break;
case NotifyCollectionChangedAction.Move: // ObservableDictionary have no Move operation.
default:
break;
}

View File

@ -1,9 +1,6 @@
using ObservableCollections.Internal;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Linq;
namespace ObservableCollections
{
@ -211,9 +208,7 @@ namespace ObservableCollections
list.RemoveAt(e.OldStartingIndex);
list.Insert(e.NewStartingIndex, removeItem);
// TODO:???
//filter.InvokeOnRemove(removeItem);
//filter.InvokeOnAdd(v);
filter.InvokeOnMove(removeItem);
}
break;
case NotifyCollectionChangedAction.Reset:
@ -380,9 +375,8 @@ namespace ObservableCollections
}
break;
case NotifyCollectionChangedAction.Replace:
case NotifyCollectionChangedAction.Move:
// ObservableList does not support replace range
// Replace is remove old item and insert new item(same index on replace, difference index on move).
// Replace is remove old item and insert new item.
{
var oldValue = e.OldItem;
list.Remove((oldValue, identitySelector(oldValue)), out var oldView);
@ -396,6 +390,16 @@ namespace ObservableCollections
filter.InvokeOnAdd(value, view);
}
break;
case NotifyCollectionChangedAction.Move:
{
// Move(index change) does not affect sorted list.
var oldValue = e.OldItem;
if (list.TryGetValue((oldValue, identitySelector(oldValue)), out var view))
{
filter.InvokeOnMove(view);
}
}
break;
case NotifyCollectionChangedAction.Reset:
if (!filter.IsNullFilter())
{
@ -593,9 +597,8 @@ namespace ObservableCollections
}
break;
case NotifyCollectionChangedAction.Replace:
case NotifyCollectionChangedAction.Move:
// ObservableList does not support replace range
// Replace is remove old item and insert new item(same index on replace, difference index on move).
// Replace is remove old item and insert new item.
{
var oldValue = e.OldItem;
var oldKey = identitySelector(oldValue);
@ -614,6 +617,17 @@ namespace ObservableCollections
filter.InvokeOnAdd(value, view);
}
break;
case NotifyCollectionChangedAction.Move:
// Move(index change) does not affect soreted dict.
{
var value = e.OldItem;
var key = identitySelector(value);
if (viewMap.TryGetValue(key, out var view))
{
filter.InvokeOnMove(value, view);
}
}
break;
case NotifyCollectionChangedAction.Reset:
if (!filter.IsNullFilter())
{