From 8b2accd6ad9bbed7073b99ca8ef390e06723efd0 Mon Sep 17 00:00:00 2001 From: Dan Walmsley Date: Tue, 22 Mar 2016 19:16:40 +0000 Subject: [PATCH 1/5] Implemented Windows Enumerable. --- src/Perspex.Controls/Window.cs | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/src/Perspex.Controls/Window.cs b/src/Perspex.Controls/Window.cs index ae12a4d6ed..9c379d1722 100644 --- a/src/Perspex.Controls/Window.cs +++ b/src/Perspex.Controls/Window.cs @@ -10,6 +10,9 @@ using Perspex.Layout; using Perspex.Media; using Perspex.Platform; using Perspex.Styling; +using System.Collections; +using System.Collections.Generic; +using Perspex.Threading; namespace Perspex.Controls { @@ -44,6 +47,22 @@ namespace Perspex.Controls /// public class Window : TopLevel, IStyleable, IFocusScope, ILayoutRoot, INameScope { + private static IList windows = new List(); + + /// + /// Retrieves an enumeration of all Windows in the currently running application. + /// Can only be accessed from the UI Thread. + /// + public static IEnumerable Windows + { + get + { + Dispatcher.UIThread.VerifyAccess(); + + return windows; + } + } + /// /// Defines the property. /// @@ -153,6 +172,7 @@ namespace Perspex.Controls /// public void Close() { + windows.Remove(this); PlatformImpl.Dispose(); } @@ -193,6 +213,8 @@ namespace Perspex.Controls /// public void Show() { + windows.Add(this); + LayoutManager.Instance.ExecuteInitialLayoutPass(this); using (BeginAutoSizing()) @@ -223,6 +245,8 @@ namespace Perspex.Controls /// public Task ShowDialog() { + windows.Add(this); + LayoutManager.Instance.ExecuteInitialLayoutPass(this); using (BeginAutoSizing()) From 9e0e0905af7a084ecc607b6a05dd1da561f5cb6e Mon Sep 17 00:00:00 2001 From: Dan Walmsley Date: Tue, 22 Mar 2016 20:20:23 +0000 Subject: [PATCH 2/5] Window.Windows is now Window.OpenWindows, exposed as IList and corrected code standards. --- src/Perspex.Controls/Window.cs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/Perspex.Controls/Window.cs b/src/Perspex.Controls/Window.cs index 9c379d1722..a2053ab33e 100644 --- a/src/Perspex.Controls/Window.cs +++ b/src/Perspex.Controls/Window.cs @@ -47,19 +47,19 @@ namespace Perspex.Controls /// public class Window : TopLevel, IStyleable, IFocusScope, ILayoutRoot, INameScope { - private static IList windows = new List(); + private static IList s_windows = new List(); /// /// Retrieves an enumeration of all Windows in the currently running application. /// Can only be accessed from the UI Thread. /// - public static IEnumerable Windows + public static IList OpenWindows { get { Dispatcher.UIThread.VerifyAccess(); - return windows; + return s_windows; } } @@ -172,7 +172,7 @@ namespace Perspex.Controls /// public void Close() { - windows.Remove(this); + s_windows.Remove(this); PlatformImpl.Dispose(); } @@ -213,7 +213,7 @@ namespace Perspex.Controls /// public void Show() { - windows.Add(this); + s_windows.Add(this); LayoutManager.Instance.ExecuteInitialLayoutPass(this); @@ -245,7 +245,7 @@ namespace Perspex.Controls /// public Task ShowDialog() { - windows.Add(this); + s_windows.Add(this); LayoutManager.Instance.ExecuteInitialLayoutPass(this); From 9f6042e0cf9fb408347c87016f6efef8bce08362 Mon Sep 17 00:00:00 2001 From: Dan Walmsley Date: Tue, 22 Mar 2016 20:22:50 +0000 Subject: [PATCH 3/5] no longer verify thread access to list. --- src/Perspex.Controls/Window.cs | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/Perspex.Controls/Window.cs b/src/Perspex.Controls/Window.cs index a2053ab33e..3ffc88139e 100644 --- a/src/Perspex.Controls/Window.cs +++ b/src/Perspex.Controls/Window.cs @@ -10,9 +10,7 @@ using Perspex.Layout; using Perspex.Media; using Perspex.Platform; using Perspex.Styling; -using System.Collections; using System.Collections.Generic; -using Perspex.Threading; namespace Perspex.Controls { @@ -57,8 +55,6 @@ namespace Perspex.Controls { get { - Dispatcher.UIThread.VerifyAccess(); - return s_windows; } } From 375ac04e6a01d18aeed6562649cbc7b4d81af969 Mon Sep 17 00:00:00 2001 From: Dan Walmsley Date: Tue, 22 Mar 2016 20:26:42 +0000 Subject: [PATCH 4/5] using lamda instead of getter. --- src/Perspex.Controls/Window.cs | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/src/Perspex.Controls/Window.cs b/src/Perspex.Controls/Window.cs index 3ffc88139e..3b3b46cac6 100644 --- a/src/Perspex.Controls/Window.cs +++ b/src/Perspex.Controls/Window.cs @@ -51,13 +51,7 @@ namespace Perspex.Controls /// Retrieves an enumeration of all Windows in the currently running application. /// Can only be accessed from the UI Thread. /// - public static IList OpenWindows - { - get - { - return s_windows; - } - } + public static IList OpenWindows => s_windows; /// /// Defines the property. From 5ac817e2b8f3567e00e14b76fae74c662a35a297 Mon Sep 17 00:00:00 2001 From: Dan Walmsley Date: Tue, 22 Mar 2016 20:27:34 +0000 Subject: [PATCH 5/5] updated comment. --- src/Perspex.Controls/Window.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Perspex.Controls/Window.cs b/src/Perspex.Controls/Window.cs index 3b3b46cac6..94437825cb 100644 --- a/src/Perspex.Controls/Window.cs +++ b/src/Perspex.Controls/Window.cs @@ -49,7 +49,6 @@ namespace Perspex.Controls /// /// Retrieves an enumeration of all Windows in the currently running application. - /// Can only be accessed from the UI Thread. /// public static IList OpenWindows => s_windows;