4 using System.Collections.Generic;
5 using System.ComponentModel;
7 namespace SiliconStudio.Presentation.Collections
23 private int changeCount;
38 return string.Format(
"{{AutoUpdatingSortedObservableCollection}} Count = {0}", Count);
44 if (ChangingItem != null && !ReferenceEquals(ChangingItem, item))
45 throw new InvalidOperationException(
"Multiple items in the collection are changing concurrently.");
50 ChangingIndex = GetIndex(item,
false);
59 if (ChangingItem != null && AddedItem != null)
60 throw new InvalidOperationException(
"PropertyChanged is invoked without PropertyChanging, or multiple items in the collection are changing concurrently.");
63 if (ChangingItem == null && AddedItem != null)
65 ChangingItem = AddedItem;
66 ChangingIndex = AddedIndex;
71 if (ChangingItem == null || !ReferenceEquals(ChangingItem, item))
73 throw new InvalidOperationException(
"PropertyChanged is invoked without PropertyChanging, or multiple items in the collection are changing concurrently.");
79 bool needReorder = (ChangingIndex > 0 && DefaultCompareFunc(Items[ChangingIndex - 1], item) > 0) || (ChangingIndex < Count - 1 && DefaultCompareFunc(item, Items[ChangingIndex + 1]) > 0);
82 int newIndex = GetReorderingIndex(item);
83 if (newIndex != ChangingIndex && newIndex != ChangingIndex + 1)
85 if (newIndex > ChangingIndex)
88 ObservableCollectionMoveItem(ChangingIndex, newIndex);
91 ChangingIndex = GetIndex(item,
false);
100 int imax = Count - 1;
103 int imid = (imin + imax) / 2;
105 int comp = DefaultCompareFunc(
this[imid], item);
115 comp = DefaultCompareFunc(
this[imid - 1], item);
122 if (imid < Count - 1)
124 comp = DefaultCompareFunc(
this[imid + 1], item);
142 item.PropertyChanging += ItemPropertyChanging;
143 item.PropertyChanged += ItemPropertyChanged;
144 base.InsertItem(index, item);
146 AddedIndex = GetIndex(item,
false);
152 foreach (var item
in Items)
154 item.PropertyChanging -= ItemPropertyChanging;
155 item.PropertyChanged -= ItemPropertyChanged;
163 var item = Items[index];
164 item.PropertyChanging -= ItemPropertyChanging;
165 item.PropertyChanged -= ItemPropertyChanged;
166 if (ChangingItem == item)
171 base.RemoveItem(index);
virtual void ItemPropertyChanged(object sender, PropertyChangedEventArgs e)
override void InsertItem(int index, T item)
virtual void ItemPropertyChanging(object sender, PropertyChangingEventArgs e)
AutoUpdatingSortedObservableCollection(IComparer< T > comparer=null)
Public constructor. A comparer can be provided to compare items. If null, the default comparer will b...
override void ClearItems()
override void RemoveItem(int index)
override string ToString()
int GetReorderingIndex(T item)