reworking
This commit is contained in:
parent
998f74c18d
commit
ffa8a97e35
@ -37,6 +37,9 @@ namespace ObservableCollections
|
|||||||
object SyncRoot { get; }
|
object SyncRoot { get; }
|
||||||
ISynchronizedViewFilter<T, TView> CurrentFilter { get; }
|
ISynchronizedViewFilter<T, TView> CurrentFilter { get; }
|
||||||
|
|
||||||
|
// TODO: add
|
||||||
|
event Action<SynchronizedViewChangedEventArgs<T,TView>>? ViewChanged;
|
||||||
|
// TODO: remove
|
||||||
event NotifyCollectionChangedEventHandler<T>? RoutingCollectionChanged;
|
event NotifyCollectionChangedEventHandler<T>? RoutingCollectionChanged;
|
||||||
event Action<NotifyCollectionChangedAction>? CollectionStateChanged;
|
event Action<NotifyCollectionChangedAction>? CollectionStateChanged;
|
||||||
|
|
||||||
|
@ -12,75 +12,62 @@ namespace ObservableCollections.Internal
|
|||||||
{
|
{
|
||||||
readonly ISynchronizedView<T, TView> parent;
|
readonly ISynchronizedView<T, TView> parent;
|
||||||
readonly List<TView> listView;
|
readonly List<TView> listView;
|
||||||
readonly Func<T, TView> selector;
|
|
||||||
|
|
||||||
public SynchronizedViewList(ISynchronizedView<T, TView> parent, Func<T, TView> selector)
|
public SynchronizedViewList(ISynchronizedView<T, TView> parent)
|
||||||
{
|
{
|
||||||
this.parent = parent;
|
this.parent = parent;
|
||||||
this.selector = selector;
|
// TODO:add
|
||||||
parent.RoutingCollectionChanged += Parent_RoutingCollectionChanged; // TODO: -=
|
parent.ViewChanged += Parent_ViewChanged;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void Parent_RoutingCollectionChanged(in NotifyCollectionChangedEventArgs<T> e)
|
private void Parent_ViewChanged(SynchronizedViewChangedEventArgs<T, TView> e)
|
||||||
{
|
{
|
||||||
// call in parent.lock.
|
// event is called inside lock(parent.SyncRoot)
|
||||||
|
// TODO: invoke in ICollectionEventDispatcher?
|
||||||
|
|
||||||
switch (e.Action)
|
switch (e.Action)
|
||||||
{
|
{
|
||||||
case NotifyCollectionChangedAction.Add:
|
case NotifyCollectionChangedAction.Add: // Add or Insert
|
||||||
if (e.IsSingleItem)
|
if (e.NewViewIndex == -1)
|
||||||
{
|
{
|
||||||
// parent.CurrentFilter.IsMatch(
|
listView.Add(e.NewView);
|
||||||
|
|
||||||
var item = selector(e.NewItem);
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if (e.NewStartingIndex != -1)
|
|
||||||
{
|
|
||||||
listView.Insert(e.NewStartingIndex, selector(e.NewItem));
|
|
||||||
}
|
|
||||||
else // dict is -1
|
|
||||||
{
|
|
||||||
listView.Add(selector(e.NewItem));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (e.NewStartingIndex != -1)
|
listView.Insert(e.NewViewIndex, e.NewView);
|
||||||
{
|
|
||||||
var array = ArrayPool<TView>.Shared.Rent(e.NewItems.Length);
|
|
||||||
try
|
|
||||||
{
|
|
||||||
var i = 0;
|
|
||||||
foreach (var item in e.NewItems)
|
|
||||||
{
|
|
||||||
array[i++] = selector(item);
|
|
||||||
}
|
}
|
||||||
|
break;
|
||||||
listView.InsertRange(e.NewStartingIndex, array.Take(e.NewItems.Length));
|
case NotifyCollectionChangedAction.Remove: // Remove
|
||||||
}
|
if (e.OldViewIndex == -1) // can't gurantee correct remove if index is not provided
|
||||||
finally
|
|
||||||
{
|
{
|
||||||
ArrayPool<TView>.Shared.Return(array, true);
|
listView.Remove(e.OldView);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
foreach (var item in e.NewItems)
|
listView.RemoveAt(e.OldViewIndex);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case NotifyCollectionChangedAction.Replace: // Indexer
|
||||||
|
if (e.NewViewIndex == -1)
|
||||||
{
|
{
|
||||||
listView.Add(selector(item));
|
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
listView[e.NewViewIndex] = e.NewView;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
case NotifyCollectionChangedAction.Move: //Remove and Insert
|
||||||
|
if (e.NewViewIndex == -1)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
listView.RemoveAt(e.OldViewIndex);
|
||||||
|
listView.Insert(e.NewViewIndex, e.NewView);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case NotifyCollectionChangedAction.Remove:
|
case NotifyCollectionChangedAction.Reset: // Clear
|
||||||
break;
|
|
||||||
case NotifyCollectionChangedAction.Replace:
|
|
||||||
break;
|
|
||||||
case NotifyCollectionChangedAction.Move:
|
|
||||||
break;
|
|
||||||
case NotifyCollectionChangedAction.Reset:
|
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
@ -89,6 +76,7 @@ namespace ObservableCollections.Internal
|
|||||||
// throw new NotImplementedException();
|
// throw new NotImplementedException();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public TView this[int index] => throw new NotImplementedException();
|
public TView this[int index] => throw new NotImplementedException();
|
||||||
|
|
||||||
public int Count => throw new NotImplementedException();
|
public int Count => throw new NotImplementedException();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user