Widow – Diff between revs 1 and 9
?pathlinks?
Rev 1 | Rev 9 | |||
---|---|---|---|---|
Line -... | Line 1... | |||
- | 1 | using System; |
||
1 | using System.Collections.Generic; |
2 | using System.Collections.Generic; |
|
- | 3 | using System.Collections.ObjectModel; |
||
- | 4 | using System.Collections.Specialized; |
||
2 | using System.ComponentModel; |
5 | using System.ComponentModel; |
|
- | 6 | using System.Linq; |
||
3 | using System.Runtime.CompilerServices; |
7 | using System.Runtime.CompilerServices; |
|
4 | using System.Xml.Serialization; |
8 | using System.Xml.Serialization; |
|
5 | using Windows.Annotations; |
9 | using Windows.Annotations; |
|
Line 6... | Line 10... | |||
6 | |
10 | |
|
7 | namespace Windows |
11 | namespace Windows |
|
8 | { |
12 | { |
|
9 | [XmlRoot(Namespace = "urn:widow-windows-schema", ElementName = "Windows")] |
13 | [XmlRoot(Namespace = "urn:widow-windows-schema", ElementName = "Windows")] |
|
10 | public class Windows : INotifyPropertyChanged |
14 | public class Windows : INotifyPropertyChanged, IDisposable |
|
11 | { |
15 | { |
|
Line 12... | Line 16... | |||
12 | #region Public Enums, Properties and Fields |
16 | #region Public Enums, Properties and Fields |
|
13 | |
17 | |
|
14 | [XmlElement(ElementName = "Window")] |
18 | [XmlElement(ElementName = "Window")] |
|
15 | public List<Window> Window |
19 | public ObservableCollection<Window> Window |
|
16 | { |
20 | { |
|
17 | get => _window; |
21 | get => _window; |
|
18 | set |
22 | set |
|
19 | { |
23 | { |
|
20 | if (Equals(value, _window)) |
24 | if (Equals(value, _window)) |
|
21 | { |
25 | { |
|
Line -... | Line 26... | |||
- | 26 | return; |
||
22 | return; |
27 | } |
|
- | 28 | |
||
- | 29 | _window.CollectionChanged -= _window_CollectionChanged; |
||
- | 30 | _window = value; |
||
- | 31 | _windows.Clear(); |
||
- | 32 | foreach (var window in value) |
||
- | 33 | { |
||
- | 34 | _windows.Add(window.Name); |
||
23 | } |
35 | } |
|
24 | |
36 | |
|
25 | _window = value; |
37 | _window.CollectionChanged += _window_CollectionChanged; |
|
Line 26... | Line 38... | |||
26 | OnPropertyChanged(); |
38 | OnPropertyChanged(); |
|
Line 27... | Line 39... | |||
27 | } |
39 | } |
|
Line -... | Line 40... | |||
- | 40 | } |
||
- | 41 | |
||
28 | } |
42 | #endregion |
|
Line 29... | Line 43... | |||
29 | |
43 | |
|
Line 30... | Line 44... | |||
30 | #endregion |
44 | #region Private Delegates, Events, Enums, Properties, Indexers and Fields |
|
Line 31... | Line 45... | |||
31 | |
45 | |
|
32 | #region Private Delegates, Events, Enums, Properties, Indexers and Fields |
46 | private ObservableCollection<Window> _window = new ObservableCollection<Window>(); |
|
33 | |
47 | |
|
- | 48 | private HashSet<string> _windows = new HashSet<string>(); |
||
- | 49 | |
||
- | 50 | #endregion |
||
- | 51 | |
||
- | 52 | #region Constructors, Destructors and Finalizers |
||
- | 53 | |
||
34 | private List<Window> _window = new List<Window>(); |
54 | [UsedImplicitly] |
|
Line 35... | Line 55... | |||
35 | |
55 | public Windows() |
|
Line 36... | Line 56... | |||
36 | #endregion |
56 | { |
|
Line 37... | Line 57... | |||
37 | |
57 | _window.CollectionChanged += _window_CollectionChanged; |
|
Line 38... | Line 58... | |||
38 | #region Constructors, Destructors and Finalizers |
58 | } |
|
Line -... | Line 59... | |||
- | 59 | |
||
- | 60 | public void Dispose() |
||
- | 61 | { |
||
- | 62 | Window.CollectionChanged -= _window_CollectionChanged; |
||
- | 63 | } |
||
- | 64 | |
||
- | 65 | #endregion |
||
- | 66 | |
||
- | 67 | #region Interface |
||
- | 68 | |
||
- | 69 | public event PropertyChangedEventHandler PropertyChanged; |
||
- | 70 | |
||
- | 71 | #endregion |
||
- | 72 | |
||
- | 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 | } |
||
39 | |
98 | } |
|
Line 40... | Line 99... | |||
40 | [UsedImplicitly] |
99 | } |
|
41 | public Windows() |
100 | |
|
42 | { |
101 | #endregion |