소스 검색

Add ViewEventArgs

tznind 2 년 전
부모
커밋
7764006932

+ 2 - 2
Terminal.Gui/Configuration/ThemeScope.cs

@@ -176,14 +176,14 @@ namespace Terminal.Gui.Configuration {
 			internal void OnThemeChanged (string theme)
 			{
 				Debug.WriteLine ($"Themes.OnThemeChanged({theme}) -> {Theme}");
-				ThemeChanged?.Invoke (new ThemeManagerEventArgs (theme));
+				ThemeChanged?.Invoke (this, new ThemeManagerEventArgs (theme));
 			}
 
 			/// <summary>
 			/// Event fired he selected theme has changed.
 			/// application.
 			/// </summary>
-			public event Action<ThemeManagerEventArgs>? ThemeChanged;
+			public event EventHandler<ThemeManagerEventArgs>? ThemeChanged;
 
 			/// <summary>
 			/// Holds the <see cref="ThemeScope"/> definitions. 

+ 6 - 6
Terminal.Gui/Core/Application.cs

@@ -267,7 +267,7 @@ namespace Terminal.Gui {
 		///	<see cref="Begin(Toplevel)"/> must also subscribe to <see cref="NotifyStopRunState"/>
 		///	and manually dispose of the <see cref="RunState"/> token when the application is done.
 		/// </remarks>
-		public static event Action<Toplevel> NotifyStopRunState;
+		public static event EventHandler<ToplevelEventArgs> NotifyStopRunState;
 
 		/// <summary>
 		///   This event is raised on each iteration of the <see cref="MainLoop"/>. 
@@ -723,12 +723,12 @@ namespace Terminal.Gui {
 		/// <summary>
 		/// Event to be invoked when a view grab the mouse.
 		/// </summary>
-		public static event Action<View> GrabbedMouse;
+		public static event EventHandler<ViewEventArgs> GrabbedMouse;
 
 		/// <summary>
 		/// Event to be invoked when a view ungrab the mouse.
 		/// </summary>
-		public static event Action<View> UnGrabbedMouse;
+		public static event EventHandler<ViewEventArgs> UnGrabbedMouse;
 
 		/// <summary>
 		/// Grabs the mouse, forcing all mouse events to be routed to the specified view until UngrabMouse is called.
@@ -760,14 +760,14 @@ namespace Terminal.Gui {
 		{
 			if (view == null)
 				return;
-			GrabbedMouse?.Invoke (view);
+			GrabbedMouse?.Invoke (view, new ViewEventArgs(view));
 		}
 
 		static void OnUnGrabbedMouse (View view)
 		{
 			if (view == null)
 				return;
-			UnGrabbedMouse?.Invoke (view);
+			UnGrabbedMouse?.Invoke (view, new ViewEventArgs (view));
 		}
 
 		/// <summary>
@@ -1497,7 +1497,7 @@ namespace Terminal.Gui {
 		static void OnNotifyStopRunState (Toplevel top)
 		{
 			if (ExitRunLoopAfterFirstIteration) {
-				NotifyStopRunState?.Invoke (top);
+				NotifyStopRunState?.Invoke (top, new ToplevelEventArgs(top));
 			}
 		}
 

+ 16 - 0
Terminal.Gui/Core/EventArgs/ViewEventArgs.cs

@@ -0,0 +1,16 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace Terminal.Gui{
+	public class ViewEventArgs :EventArgs{
+		public ViewEventArgs (View view)
+		{
+			View = view;
+		}
+
+		public View View { get; }
+	}
+}

+ 8 - 8
UnitTests/Application/ApplicationTests.cs

@@ -978,27 +978,27 @@ namespace Terminal.Gui.ApplicationTests {
 			Assert.Equal (grabView, view2);
 			Assert.Null (Application.MouseGrabView);
 
-			void Application_GrabbedMouse (View obj)
+			void Application_GrabbedMouse (object sender, ViewEventArgs e)
 			{
 				if (count == 0) {
-					Assert.Equal (view1, obj);
+					Assert.Equal (view1, e.View);
 					grabView = view1;
 				} else {
-					Assert.Equal (view2, obj);
+					Assert.Equal (view2, e.View);
 					grabView = view2;
 				}
 
 				Application.GrabbedMouse -= Application_GrabbedMouse;
 			}
 
-			void Application_UnGrabbedMouse (View obj)
+			void Application_UnGrabbedMouse (object sender, ViewEventArgs e)
 			{
 				if (count == 0) {
-					Assert.Equal (view1, obj);
-					Assert.Equal (grabView, obj);
+					Assert.Equal (view1, e.View);
+					Assert.Equal (grabView, e.View);
 				} else {
-					Assert.Equal (view2, obj);
-					Assert.Equal (grabView, obj);
+					Assert.Equal (view2, e.View);
+					Assert.Equal (grabView, e.View);
 				}
 				count++;