Browse Source

use a ShutdownRequestedEventArgs class to future proof the event args.

Dan Walmsley 4 years ago
parent
commit
c9458e5be8

+ 3 - 3
src/Avalonia.Controls/ApiCompatBaseline.txt

@@ -30,9 +30,9 @@ MembersMustExist : Member 'public System.Double Avalonia.Controls.NumericUpDownV
 MembersMustExist : Member 'public System.Double Avalonia.Controls.NumericUpDownValueChangedEventArgs.OldValue.get()' does not exist in the implementation but it does exist in the contract.
 MembersMustExist : Member 'public Avalonia.StyledProperty<System.Boolean> Avalonia.StyledProperty<System.Boolean> Avalonia.Controls.ScrollViewer.AllowAutoHideProperty' does not exist in the implementation but it does exist in the contract.
 MembersMustExist : Member 'public Avalonia.AvaloniaProperty<Avalonia.Media.Stretch> Avalonia.AvaloniaProperty<Avalonia.Media.Stretch> Avalonia.Controls.Viewbox.StretchProperty' does not exist in the implementation but it does exist in the contract.
-InterfacesShouldHaveSameMembers : Interface member 'public System.EventHandler<System.ComponentModel.CancelEventArgs> Avalonia.Controls.ApplicationLifetimes.IClassicDesktopStyleApplicationLifetime.ShutdownRequested' is present in the implementation but not in the contract.
-InterfacesShouldHaveSameMembers : Interface member 'public void Avalonia.Controls.ApplicationLifetimes.IClassicDesktopStyleApplicationLifetime.add_ShutdownRequested(System.EventHandler<System.ComponentModel.CancelEventArgs>)' is present in the implementation but not in the contract.
-InterfacesShouldHaveSameMembers : Interface member 'public void Avalonia.Controls.ApplicationLifetimes.IClassicDesktopStyleApplicationLifetime.remove_ShutdownRequested(System.EventHandler<System.ComponentModel.CancelEventArgs>)' is present in the implementation but not in the contract.
+InterfacesShouldHaveSameMembers : Interface member 'public System.EventHandler<Avalonia.Controls.ApplicationLifetimes.ShutdownRequestedCancelEventArgs> Avalonia.Controls.ApplicationLifetimes.IClassicDesktopStyleApplicationLifetime.ShutdownRequested' is present in the implementation but not in the contract.
+InterfacesShouldHaveSameMembers : Interface member 'public void Avalonia.Controls.ApplicationLifetimes.IClassicDesktopStyleApplicationLifetime.add_ShutdownRequested(System.EventHandler<Avalonia.Controls.ApplicationLifetimes.ShutdownRequestedCancelEventArgs>)' is present in the implementation but not in the contract.
+InterfacesShouldHaveSameMembers : Interface member 'public void Avalonia.Controls.ApplicationLifetimes.IClassicDesktopStyleApplicationLifetime.remove_ShutdownRequested(System.EventHandler<Avalonia.Controls.ApplicationLifetimes.ShutdownRequestedCancelEventArgs>)' is present in the implementation but not in the contract.
 MembersMustExist : Member 'public void Avalonia.Controls.Embedding.Offscreen.OffscreenTopLevelImplBase.SetCursor(Avalonia.Platform.IPlatformHandle)' does not exist in the implementation but it does exist in the contract.
 MembersMustExist : Member 'public Avalonia.AvaloniaProperty Avalonia.AvaloniaProperty Avalonia.Controls.Notifications.NotificationCard.CloseOnClickProperty' does not exist in the implementation but it does exist in the contract.
 EnumValuesMustMatch : Enum value 'Avalonia.Platform.ExtendClientAreaChromeHints Avalonia.Platform.ExtendClientAreaChromeHints.Default' is (System.Int32)2 in the implementation but (System.Int32)1 in the contract.

+ 2 - 2
src/Avalonia.Controls/ApplicationLifetimes/ClassicDesktopStyleApplicationLifetime.cs

@@ -48,7 +48,7 @@ namespace Avalonia.Controls.ApplicationLifetimes
         public event EventHandler<ControlledApplicationLifetimeStartupEventArgs> Startup;
 
         /// <inheritdoc/>
-        public event EventHandler<CancelEventArgs> ShutdownRequested;
+        public event EventHandler<ShutdownRequestedCancelEventArgs> ShutdownRequested;
 
         /// <inheritdoc/>
         public event EventHandler<ControlledApplicationLifetimeExitEventArgs> Exit;
@@ -134,7 +134,7 @@ namespace Avalonia.Controls.ApplicationLifetimes
                 _activeLifetime = null;
         }
         
-        private void OnShutdownRequested(object sender, CancelEventArgs e)
+        private void OnShutdownRequested(object sender, ShutdownRequestedCancelEventArgs e)
         {
             ShutdownRequested?.Invoke(this, e);
 

+ 1 - 1
src/Avalonia.Controls/ApplicationLifetimes/IClassicDesktopStyleApplicationLifetime.cs

@@ -52,6 +52,6 @@ namespace Avalonia.Controls.ApplicationLifetimes
         /// will try to close each non-owned open window, invoking the <see cref="Window.Closing"/> event on each and allowing
         /// each window to cancel the shutdown of the application. Windows cannot however prevent OS shutdown.
         /// </remarks>
-        event EventHandler<CancelEventArgs> ShutdownRequested;
+        event EventHandler<ShutdownRequestedCancelEventArgs> ShutdownRequested;
     }
 }

+ 9 - 0
src/Avalonia.Controls/ApplicationLifetimes/ShutdownRequestedCancelEventArgs.cs

@@ -0,0 +1,9 @@
+using System.ComponentModel;
+
+namespace Avalonia.Controls.ApplicationLifetimes
+{
+    public class ShutdownRequestedCancelEventArgs : CancelEventArgs
+    {
+
+    }
+}

+ 2 - 1
src/Avalonia.Controls/Platform/IPlatformLifetimeEventsImpl.cs

@@ -1,5 +1,6 @@
 using System;
 using System.ComponentModel;
+using Avalonia.Controls.ApplicationLifetimes;
 
 namespace Avalonia.Platform
 {
@@ -11,6 +12,6 @@ namespace Avalonia.Platform
         /// <remarks>
         /// Raised on on OSX via the Quit menu or right-clicking on the application icon and selecting Quit.
         /// </remarks>
-        event EventHandler<CancelEventArgs> ShutdownRequested;
+        event EventHandler<ShutdownRequestedCancelEventArgs> ShutdownRequested;
     }
 }

+ 3 - 2
src/Avalonia.Native/AvaloniaNativeApplicationPlatform.cs

@@ -1,5 +1,6 @@
 using System;
 using System.ComponentModel;
+using Avalonia.Controls.ApplicationLifetimes;
 using Avalonia.Native.Interop;
 using Avalonia.Platform;
 
@@ -7,7 +8,7 @@ namespace Avalonia.Native
 {
     internal class AvaloniaNativeApplicationPlatform : CallbackBase, IAvnApplicationEvents, IPlatformLifetimeEventsImpl
     {
-        public event EventHandler<CancelEventArgs> ShutdownRequested;
+        public event EventHandler<ShutdownRequestedCancelEventArgs> ShutdownRequested;
         
         void IAvnApplicationEvents.FilesOpened(IAvnStringArray urls)
         {
@@ -17,7 +18,7 @@ namespace Avalonia.Native
         public int TryShutdown()
         {
             if (ShutdownRequested is null) return 1;
-            var e = new CancelEventArgs();
+            var e = new ShutdownRequestedCancelEventArgs();
             ShutdownRequested(this, e);
             return (!e.Cancel).AsComBool();
         }

+ 3 - 5
src/Windows/Avalonia.Win32/Win32Platform.cs

@@ -6,18 +6,16 @@ using System.IO;
 using System.Reactive.Disposables;
 using System.Runtime.InteropServices;
 using System.Threading;
-using Avalonia.Animation;
 using Avalonia.Controls;
+using Avalonia.Controls.ApplicationLifetimes;
 using Avalonia.Controls.Platform;
 using Avalonia.Input;
 using Avalonia.Input.Platform;
 using Avalonia.OpenGL;
-using Avalonia.OpenGL.Egl;
 using Avalonia.Platform;
 using Avalonia.Rendering;
 using Avalonia.Threading;
 using Avalonia.Utilities;
-using Avalonia.Win32;
 using Avalonia.Win32.Input;
 using Avalonia.Win32.Interop;
 using static Avalonia.Win32.Interop.UnmanagedMethods;
@@ -208,7 +206,7 @@ namespace Avalonia.Win32
 
         public event Action<DispatcherPriority?> Signaled;
 
-        public event EventHandler<CancelEventArgs> ShutdownRequested;
+        public event EventHandler<ShutdownRequestedCancelEventArgs> ShutdownRequested;
 
         [SuppressMessage("Microsoft.StyleCop.CSharp.NamingRules", "SA1305:FieldNamesMustNotUseHungarianNotation", Justification = "Using Win32 naming for consistency.")]
         private IntPtr WndProc(IntPtr hWnd, uint msg, IntPtr wParam, IntPtr lParam)
@@ -222,7 +220,7 @@ namespace Avalonia.Win32
             {
                 if (ShutdownRequested != null)
                 {
-                    var e = new CancelEventArgs();
+                    var e = new ShutdownRequestedCancelEventArgs();
 
                     ShutdownRequested(this, e);
 

+ 1 - 1
tests/Avalonia.Controls.UnitTests/DesktopStyleApplicationLifetimeTests.cs

@@ -232,7 +232,7 @@ namespace Avalonia.Controls.UnitTests
                     ++raised;
                 };
 
-                lifetimeEvents.Raise(x => x.ShutdownRequested += null, new CancelEventArgs());
+                lifetimeEvents.Raise(x => x.ShutdownRequested += null, new ShutdownRequestedCancelEventArgs());
 
                 Assert.Equal(1, raised);
                 Assert.Equal(new[] { window }, lifetime.Windows);