Widow – Blame information for rev 11
?pathlinks?
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 | |||
11 | office | 29 | _window.CollectionChanged -= Window_CollectionChanged; |
30 | _window.Clear(); |
||
31 | |||
9 | office | 32 | _windows.Clear(); |
33 | foreach (var window in value) |
||
34 | { |
||
11 | office | 35 | _window.Add(window); |
36 | |||
37 | if (_windows.Contains(window.Title)) |
||
38 | { |
||
39 | continue; |
||
40 | } |
||
41 | |||
42 | _windows.Add(window.Title); |
||
9 | office | 43 | } |
44 | |||
11 | office | 45 | _window.CollectionChanged += Window_CollectionChanged; |
1 | office | 46 | OnPropertyChanged(); |
47 | } |
||
48 | } |
||
49 | |||
50 | #endregion |
||
51 | |||
52 | #region Private Delegates, Events, Enums, Properties, Indexers and Fields |
||
53 | |||
11 | office | 54 | private readonly ObservableCollection<Window> _window = new ObservableCollection<Window>(); |
1 | office | 55 | |
11 | office | 56 | private readonly HashSet<string> _windows = new HashSet<string>(); |
9 | office | 57 | |
1 | office | 58 | #endregion |
59 | |||
60 | #region Constructors, Destructors and Finalizers |
||
61 | |||
62 | [UsedImplicitly] |
||
63 | public Windows() |
||
64 | { |
||
11 | office | 65 | _window.CollectionChanged += Window_CollectionChanged; |
1 | office | 66 | } |
67 | |||
9 | office | 68 | public void Dispose() |
69 | { |
||
11 | office | 70 | Window.CollectionChanged -= Window_CollectionChanged; |
9 | office | 71 | } |
72 | |||
1 | office | 73 | #endregion |
74 | |||
75 | #region Interface |
||
76 | |||
77 | public event PropertyChangedEventHandler PropertyChanged; |
||
78 | |||
79 | #endregion |
||
80 | |||
9 | office | 81 | #region Event Handlers |
82 | |||
11 | office | 83 | private void Window_CollectionChanged(object sender, NotifyCollectionChangedEventArgs e) |
9 | office | 84 | { |
85 | if (e.OldItems != null) |
||
86 | { |
||
87 | foreach (var window in e.OldItems.OfType<Window>()) |
||
88 | { |
||
11 | office | 89 | if (_windows.Contains(window.Title)) |
9 | office | 90 | { |
11 | office | 91 | _windows.Remove(window.Title); |
9 | office | 92 | } |
93 | } |
||
94 | } |
||
95 | |||
96 | |||
97 | if (e.NewItems != null) |
||
98 | { |
||
99 | foreach (var window in e.NewItems.OfType<Window>()) |
||
100 | { |
||
11 | office | 101 | if (!_windows.Contains(window.Title)) |
9 | office | 102 | { |
11 | office | 103 | _windows.Add(window.Title); |
9 | office | 104 | } |
105 | } |
||
106 | } |
||
107 | } |
||
108 | |||
109 | #endregion |
||
110 | |||
111 | #region Public Methods |
||
112 | |||
11 | office | 113 | public bool Contains(string hash) |
9 | office | 114 | { |
11 | office | 115 | return _windows.Contains(hash); |
9 | office | 116 | } |
117 | |||
118 | #endregion |
||
119 | |||
1 | office | 120 | #region Private Methods |
121 | |||
122 | [NotifyPropertyChangedInvocator] |
||
123 | protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null) |
||
124 | { |
||
125 | PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); |
||
126 | } |
||
127 | |||
128 | #endregion |
||
129 | } |
||
130 | } |