main
1using System;
2using System.Collections.ObjectModel;
3using System.Collections.Specialized;
4
5namespace solidware.financials.windows.ui.views.controls
6{
7 public class SmartCollection<T> : ObservableCollection<T>
8 {
9 bool suspend;
10
11 public SmartCollection()
12 {
13 suspend = false;
14 }
15
16 protected override void OnCollectionChanged(NotifyCollectionChangedEventArgs e)
17 {
18 if (!suspend) base.OnCollectionChanged(e);
19 }
20
21 public IDisposable BeginEdit()
22 {
23 return new SuspendNotifications<T>(this);
24 }
25
26 class SuspendNotifications<K> : IDisposable
27 {
28 readonly SmartCollection<K> items;
29
30 public SuspendNotifications(SmartCollection<K> items)
31 {
32 this.items = items;
33 items.suspend = true;
34 }
35
36 public void Dispose()
37 {
38 items.suspend = false;
39 items.OnCollectionChanged(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Reset));
40 }
41 }
42 }
43}