private static void UpdateFilterItems(OrderedListInternal <int, T> filterCollection, int index, int value) { if (filterCollection.Count == 0) { return; } int start = filterCollection.IndexOfKey(index); if (start == -1) { if (filterCollection.Keys[filterCollection.Count - 1] < index) { return; } for (int i = 0; i < filterCollection.Count; i++) { int key = filterCollection.Keys[i]; if (key < index) { continue; } filterCollection.Keys[i] = key + value; } return; } for (int i = start; i < filterCollection.Count; i++) { filterCollection.Keys[i] += value; } }
public OrderedListInternal(OrderedListInternal <TKey, TValue> list) { KeysInternal = list.KeysInternal.ToArrayEx(); ValuesInternal = list.ValuesInternal.ToArrayEx(); Size = list.Size; Comparer = list.Comparer; }
protected override void InitializePendingChanges() { base.InitializePendingChanges(); if (_filter != null && _snapshotFilterCollection == null) { _snapshotFilterCollection = new OrderedListInternal <int, T>(_filterCollection); } }
private void UpdateItem(OrderedListInternal <int, T> filterCollection, NotifyCollectionChangedEventArgs e, NotificationType notificationType) { int filterIndex; switch (e.Action) { case NotifyCollectionChangedAction.Add: var item = (T)e.NewItems[0]; UpdateFilterItems(filterCollection, e.NewStartingIndex, 1); if (!_filter(item)) { return; } filterIndex = filterCollection.Add(e.NewStartingIndex, item); OnCollectionChanged(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Add, item, filterIndex), notificationType); break; case NotifyCollectionChangedAction.Remove: filterIndex = filterCollection.IndexOfKey(e.OldStartingIndex); UpdateFilterItems(filterCollection, e.OldStartingIndex, -1); if (filterIndex == -1) { return; } filterCollection.RemoveAt(filterIndex); OnCollectionChanged(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Remove, e.OldItems[0], filterIndex), notificationType); break; case NotifyCollectionChangedAction.Replace: filterIndex = filterCollection.IndexOfKey(e.NewStartingIndex); if (filterIndex == -1) { return; } var newItem = (T)e.NewItems[0]; if (_filter(newItem)) { T oldItem = filterCollection.GetValue(filterIndex); filterCollection.Values[filterIndex] = newItem; OnCollectionChanged(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Replace, e.NewItems[0], oldItem, filterIndex), notificationType); } else { T oldValue = filterCollection.GetValue(filterIndex); filterCollection.RemoveAt(filterIndex); OnCollectionChanged(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Remove, oldValue, filterIndex), notificationType); } break; default: UpdateFilterInternal(filterCollection, _filter, notificationType); break; } }
/// <summary> /// Initializes default values. /// </summary> protected override void OnInitialized() { base.OnInitialized(); var syncronizedNotifiableCollection = Items as SynchronizedNotifiableCollection <T>; if (syncronizedNotifiableCollection != null) { syncronizedNotifiableCollection.ExecutionMode = Models.ExecutionMode.None; } _filterCollection = new OrderedListInternal <int, T>(); _notifyCollectionChanged = Items as INotifyCollectionChanged; _notifyCollectionChanging = Items as INotifyCollectionChanging; if (_notifyCollectionChanged != null) { _notifyCollectionChanged.CollectionChanged += OnSourceCollectionChanged; } }
private void UpdateFilterInternal(OrderedListInternal <int, T> filterCollection, FilterDelegate <T> filter, NotificationType notificationType) { var currentFilter = filter; filterCollection.Clear(); var items = GetItems(); if (currentFilter != null) { for (var index = 0; index < items.Count; index++) { var item = items[index]; if (currentFilter(item)) { filterCollection.Add(index, item); } } } OnCollectionChanged(Empty.ResetEventArgs, notificationType); }
protected override IList <T> OnItemsChanged(IList <T> items) { _filterCollection = new OrderedListInternal <int, T>(); var notifiableCollection = items as INotifiableCollection; if (notifiableCollection == null) { var notifyCollectionChanged = items as INotifyCollectionChanged; if (notifyCollectionChanged != null) { _isSourceNotifiable = true; notifyCollectionChanged.CollectionChanged += OnSourceCollectionChangedUnsafe; } } else { _isSourceNotifiable = true; notifiableCollection.CollectionChangedUnsafe += OnSourceCollectionChangedUnsafe; notifiableCollection.CollectionChanged += OnSourceCollectionChangedSafe; } return(base.OnItemsChanged(items)); }
protected override void ClearPendingChanges() { base.ClearPendingChanges(); _snapshotFilterCollection = null; }