Browse Source

Use C# events in more controls

Artyom 4 years ago
parent
commit
28805f3c5c

+ 1 - 1
Terminal.Gui/Views/Checkbox.cs

@@ -25,7 +25,7 @@ namespace Terminal.Gui {
 		///   raised when the <see cref="CheckBox"/> is activated either with
 		///   the mouse or the keyboard. The passed <c>bool</c> contains the previous state. 
 		/// </remarks>
-		public Action<bool> Toggled;
+		public event Action<bool> Toggled;
 
 		/// <summary>
 		/// Called when the <see cref="Checked"/> property changes. Invokes the <see cref="Toggled"/> event.

+ 2 - 2
Terminal.Gui/Views/ComboBox.cs

@@ -57,12 +57,12 @@ namespace Terminal.Gui {
 		/// <summary>
 		/// This event is raised when the selected item in the <see cref="ComboBox"/> has changed.
 		/// </summary>
-		public Action<ListViewItemEventArgs> SelectedItemChanged;
+		public event Action<ListViewItemEventArgs> SelectedItemChanged;
 
 		/// <summary>
 		/// This event is raised when the user Double Clicks on an item or presses ENTER to open the selected item.
 		/// </summary>
-		public Action<ListViewItemEventArgs> OpenSelectedItem;
+		public event Action<ListViewItemEventArgs> OpenSelectedItem;
 
 		IList searchset;
 		ustring text = "";

+ 1 - 1
Terminal.Gui/Views/DateField.cs

@@ -38,7 +38,7 @@ namespace Terminal.Gui {
 		/// <remarks>
 		///   The passed event arguments containing the old value, new value, and format string.
 		/// </remarks>
-		public Action<DateTimeEventArgs<DateTime>> DateChanged;
+		public event Action<DateTimeEventArgs<DateTime>> DateChanged;
 
 		/// <summary>
 		///    Initializes a new instance of <see cref="DateField"/> using <see cref="LayoutStyle.Absolute"/> layout.

+ 1 - 1
Terminal.Gui/Views/Label.cs

@@ -53,7 +53,7 @@ namespace Terminal.Gui {
 		///   raised when the button is activated either with
 		///   the mouse or the keyboard.
 		/// </remarks>
-		public Action Clicked;
+		public event Action Clicked;
 
 		///// <inheritdoc/>
 		//public new ustring Text {

+ 4 - 4
UICatalog/Scenarios/DynamicMenuBar.cs

@@ -236,7 +236,7 @@ namespace UICatalog {
 				Y = Pos.Bottom (_ckbIsTopLevel)
 			};
 			_frmMenuDetails.Add (_ckbSubMenu);
-			_ckbIsTopLevel.Toggled = (e) => {
+			_ckbIsTopLevel.Toggled += (e) => {
 				if (_ckbIsTopLevel.Checked && _currentEditMenuBarItem.Parent != null) {
 					MessageBox.ErrorQuery ("Invalid IsTopLevel", "Only menu bar can have top level menu item!", "Ok");
 					_ckbIsTopLevel.Checked = false;
@@ -250,7 +250,7 @@ namespace UICatalog {
 					_txtAction.ReadOnly = true;
 				}
 			};
-			_ckbSubMenu.Toggled = (e) => {
+			_ckbSubMenu.Toggled += (e) => {
 				if (_ckbSubMenu.Checked) {
 					_ckbIsTopLevel.Checked = false;
 					_ckbIsTopLevel.SetNeedsDisplay ();
@@ -746,7 +746,7 @@ namespace UICatalog {
 					Y = Pos.Bottom (_ckbIsTopLevel),
 					Checked = menuItem == null
 				};
-				_ckbIsTopLevel.Toggled = (e) => {
+				_ckbIsTopLevel.Toggled += (e) => {
 					if (_ckbIsTopLevel.Checked && menuItem != null) {
 						MessageBox.ErrorQuery ("Invalid IsTopLevel", "Only menu bar can have top level menu item!", "Ok");
 						_ckbIsTopLevel.Checked = false;
@@ -760,7 +760,7 @@ namespace UICatalog {
 						_txtAction.ReadOnly = true;
 					}
 				};
-				_ckbSubMenu.Toggled = (e) => {
+				_ckbSubMenu.Toggled += (e) => {
 					if (_ckbSubMenu.Checked) {
 						_ckbIsTopLevel.Checked = false;
 						_ckbIsTopLevel.SetNeedsDisplay ();

+ 12 - 12
UICatalog/Scenarios/LabelsAsButtons.cs

@@ -29,17 +29,17 @@ namespace UICatalog {
 				//TODO: Change to use Pos.AnchorEnd()
 				Y = Pos.Bottom (Win) - 3,
 				//IsDefault = true,
-				Clicked = () => Application.RequestStop (),
 				HotKeySpecifier = (System.Rune)'_',
 				CanFocus = true,
 			};
+			defaultLabel.Clicked += () => Application.RequestStop ();
 			Win.Add (defaultLabel);
 
 			var swapLabel = new Label (50, 0, "S_wap Default (Absolute Layout)") {
 				HotKeySpecifier = (System.Rune)'_',
 				CanFocus = true,
 			};
-			swapLabel.Clicked = () => {
+			swapLabel.Clicked += () => {
 				//defaultLabel.IsDefault = !defaultLabel.IsDefault;
 				//swapLabel.IsDefault = !swapLabel.IsDefault;
 			};
@@ -47,7 +47,7 @@ namespace UICatalog {
 
 			static void DoMessage (Label Label, ustring txt)
 			{
-				Label.Clicked = () => {
+				Label.Clicked += () => {
 					var btnText = Label.Text.ToString ();
 					MessageBox.Query ("Message", $"Did you click {txt}?", "Yes", "No");
 				};
@@ -88,10 +88,10 @@ namespace UICatalog {
 			Win.Add (Label = new Label ("a Newline\nin the Label") {
 				X = 2,
 				Y = Pos.Bottom (Label) + 1,
-				Clicked = () => MessageBox.Query ("Message", "Question?", "Yes", "No"),
 				HotKeySpecifier = (System.Rune)'_',
 				CanFocus = true,
 			});
+			Label.Clicked += () => MessageBox.Query ("Message", "Question?", "Yes", "No");
 
 			var textChanger = new Label ("Te_xt Changer") {
 				X = 2,
@@ -100,7 +100,7 @@ namespace UICatalog {
 				CanFocus = true,
 			};
 			Win.Add (textChanger);
-			textChanger.Clicked = () => textChanger.Text += "!";
+			textChanger.Clicked += () => textChanger.Text += "!";
 
 			Win.Add (Label = new Label ("Lets see if this will move as \"Text Changer\" grows") {
 				X = Pos.Right (textChanger) + 2,
@@ -118,7 +118,7 @@ namespace UICatalog {
 			};
 			Win.Add (removeLabel);
 			// This in intresting test case because `moveBtn` and below are laid out relative to this one!
-			removeLabel.Clicked = () => Win.Remove (removeLabel);
+			removeLabel.Clicked += () => Win.Remove (removeLabel);
 
 			var computedFrame = new FrameView ("Computed Layout") {
 				X = 0,
@@ -137,7 +137,7 @@ namespace UICatalog {
 				HotKeySpecifier = (System.Rune)'_',
 				CanFocus = true,
 			};
-			moveBtn.Clicked = () => {
+			moveBtn.Clicked += () => {
 				moveBtn.X = moveBtn.Frame.X + 5;
 				// This is already fixed with the call to SetNeedDisplay() in the Pos Dim.
 				//computedFrame.LayoutSubviews (); // BUGBUG: This call should not be needed. View.X is not causing relayout correctly
@@ -154,7 +154,7 @@ namespace UICatalog {
 				HotKeySpecifier = (System.Rune)'_',
 				CanFocus = true,
 			};
-			sizeBtn.Clicked = () => {
+			sizeBtn.Clicked += () => {
 				sizeBtn.Width = sizeBtn.Frame.Width + 5;
 				//computedFrame.LayoutSubviews (); // FIXED: This call should not be needed. View.X is not causing relayout correctly
 			};
@@ -174,7 +174,7 @@ namespace UICatalog {
 				HotKeySpecifier = (System.Rune)'_',
 				CanFocus = true,
 			};
-			moveBtnA.Clicked = () => {
+			moveBtnA.Clicked += () => {
 				moveBtnA.Frame = new Rect (moveBtnA.Frame.X + 5, moveBtnA.Frame.Y, moveBtnA.Frame.Width, moveBtnA.Frame.Height);
 			};
 			absoluteFrame.Add (moveBtnA);
@@ -185,7 +185,7 @@ namespace UICatalog {
 				HotKeySpecifier = (System.Rune)'_',
 				CanFocus = true,
 			};
-			sizeBtnA.Clicked = () => {
+			sizeBtnA.Clicked += () => {
 				sizeBtnA.Frame = new Rect (sizeBtnA.Frame.X, sizeBtnA.Frame.Y, sizeBtnA.Frame.Width + 5, sizeBtnA.Frame.Height);
 			};
 			absoluteFrame.Add (sizeBtnA);
@@ -240,7 +240,7 @@ namespace UICatalog {
 				HotKeySpecifier = (System.Rune)'_',
 				CanFocus = true,
 			};
-			moveHotKeyBtn.Clicked = () => {
+			moveHotKeyBtn.Clicked += () => {
 				moveHotKeyBtn.Text = MoveHotkey (moveHotKeyBtn.Text);
 			};
 			Win.Add (moveHotKeyBtn);
@@ -254,7 +254,7 @@ namespace UICatalog {
 				HotKeySpecifier = (System.Rune)'_',
 				CanFocus = true,
 			};
-			moveUnicodeHotKeyBtn.Clicked = () => {
+			moveUnicodeHotKeyBtn.Clicked += () => {
 				moveUnicodeHotKeyBtn.Text = MoveHotkey (moveUnicodeHotKeyBtn.Text);
 			};
 			Win.Add (moveUnicodeHotKeyBtn);