Changeset 2623 for trunk/sources
- Timestamp:
- 01/13/10 03:32:32 (15 years ago)
- Location:
- trunk/sources/HeuristicLab.Collections/3.3
- Files:
-
- 3 added
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Collections/3.3/HeuristicLab.Collections-3.3.csproj
r2618 r2623 49 49 </ItemGroup> 50 50 <ItemGroup> 51 <Compile Include="ReadOnlyObservableSet.cs" /> 52 <Compile Include="IObservableSet.cs" /> 53 <Compile Include="ObservableSet.cs"> 54 <SubType>Code</SubType> 55 </Compile> 51 56 <Compile Include="ReadOnlyObservableKeyedCollection.cs"> 52 57 <SubType>Code</SubType> -
trunk/sources/HeuristicLab.Collections/3.3/IObservableDictionary.cs
r2620 r2623 27 27 28 28 namespace HeuristicLab.Collections { 29 public interface IObservableDictionary<TKey, TValue> : IDictionary<TKey, TValue>, INotifyPropertyChanged { 30 event CollectionItemsChangedEventHandler<KeyValuePair<TKey, TValue>> ItemsAdded; 31 event CollectionItemsChangedEventHandler<KeyValuePair<TKey, TValue>> ItemsRemoved; 29 public interface IObservableDictionary<TKey, TValue> : IDictionary<TKey, TValue>, IObservableCollection<KeyValuePair<TKey, TValue>> { 32 30 event CollectionItemsChangedEventHandler<KeyValuePair<TKey, TValue>> ItemsReplaced; 33 event CollectionItemsChangedEventHandler<KeyValuePair<TKey, TValue>> CollectionReset;34 31 } 35 32 } -
trunk/sources/HeuristicLab.Collections/3.3/IObservableKeyedCollection.cs
r2620 r2623 27 27 28 28 namespace HeuristicLab.Collections { 29 public interface IObservableKeyedCollection<TKey, TItem> : I Collection<TItem>, INotifyPropertyChanged{29 public interface IObservableKeyedCollection<TKey, TItem> : IObservableCollection<TItem> { 30 30 TItem this[TKey key] { get; } 31 31 … … 33 33 bool TryGetValue(TKey key, out TItem item); 34 34 35 event CollectionItemsChangedEventHandler<TItem> ItemsAdded;36 event CollectionItemsChangedEventHandler<TItem> ItemsRemoved; 35 bool Remove(TKey key); 36 37 37 event CollectionItemsChangedEventHandler<TItem> ItemsReplaced; 38 event CollectionItemsChangedEventHandler<TItem> CollectionReset;39 38 } 40 39 } -
trunk/sources/HeuristicLab.Collections/3.3/IObservableList.cs
r2620 r2623 27 27 28 28 namespace HeuristicLab.Collections { 29 public interface IObservableList<T> : IList<T>, I NotifyPropertyChanged{30 event CollectionItemsChangedEventHandler<IndexedItem<T>> ItemsAdded;31 event CollectionItemsChangedEventHandler<IndexedItem<T>> ItemsRemoved;29 public interface IObservableList<T> : IList<T>, IObservableCollection<T> { 30 new event CollectionItemsChangedEventHandler<IndexedItem<T>> ItemsAdded; 31 new event CollectionItemsChangedEventHandler<IndexedItem<T>> ItemsRemoved; 32 32 event CollectionItemsChangedEventHandler<IndexedItem<T>> ItemsReplaced; 33 33 event CollectionItemsChangedEventHandler<IndexedItem<T>> ItemsMoved; 34 event CollectionItemsChangedEventHandler<IndexedItem<T>> CollectionReset;34 new event CollectionItemsChangedEventHandler<IndexedItem<T>> CollectionReset; 35 35 } 36 36 } -
trunk/sources/HeuristicLab.Collections/3.3/IndexedItem.cs
r2572 r2623 44 44 public override string ToString() { 45 45 StringBuilder sb = new StringBuilder(); 46 sb.Append("[").Append(index).Append(", ").Append(value != null ? value.ToString() : "null").Append("]"); 46 sb.Append("[").Append(index).Append(", "); 47 if (value != null) sb.Append(value.ToString()); 48 sb.Append("]"); 47 49 return sb.ToString(); 48 50 } -
trunk/sources/HeuristicLab.Collections/3.3/ObservableDictionary.cs
r2620 r2623 173 173 174 174 #region Enumeration 175 public Dictionary<TKey, TValue>.EnumeratorGetEnumerator() {175 public IEnumerator<KeyValuePair<TKey, TValue>> GetEnumerator() { 176 176 return dict.GetEnumerator(); 177 177 } 178 IEnumerator<KeyValuePair<TKey, TValue>> IEnumerable<KeyValuePair<TKey, TValue>>.GetEnumerator() {179 return ((IEnumerable<KeyValuePair<TKey, TValue>>)dict).GetEnumerator();180 }181 178 IEnumerator IEnumerable.GetEnumerator() { 182 return ((IEnumerable)dict).GetEnumerator();179 return dict.GetEnumerator(); 183 180 } 184 181 #endregion -
trunk/sources/HeuristicLab.Collections/3.3/ObservableList.cs
r2620 r2623 77 77 list = new List<T>(collection); 78 78 OnItemsAdded(GetIndexedItems()); 79 OnItemsAdded(collection); 79 80 } 80 81 #endregion … … 163 164 OnPropertyChanged("Count"); 164 165 OnItemsAdded(new IndexedItem<T>[] { new IndexedItem<T>(list.Count - 1, item) }); 166 OnItemsAdded(new T[] { item }); 165 167 } 166 168 public void AddRange(IEnumerable<T> collection) { … … 179 181 OnPropertyChanged("Count"); 180 182 OnItemsAdded(items); 183 OnItemsAdded(collection); 181 184 } 182 185 } … … 190 193 OnPropertyChanged("Count"); 191 194 OnItemsAdded(new IndexedItem<T>[] { new IndexedItem<T>(index, item) }); 195 OnItemsAdded(new T[] { item }); 192 196 } 193 197 public void InsertRange(int index, IEnumerable<T> collection) { … … 205 209 OnPropertyChanged("Count"); 206 210 OnItemsAdded(items); 211 OnItemsAdded(collection); 207 212 } 208 213 } … … 215 220 OnPropertyChanged("Count"); 216 221 OnItemsRemoved(new IndexedItem<T>[] { new IndexedItem<T>(index, item) }); 222 OnItemsRemoved(new T[] { item }); 217 223 return true; 218 224 } … … 221 227 public int RemoveAll(Predicate<T> match) { 222 228 if (match == null) throw new ArgumentNullException(); 223 List<IndexedItem<T>> items = new List<IndexedItem<T>>(); 229 List<IndexedItem<T>> indexedItems = new List<IndexedItem<T>>(); 230 List<T> items = new List<T>(); 224 231 for (int i = 0; i < list.Count; i++) { 225 if (match(list[i])) 226 items.Add(new IndexedItem<T>(i, list[i])); 232 if (match(list[i])) { 233 indexedItems.Add(new IndexedItem<T>(i, list[i])); 234 items.Add(list[i]); 235 } 227 236 } 228 237 int result = 0; 229 if (i tems.Count > 0) {238 if (indexedItems.Count > 0) { 230 239 result = list.RemoveAll(match); 231 240 OnPropertyChanged("Item[]"); 232 241 OnPropertyChanged("Count"); 242 OnItemsRemoved(indexedItems); 233 243 OnItemsRemoved(items); 234 244 } … … 241 251 OnPropertyChanged("Count"); 242 252 OnItemsRemoved(new IndexedItem<T>[] { new IndexedItem<T>(index, item) }); 253 OnItemsRemoved(new T[] { item }); 243 254 } 244 255 public void RemoveRange(int index, int count) { 245 256 if (count > 0) { 246 IndexedItem<T>[] items = GetIndexedItems(index, count); 257 IndexedItem<T>[] indexedItems = GetIndexedItems(index, count); 258 T[] items = new T[count]; 259 list.CopyTo(index, items, 0, count); 247 260 list.RemoveRange(index, count); 248 261 OnPropertyChanged("Item[]"); 249 262 OnPropertyChanged("Count"); 263 OnItemsRemoved(indexedItems); 250 264 OnItemsRemoved(items); 251 265 } … … 254 268 public void Clear() { 255 269 if (list.Count > 0) { 256 IndexedItem<T>[] items = GetIndexedItems(); 270 IndexedItem<T>[] indexedItems = GetIndexedItems(); 271 T[] items = list.ToArray(); 257 272 list.Clear(); 258 273 OnPropertyChanged("Item[]"); 259 274 OnPropertyChanged("Count"); 260 OnCollectionReset(new IndexedItem<T>[0], items); 275 OnCollectionReset(new IndexedItem<T>[0], indexedItems); 276 OnCollectionReset(new T[0], items); 261 277 } 262 278 } … … 320 336 return list.ToArray(); 321 337 } 322 void ICollection<T>.CopyTo(T[] array, int arrayIndex) { 338 public void CopyTo(T[] array) { 339 list.CopyTo(array); 340 } 341 public void CopyTo(T[] array, int arrayIndex) { 323 342 list.CopyTo(array, arrayIndex); 343 } 344 public void CopyTo(int index, T[] array, int arrayIndex, int count) { 345 list.CopyTo(index, array, arrayIndex, count); 324 346 } 325 347 public List<TOutput> ConvertAll<TOutput>(Converter<T, TOutput> converter) { … … 338 360 339 361 #region Enumeration 340 public List<T>.EnumeratorGetEnumerator() {362 public IEnumerator<T> GetEnumerator() { 341 363 return list.GetEnumerator(); 342 364 } 343 IEnumerator<T> IEnumerable<T>.GetEnumerator() {344 return ((IEnumerable<T>)list).GetEnumerator();345 }346 365 IEnumerator IEnumerable.GetEnumerator() { 347 return ((IEnumerable)list).GetEnumerator();366 return list.GetEnumerator(); 348 367 } 349 368 #endregion … … 367 386 368 387 [field: NonSerialized] 388 private event CollectionItemsChangedEventHandler<T> itemsAdded; 389 event CollectionItemsChangedEventHandler<T> IObservableCollection<T>.ItemsAdded { 390 add { itemsAdded += value; } 391 remove { itemsAdded -= value; } 392 } 393 private void OnItemsAdded(IEnumerable<T> items) { 394 if (itemsAdded != null) 395 itemsAdded(this, new CollectionItemsChangedEventArgs<T>(items)); 396 } 397 398 [field: NonSerialized] 369 399 public event CollectionItemsChangedEventHandler<IndexedItem<T>> ItemsRemoved; 370 400 protected virtual void OnItemsRemoved(IEnumerable<IndexedItem<T>> items) { … … 374 404 375 405 [field: NonSerialized] 406 private event CollectionItemsChangedEventHandler<T> itemsRemoved; 407 event CollectionItemsChangedEventHandler<T> IObservableCollection<T>.ItemsRemoved { 408 add { itemsRemoved += value; } 409 remove { itemsRemoved -= value; } 410 } 411 private void OnItemsRemoved(IEnumerable<T> items) { 412 if (itemsRemoved != null) 413 itemsRemoved(this, new CollectionItemsChangedEventArgs<T>(items)); 414 } 415 416 [field: NonSerialized] 376 417 public event CollectionItemsChangedEventHandler<IndexedItem<T>> ItemsReplaced; 377 418 protected virtual void OnItemsReplaced(IEnumerable<IndexedItem<T>> items, IEnumerable<IndexedItem<T>> oldItems) { … … 392 433 if (CollectionReset != null) 393 434 CollectionReset(this, new CollectionItemsChangedEventArgs<IndexedItem<T>>(items, oldItems)); 435 } 436 437 [field: NonSerialized] 438 private event CollectionItemsChangedEventHandler<T> collectionReset; 439 event CollectionItemsChangedEventHandler<T> IObservableCollection<T>.CollectionReset { 440 add { collectionReset += value; } 441 remove { collectionReset -= value; } 442 } 443 private void OnCollectionReset(IEnumerable<T> items, IEnumerable<T> oldItems) { 444 if (collectionReset != null) 445 collectionReset(this, new CollectionItemsChangedEventArgs<T>(items, oldItems)); 394 446 } 395 447 -
trunk/sources/HeuristicLab.Collections/3.3/ReadOnlyObservableKeyedCollection.cs
r2620 r2623 80 80 } 81 81 82 bool IObservableKeyedCollection<TKey, TItem>.Remove(TKey key) { 83 throw new NotSupportedException(); 84 } 82 85 bool ICollection<TItem>.Remove(TItem item) { 83 86 throw new NotSupportedException(); -
trunk/sources/HeuristicLab.Collections/3.3/ReadOnlyObservableList.cs
r2620 r2623 57 57 this.list = list; 58 58 list.ItemsAdded += new CollectionItemsChangedEventHandler<IndexedItem<T>>(list_ItemsAdded); 59 ((IObservableCollection<T>)list).ItemsAdded += new CollectionItemsChangedEventHandler<T>(list_ItemsAdded); 59 60 list.ItemsRemoved += new CollectionItemsChangedEventHandler<IndexedItem<T>>(list_ItemsRemoved); 61 ((IObservableCollection<T>)list).ItemsRemoved += new CollectionItemsChangedEventHandler<T>(list_ItemsRemoved); 60 62 list.ItemsReplaced += new CollectionItemsChangedEventHandler<IndexedItem<T>>(list_ItemsReplaced); 61 63 list.ItemsMoved += new CollectionItemsChangedEventHandler<IndexedItem<T>>(list_ItemsMoved); 62 64 list.CollectionReset += new CollectionItemsChangedEventHandler<IndexedItem<T>>(list_CollectionReset); 65 ((IObservableCollection<T>)list).CollectionReset += new CollectionItemsChangedEventHandler<T>(list_CollectionReset); 63 66 list.PropertyChanged += new PropertyChangedEventHandler(list_PropertyChanged); 64 67 } … … 97 100 98 101 #region Conversion 99 void ICollection<T>.CopyTo(T[] array, int arrayIndex) {102 public void CopyTo(T[] array, int arrayIndex) { 100 103 list.CopyTo(array, arrayIndex); 101 104 } … … 120 123 121 124 [field: NonSerialized] 125 private event CollectionItemsChangedEventHandler<T> itemsAdded; 126 event CollectionItemsChangedEventHandler<T> IObservableCollection<T>.ItemsAdded { 127 add { itemsAdded += value; } 128 remove { itemsAdded -= value; } 129 } 130 private void OnItemsAdded(IEnumerable<T> items) { 131 if (itemsAdded != null) 132 itemsAdded(this, new CollectionItemsChangedEventArgs<T>(items)); 133 } 134 135 [field: NonSerialized] 122 136 public event CollectionItemsChangedEventHandler<IndexedItem<T>> ItemsRemoved; 123 137 protected virtual void OnItemsRemoved(IEnumerable<IndexedItem<T>> items) { … … 127 141 128 142 [field: NonSerialized] 143 private event CollectionItemsChangedEventHandler<T> itemsRemoved; 144 event CollectionItemsChangedEventHandler<T> IObservableCollection<T>.ItemsRemoved { 145 add { itemsRemoved += value; } 146 remove { itemsRemoved -= value; } 147 } 148 private void OnItemsRemoved(IEnumerable<T> items) { 149 if (itemsRemoved != null) 150 itemsRemoved(this, new CollectionItemsChangedEventArgs<T>(items)); 151 } 152 153 [field: NonSerialized] 129 154 public event CollectionItemsChangedEventHandler<IndexedItem<T>> ItemsReplaced; 130 155 protected virtual void OnItemsReplaced(IEnumerable<IndexedItem<T>> items, IEnumerable<IndexedItem<T>> oldItems) { … … 148 173 149 174 [field: NonSerialized] 175 private event CollectionItemsChangedEventHandler<T> collectionReset; 176 event CollectionItemsChangedEventHandler<T> IObservableCollection<T>.CollectionReset { 177 add { collectionReset += value; } 178 remove { collectionReset -= value; } 179 } 180 private void OnCollectionReset(IEnumerable<T> items, IEnumerable<T> oldItems) { 181 if (collectionReset != null) 182 collectionReset(this, new CollectionItemsChangedEventArgs<T>(items, oldItems)); 183 } 184 185 [field: NonSerialized] 150 186 public event PropertyChangedEventHandler PropertyChanged; 151 187 protected virtual void OnPropertyChanged(string propertyName) { … … 157 193 OnItemsAdded(e.Items); 158 194 } 195 private void list_ItemsAdded(object sender, CollectionItemsChangedEventArgs<T> e) { 196 OnItemsAdded(e.Items); 197 } 159 198 private void list_ItemsRemoved(object sender, CollectionItemsChangedEventArgs<IndexedItem<T>> e) { 160 199 OnItemsRemoved(e.Items); 161 200 } 201 private void list_ItemsRemoved(object sender, CollectionItemsChangedEventArgs<T> e) { 202 OnItemsRemoved(e.Items); 203 } 162 204 private void list_ItemsReplaced(object sender, CollectionItemsChangedEventArgs<IndexedItem<T>> e) { 163 205 OnItemsReplaced(e.Items, e.OldItems); … … 167 209 } 168 210 private void list_CollectionReset(object sender, CollectionItemsChangedEventArgs<IndexedItem<T>> e) { 211 OnCollectionReset(e.Items, e.OldItems); 212 } 213 private void list_CollectionReset(object sender, CollectionItemsChangedEventArgs<T> e) { 169 214 OnCollectionReset(e.Items, e.OldItems); 170 215 }
Note: See TracChangeset
for help on using the changeset viewer.