Browse Source

use a ShutdownRequestedEventArgs class to future proof the event args.

pull/6310/head
Dan Walmsley 5 years ago
parent
commit
c9458e5be8
  1. 6
      src/Avalonia.Controls/ApiCompatBaseline.txt
  2. 4
      src/Avalonia.Controls/ApplicationLifetimes/ClassicDesktopStyleApplicationLifetime.cs
  3. 2
      src/Avalonia.Controls/ApplicationLifetimes/IClassicDesktopStyleApplicationLifetime.cs
  4. 9
      src/Avalonia.Controls/ApplicationLifetimes/ShutdownRequestedCancelEventArgs.cs
  5. 3
      src/Avalonia.Controls/Platform/IPlatformLifetimeEventsImpl.cs
  6. 5
      src/Avalonia.Native/AvaloniaNativeApplicationPlatform.cs
  7. 8
      src/Windows/Avalonia.Win32/Win32Platform.cs
  8. 2
      tests/Avalonia.Controls.UnitTests/DesktopStyleApplicationLifetimeTests.cs

6
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 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.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. 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 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<System.ComponentModel.CancelEventArgs>)' 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<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<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 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. 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. EnumValuesMustMatch : Enum value 'Avalonia.Platform.ExtendClientAreaChromeHints Avalonia.Platform.ExtendClientAreaChromeHints.Default' is (System.Int32)2 in the implementation but (System.Int32)1 in the contract.

4
src/Avalonia.Controls/ApplicationLifetimes/ClassicDesktopStyleApplicationLifetime.cs

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

2
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 /// 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. /// each window to cancel the shutdown of the application. Windows cannot however prevent OS shutdown.
/// </remarks> /// </remarks>
event EventHandler<CancelEventArgs> ShutdownRequested; event EventHandler<ShutdownRequestedCancelEventArgs> ShutdownRequested;
} }
} }

9
src/Avalonia.Controls/ApplicationLifetimes/ShutdownRequestedCancelEventArgs.cs

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

3
src/Avalonia.Controls/Platform/IPlatformLifetimeEventsImpl.cs

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

5
src/Avalonia.Native/AvaloniaNativeApplicationPlatform.cs

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

8
src/Windows/Avalonia.Win32/Win32Platform.cs

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

2
tests/Avalonia.Controls.UnitTests/DesktopStyleApplicationLifetimeTests.cs

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

Loading…
Cancel
Save