Widow

Subversion Repositories:
Compare Path: Rev
With Path: Rev
?path1? @ 12  →  ?path2? @ 14
/trunk/Windows/Window.cs
@@ -11,17 +11,17 @@
#region Public Enums, Properties and Fields
 
[XmlElement(ElementName = "Process")]
public string Process
public string Class
{
get => _process;
get => _class;
set
{
if (value == _process)
if (value == _class)
{
return;
}
 
_process = value;
_class = value;
OnPropertyChanged();
}
}
@@ -174,6 +174,8 @@
 
#region Private Delegates, Events, Enums, Properties, Indexers and Fields
 
private string _class;
 
private int _height;
 
private bool _ignoreHeight;
@@ -186,8 +188,6 @@
 
private int _left;
 
private string _process;
 
private string _title;
 
private int _top;
@@ -203,9 +203,9 @@
{
}
 
public Window(string process, string title, int top, int left, int width, int height) : this()
public Window(string @class, string title, int top, int left, int width, int height) : this()
{
Process = process;
Class = @class;
Title = title;
Top = top;
Left = left;
/trunk/Windows/WindowHash.cs
@@ -0,0 +1,76 @@
using System;
 
namespace Windows
{
public class WindowHash : IEquatable<WindowHash>
{
#region Public Enums, Properties and Fields
 
public string Title { get; }
 
public string Class { get; }
 
#endregion
 
#region Constructors, Destructors and Finalizers
 
public WindowHash(string title, string @class)
{
Title = title;
Class = @class;
}
 
#endregion
 
#region Interface
 
public bool Equals(WindowHash other)
{
if (ReferenceEquals(null, other))
{
return false;
}
 
if (ReferenceEquals(this, other))
{
return true;
}
 
return string.Equals(Title, other.Title) && string.Equals(Class, other.Class);
}
 
#endregion
 
#region Public Overrides
 
public override bool Equals(object obj)
{
if (ReferenceEquals(null, obj))
{
return false;
}
 
if (ReferenceEquals(this, obj))
{
return true;
}
 
if (obj.GetType() != GetType())
{
return false;
}
 
return Equals((WindowHash) obj);
}
 
public override int GetHashCode()
{
unchecked
{
return (Title != null ? Title.GetHashCode() : 0) * 397 ^ (Class != null ? Class.GetHashCode() : 0);
}
}
 
#endregion
}
}
/trunk/Windows/Windows.cs
@@ -34,12 +34,14 @@
{
_window.Add(window);
 
if (_windows.ContainsKey(window.Title))
var windowHash = new WindowHash(window.Title, window.Class);
 
if (_windows.ContainsKey(windowHash))
{
continue;
}
 
_windows.Add(window.Title, window);
_windows.Add(windowHash, window);
}
 
_window.CollectionChanged += Window_CollectionChanged;
@@ -53,7 +55,7 @@
 
private readonly ObservableCollection<Window> _window = new ObservableCollection<Window>();
 
private readonly Dictionary<string, Window> _windows = new Dictionary<string, Window>();
private readonly Dictionary<WindowHash, Window> _windows = new Dictionary<WindowHash, Window>();
 
#endregion
 
@@ -86,9 +88,11 @@
{
foreach (var window in e.OldItems.OfType<Window>())
{
if (_windows.ContainsKey(window.Title))
var windowHash = new WindowHash(window.Title, window.Class);
 
if (_windows.ContainsKey(windowHash))
{
_windows.Remove(window.Title);
_windows.Remove(windowHash);
}
}
}
@@ -98,9 +102,11 @@
{
foreach (var window in e.NewItems.OfType<Window>())
{
if (!_windows.ContainsKey(window.Title))
var windowHash = new WindowHash(window.Title, window.Class);
 
if (!_windows.ContainsKey(windowHash))
{
_windows.Add(window.Title, window);
_windows.Add(windowHash, window);
}
}
}
@@ -110,9 +116,9 @@
 
#region Public Methods
 
public bool TryGetWindow(string title, out Window window)
public bool TryGetWindow(WindowHash hash, out Window window)
{
return _windows.TryGetValue(title, out window);
return _windows.TryGetValue(hash, out window);
}
 
#endregion
/trunk/Windows/Windows.csproj
@@ -43,6 +43,7 @@
<ItemGroup>
<Compile Include="Properties\Annotations.cs" />
<Compile Include="Window.cs" />
<Compile Include="WindowHash.cs" />
<Compile Include="Windows.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>