Widow – Rev 11
?pathlinks?
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Collections.Specialized;
using System.ComponentModel;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Xml.Serialization;
using Windows.Annotations;
namespace Windows
{
[XmlRoot(Namespace = "urn:widow-windows-schema", ElementName = "Windows")]
public class Windows : INotifyPropertyChanged, IDisposable
{
#region Public Enums, Properties and Fields
[XmlElement(ElementName = "Window")]
public ObservableCollection<Window> Window
{
get => _window;
set
{
if (Equals(value, _window))
{
return;
}
_window.CollectionChanged -= Window_CollectionChanged;
_window.Clear();
_windows.Clear();
foreach (var window in value)
{
_window.Add(window);
if (_windows.Contains(window.Title))
{
continue;
}
_windows.Add(window.Title);
}
_window.CollectionChanged += Window_CollectionChanged;
OnPropertyChanged();
}
}
#endregion
#region Private Delegates, Events, Enums, Properties, Indexers and Fields
private readonly ObservableCollection<Window> _window = new ObservableCollection<Window>();
private readonly HashSet<string> _windows = new HashSet<string>();
#endregion
#region Constructors, Destructors and Finalizers
[UsedImplicitly]
public Windows()
{
_window.CollectionChanged += Window_CollectionChanged;
}
public void Dispose()
{
Window.CollectionChanged -= Window_CollectionChanged;
}
#endregion
#region Interface
public event PropertyChangedEventHandler PropertyChanged;
#endregion
#region Event Handlers
private void Window_CollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
{
if (e.OldItems != null)
{
foreach (var window in e.OldItems.OfType<Window>())
{
if (_windows.Contains(window.Title))
{
_windows.Remove(window.Title);
}
}
}
if (e.NewItems != null)
{
foreach (var window in e.NewItems.OfType<Window>())
{
if (!_windows.Contains(window.Title))
{
_windows.Add(window.Title);
}
}
}
}
#endregion
#region Public Methods
public bool Contains(string hash)
{
return _windows.Contains(hash);
}
#endregion
#region Private Methods
[NotifyPropertyChangedInvocator]
protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
#endregion
}
}
Generated by GNU Enscript 1.6.5.90.