From 1e74e8fc60b52360b57f0850298c318656e87875 Mon Sep 17 00:00:00 2001 From: Steven Kirk Date: Sat, 13 Apr 2019 16:26:08 +0200 Subject: [PATCH 1/5] Add failing tests for #2388. --- .../WindowTests.cs | 45 +++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/tests/Avalonia.Controls.UnitTests/WindowTests.cs b/tests/Avalonia.Controls.UnitTests/WindowTests.cs index 8221dadc86..ee416c4cb0 100644 --- a/tests/Avalonia.Controls.UnitTests/WindowTests.cs +++ b/tests/Avalonia.Controls.UnitTests/WindowTests.cs @@ -292,6 +292,51 @@ namespace Avalonia.Controls.UnitTests } } + [Fact] + public void Calling_Show_On_Closed_Window_Should_Throw() + { + using (UnitTestApplication.Start(TestServices.StyledWindow)) + { + var windowImpl = Mock.Of(x => x.Scaling == 1); + var target = new Window(windowImpl); + + target.Show(); + target.Close(); + + var openedRaised = false; + target.Opened += (s, e) => openedRaised = true; + + var ex = Assert.Throws(() => target.Show()); + Assert.Equal("Cannot re-show a closed window.", ex.Message); + Assert.False(openedRaised); + } + } + + [Fact] + public async Task Calling_ShowDialog_On_Closed_Window_Should_Throw() + { + using (UnitTestApplication.Start(TestServices.StyledWindow)) + { + var parent = new Mock(); + var windowImpl = new Mock(); + windowImpl.SetupProperty(x => x.Closed); + windowImpl.Setup(x => x.Scaling).Returns(1); + + var target = new Window(windowImpl.Object); + var task = target.ShowDialog(parent.Object); + + windowImpl.Object.Closed(); + await task; + + var openedRaised = false; + target.Opened += (s, e) => openedRaised = true; + + var ex = await Assert.ThrowsAsync(() => target.ShowDialog(parent.Object)); + Assert.Equal("Cannot re-show a closed window.", ex.Message); + Assert.False(openedRaised); + } + } + [Fact] public void Window_Should_Be_Centered_When_WindowStartupLocation_Is_CenterScreen() { From 30e006ac78d91b49eddd0ad9368ccff216e58c32 Mon Sep 17 00:00:00 2001 From: Steven Kirk Date: Sat, 13 Apr 2019 16:26:43 +0200 Subject: [PATCH 2/5] Throw an exception when trying to re-show closed window. --- src/Avalonia.Controls/Window.cs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/Avalonia.Controls/Window.cs b/src/Avalonia.Controls/Window.cs index c8e09b8f9c..6c3517af62 100644 --- a/src/Avalonia.Controls/Window.cs +++ b/src/Avalonia.Controls/Window.cs @@ -373,6 +373,11 @@ namespace Avalonia.Controls /// public override void Show() { + if (PlatformImpl == null) + { + throw new InvalidOperationException("Cannot re-show a closed window."); + } + if (IsVisible) { return; From 53e666ac90f98d72d77dca160499248187c61aee Mon Sep 17 00:00:00 2001 From: Steven Kirk Date: Sat, 13 Apr 2019 16:31:33 +0200 Subject: [PATCH 3/5] Added exception details to XML docs. --- src/Avalonia.Controls/Window.cs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/Avalonia.Controls/Window.cs b/src/Avalonia.Controls/Window.cs index 6c3517af62..e40e114769 100644 --- a/src/Avalonia.Controls/Window.cs +++ b/src/Avalonia.Controls/Window.cs @@ -371,6 +371,9 @@ namespace Avalonia.Controls /// /// Shows the window. /// + /// + /// The window has already been closed. + /// public override void Show() { if (PlatformImpl == null) @@ -402,6 +405,9 @@ namespace Avalonia.Controls /// Shows the window as a dialog. /// /// The dialog's owner window. + /// + /// The window has already been closed. + /// /// /// A task that can be used to track the lifetime of the dialog. /// From 6f1ebdf76d5528d66cf898b9b2779b698a000170 Mon Sep 17 00:00:00 2001 From: Dariusz Komosinski Date: Tue, 16 Apr 2019 10:56:08 +0200 Subject: [PATCH 4/5] Update Numerge. --- nukebuild/Numerge | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nukebuild/Numerge b/nukebuild/Numerge index 4464343aef..aef10ae67d 160000 --- a/nukebuild/Numerge +++ b/nukebuild/Numerge @@ -1 +1 @@ -Subproject commit 4464343aef5c8ab7a42fcb20a483a6058199f8b8 +Subproject commit aef10ae67dc55c95f49b52a505a0be33bfa297a5 From 1fa653350ec35ad6e03cc6dc9b144f5612a27b71 Mon Sep 17 00:00:00 2001 From: Robbie Knuth Date: Thu, 18 Apr 2019 20:15:51 -0700 Subject: [PATCH 5/5] do not fire key drag event before any drag has happened --- src/Avalonia.Controls/Platform/InProcessDragSource.cs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/Avalonia.Controls/Platform/InProcessDragSource.cs b/src/Avalonia.Controls/Platform/InProcessDragSource.cs index f8ae9f4249..0918da1a90 100644 --- a/src/Avalonia.Controls/Platform/InProcessDragSource.cs +++ b/src/Avalonia.Controls/Platform/InProcessDragSource.cs @@ -147,7 +147,10 @@ namespace Avalonia.Platform e.Handled = true; } else if (e.Key == Key.LeftCtrl || e.Key == Key.RightCtrl || e.Key == Key.LeftAlt || e.Key == Key.RightAlt) - RaiseEventAndUpdateCursor(RawDragEventType.DragOver, _lastRoot, _lastPosition, e.Modifiers); + { + if (_lastRoot != null) + RaiseEventAndUpdateCursor(RawDragEventType.DragOver, _lastRoot, _lastPosition, e.Modifiers); + } } private void ProcessMouseEvents(RawMouseEventArgs e)