Widow – Blame information for rev 9

Subversion Repositories:
Rev:
Rev Author Line No. Line
9 office 1 using System;
2 using System.Collections.Generic;
3 using System.Collections.ObjectModel;
4 using System.Collections.Specialized;
1 office 5 using System.ComponentModel;
9 office 6 using System.Linq;
1 office 7 using System.Runtime.CompilerServices;
8 using System.Xml.Serialization;
9 using Windows.Annotations;
10  
11 namespace Windows
12 {
13 [XmlRoot(Namespace = "urn:widow-windows-schema", ElementName = "Windows")]
9 office 14 public class Windows : INotifyPropertyChanged, IDisposable
1 office 15 {
16 #region Public Enums, Properties and Fields
17  
18 [XmlElement(ElementName = "Window")]
9 office 19 public ObservableCollection<Window> Window
1 office 20 {
21 get => _window;
22 set
23 {
24 if (Equals(value, _window))
25 {
26 return;
27 }
28  
9 office 29 _window.CollectionChanged -= _window_CollectionChanged;
1 office 30 _window = value;
9 office 31 _windows.Clear();
32 foreach (var window in value)
33 {
34 _windows.Add(window.Name);
35 }
36  
37 _window.CollectionChanged += _window_CollectionChanged;
1 office 38 OnPropertyChanged();
39 }
40 }
41  
42 #endregion
43  
44 #region Private Delegates, Events, Enums, Properties, Indexers and Fields
45  
9 office 46 private ObservableCollection<Window> _window = new ObservableCollection<Window>();
1 office 47  
9 office 48 private HashSet<string> _windows = new HashSet<string>();
49  
1 office 50 #endregion
51  
52 #region Constructors, Destructors and Finalizers
53  
54 [UsedImplicitly]
55 public Windows()
56 {
9 office 57 _window.CollectionChanged += _window_CollectionChanged;
1 office 58 }
59  
9 office 60 public void Dispose()
61 {
62 Window.CollectionChanged -= _window_CollectionChanged;
63 }
64  
1 office 65 #endregion
66  
67 #region Interface
68  
69 public event PropertyChangedEventHandler PropertyChanged;
70  
71 #endregion
72  
9 office 73 #region Event Handlers
74  
75 private void _window_CollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
76 {
77 if (e.OldItems != null)
78 {
79 foreach (var window in e.OldItems.OfType<Window>())
80 {
81 if (_windows.Contains(window.Name))
82 {
83 _windows.Remove(window.Name);
84 }
85 }
86 }
87  
88  
89 if (e.NewItems != null)
90 {
91 foreach (var window in e.NewItems.OfType<Window>())
92 {
93 if (!_windows.Contains(window.Name))
94 {
95 _windows.Add(window.Name);
96 }
97 }
98 }
99 }
100  
101 #endregion
102  
103 #region Public Methods
104  
105 public bool Contains(string name)
106 {
107 return _windows.Contains(name);
108 }
109  
110 #endregion
111  
1 office 112 #region Private Methods
113  
114 [NotifyPropertyChangedInvocator]
115 protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null)
116 {
117 PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
118 }
119  
120 #endregion
121 }
122 }