Browse Source

Revert "Added TextChangedEventArgs"

This reverts commit fe2710ad2d8338f1a28228274a3eed95f8970f73.
tznind 2 years ago
parent
commit
4b5fbfb89c

+ 0 - 36
Terminal.Gui/Core/EventArgs/TextChangedEventArgs.cs

@@ -1,36 +0,0 @@
-using NStack;
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-
-namespace Terminal.Gui {
-
-	/// <summary>
-	/// Event args for events where text is changed
-	/// </summary>
-	public class TextChangedEventArgs : EventArgs {
-
-		/// <summary>
-		/// Creates a new instance of the <see cref="TextChangedEventArgs"/> class
-		/// </summary>
-		/// <param name="oldValue"></param>
-		/// <param name="newValue"></param>
-		public TextChangedEventArgs (ustring oldValue, ustring newValue)
-		{
-			OldValue = oldValue;
-			NewValue = newValue;
-		}
-
-		/// <summary>
-		/// The old value before the text changed
-		/// </summary>
-		public ustring OldValue { get; }
-
-		/// <summary>
-		/// The new value
-		/// </summary>
-		public ustring NewValue { get; }
-	}
-}

+ 1 - 4
Terminal.Gui/Views/ComboBox.cs

@@ -805,11 +805,8 @@ namespace Terminal.Gui {
 				searchset.Add (item);
 			}
 		}
+
 		private void Search_Changed (ustring text)
-		{
-			Search_Changed (this, new TextChangedEventArgs (text, text));
-		}
-		private void Search_Changed (object sender, TextChangedEventArgs args)
 		{
 			if (source == null) { // Object initialization		
 				return;

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

@@ -106,13 +106,13 @@ namespace Terminal.Gui {
 			AddKeyBinding (Key.F | Key.CtrlMask, Command.Right);
 		}
 
-		void DateField_Changed (object sender, TextChangedEventArgs e)
+		void DateField_Changed (ustring e)
 		{
 			try {
-				if (!DateTime.TryParseExact (GetDate (e.NewValue).ToString (), GetInvarianteFormat (), CultureInfo.CurrentCulture, DateTimeStyles.None, out DateTime result))
-					Text = e.OldValue;
+				if (!DateTime.TryParseExact (GetDate (Text).ToString (), GetInvarianteFormat (), CultureInfo.CurrentCulture, DateTimeStyles.None, out DateTime result))
+					Text = e;
 			} catch (Exception) {
-				Text = e.OldValue;
+				Text = e;
 			}
 		}
 

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

@@ -53,7 +53,7 @@ namespace Terminal.Gui {
 		/// <remarks>
 		///   The passed <see cref="EventArgs"/> is a <see cref="NStack.ustring"/> containing the old value. 
 		/// </remarks>
-		public event EventHandler<TextChangedEventArgs> TextChanged;
+		public event Action<ustring> TextChanged;
 
 		/// <summary>
 		/// Initializes a new instance of the <see cref="TextField"/> class using <see cref="LayoutStyle.Computed"/> positioning.
@@ -308,7 +308,7 @@ namespace Terminal.Gui {
 						, HistoryText.LineStatus.Replaced);
 				}
 
-				TextChanged?.Invoke (this, new TextChangedEventArgs(oldText, newText.NewText));
+				TextChanged?.Invoke (oldText);
 
 				if (point > text.Count) {
 					point = Math.Max (TextModel.DisplaySize (text, 0).size - 1, 0);

+ 4 - 4
Terminal.Gui/Views/TimeField.cs

@@ -106,13 +106,13 @@ namespace Terminal.Gui {
 			AddKeyBinding (Key.F | Key.CtrlMask, Command.Right);
 		}
 
-		void TextField_TextChanged (object sender, TextChangedEventArgs e)
+		void TextField_TextChanged (ustring e)
 		{
 			try {
-				if (!TimeSpan.TryParseExact (e.NewValue.ToString ().Trim (), format.Trim (), CultureInfo.CurrentCulture, TimeSpanStyles.None, out TimeSpan result))
-					Text = e.OldValue;
+				if (!TimeSpan.TryParseExact (Text.ToString ().Trim (), format.Trim (), CultureInfo.CurrentCulture, TimeSpanStyles.None, out TimeSpan result))
+					Text = e;
 			} catch (Exception) {
-				Text = e.OldValue;
+				Text = e;
 			}
 		}
 

+ 2 - 2
Terminal.Gui/Windows/FileDialog.cs

@@ -649,7 +649,7 @@ namespace Terminal.Gui {
 				Y = 1 + msgLines,
 				Width = Dim.Fill () - 1,
 			};
-			dirEntry.TextChanged += (s,e) => {
+			dirEntry.TextChanged += (e) => {
 				DirectoryPath = dirEntry.Text;
 				nameEntry.Text = ustring.Empty;
 			};
@@ -731,7 +731,7 @@ namespace Terminal.Gui {
 			};
 			AddButton (this.prompt);
 
-			nameEntry.TextChanged += (s, e) => {
+			nameEntry.TextChanged += (e) => {
 				if (nameEntry.Text.IsEmpty) {
 					this.prompt.Enabled = false;
 				} else {

+ 4 - 4
UICatalog/Scenarios/AllViewsTester.cs

@@ -126,7 +126,7 @@ namespace UICatalog.Scenarios {
 			};
 			_xRadioGroup.SelectedItemChanged += (s, selected) => DimPosChanged (_curView);
 			_xText = new TextField ($"{_xVal}") { X = Pos.Right (label) + 1, Y = 0, Width = 4 };
-			_xText.TextChanged += (s,args) => {
+			_xText.TextChanged += (args) => {
 				try {
 					_xVal = int.Parse (_xText.Text.ToString ());
 					DimPosChanged (_curView);
@@ -142,7 +142,7 @@ namespace UICatalog.Scenarios {
 			label = new Label ("y:") { X = Pos.Right (_xRadioGroup) + 1, Y = 0 };
 			_locationFrame.Add (label);
 			_yText = new TextField ($"{_yVal}") { X = Pos.Right (label) + 1, Y = 0, Width = 4 };
-			_yText.TextChanged += (s, args) => {
+			_yText.TextChanged += (args) => {
 				try {
 					_yVal = int.Parse (_yText.Text.ToString ());
 					DimPosChanged (_curView);
@@ -174,7 +174,7 @@ namespace UICatalog.Scenarios {
 			};
 			_wRadioGroup.SelectedItemChanged += (s, selected) => DimPosChanged (_curView);
 			_wText = new TextField ($"{_wVal}") { X = Pos.Right (label) + 1, Y = 0, Width = 4 };
-			_wText.TextChanged += (s,args) => {
+			_wText.TextChanged += (args) => {
 				try {
 					switch (_wRadioGroup.SelectedItem) {
 					case 0:
@@ -197,7 +197,7 @@ namespace UICatalog.Scenarios {
 			label = new Label ("height:") { X = Pos.Right (_wRadioGroup) + 1, Y = 0 };
 			_sizeFrame.Add (label);
 			_hText = new TextField ($"{_hVal}") { X = Pos.Right (label) + 1, Y = 0, Width = 4 };
-			_hText.TextChanged += (s, args) => {
+			_hText.TextChanged += (args) => {
 				try {
 					switch (_hRadioGroup.SelectedItem) {
 					case 0:

+ 1 - 1
UICatalog/Scenarios/CharacterMap.cs

@@ -39,7 +39,7 @@ namespace UICatalog.Scenarios {
 			Win.Add (jumpEdit);
 			var unicodeLabel = new Label ("") { X = Pos.Right (jumpEdit) + 1, Y = Pos.Y (_charMap) };
 			Win.Add (unicodeLabel);
-			jumpEdit.TextChanged += (s,e) => {
+			jumpEdit.TextChanged += (s) => {
 				uint result = 0;
 				if (jumpEdit.Text.Length == 0) return;
 				try {

+ 1 - 1
UICatalog/Scenarios/CsvEditor.cs

@@ -99,7 +99,7 @@ namespace UICatalog.Scenarios {
 			SetupScrollBar ();
 		}
 
-		private void SelectedCellLabel_TextChanged (object sender, TextChangedEventArgs args)
+		private void SelectedCellLabel_TextChanged (ustring last)
 		{
 			// if user is in the text control and editing the selected cell
 			if (!selectedCellLabel.HasFocus)

+ 1 - 1
UICatalog/Scenarios/DynamicMenuBar.cs

@@ -89,7 +89,7 @@ namespace UICatalog.Scenarios {
 					X = Pos.Center (),
 					Width = 2,
 				};
-				_txtDelimiter.TextChanged += (s,e) => MenuBar.ShortcutDelimiter = _txtDelimiter.Text;
+				_txtDelimiter.TextChanged += (_) => MenuBar.ShortcutDelimiter = _txtDelimiter.Text;
 				_frmDelimiter.Add (_txtDelimiter);
 
 				Add (_frmDelimiter);

+ 1 - 1
UICatalog/Scenarios/DynamicStatusBar.cs

@@ -77,7 +77,7 @@ namespace UICatalog.Scenarios {
 					X = Pos.Center (),
 					Width = 2,
 				};
-				_txtDelimiter.TextChanged += (s,e) => StatusBar.ShortcutDelimiter = _txtDelimiter.Text;
+				_txtDelimiter.TextChanged += (_) => StatusBar.ShortcutDelimiter = _txtDelimiter.Text;
 				_frmDelimiter.Add (_txtDelimiter);
 
 				Add (_frmDelimiter);

+ 3 - 3
UICatalog/Scenarios/Editor.cs

@@ -813,7 +813,7 @@ namespace UICatalog.Scenarios {
 			btnFindPrevious.Clicked += (s,e) => FindPrevious ();
 			d.Add (btnFindPrevious);
 
-			txtToFind.TextChanged += (s,e) => {
+			txtToFind.TextChanged += (e) => {
 				_textToFind = txtToFind.Text.ToString ();
 				_textView.FindTextChanged ();
 				btnFindNext.Enabled = !txtToFind.Text.IsEmpty;
@@ -908,7 +908,7 @@ namespace UICatalog.Scenarios {
 				Y = Pos.Top (label),
 				Width = 20
 			};
-			txtToReplace.TextChanged += (s,e) => _textToReplace = txtToReplace.Text.ToString ();
+			txtToReplace.TextChanged += (e) => _textToReplace = txtToReplace.Text.ToString ();
 			d.Add (txtToReplace);
 
 			var btnFindPrevious = new Button ("Replace _Previous") {
@@ -933,7 +933,7 @@ namespace UICatalog.Scenarios {
 			btnReplaceAll.Clicked += (s,e) => ReplaceAll ();
 			d.Add (btnReplaceAll);
 
-			txtToFind.TextChanged += (s, e) => {
+			txtToFind.TextChanged += (e) => {
 				_textToFind = txtToFind.Text.ToString ();
 				_textView.FindTextChanged ();
 				btnFindNext.Enabled = !txtToFind.Text.IsEmpty;

+ 2 - 2
UICatalog/Scenarios/Progress.cs

@@ -167,7 +167,7 @@ namespace UICatalog.Scenarios {
 				systemTimerDemo.PulseProgressBar.Fraction = 1F;
 			};
 			systemTimerDemo.Speed.Text = $"{_systemTimerTick}";
-			systemTimerDemo.Speed.TextChanged += (s, a) => {
+			systemTimerDemo.Speed.TextChanged += (a) => {
 				uint result;
 				if (uint.TryParse (systemTimerDemo.Speed.Text.ToString(), out result)) {
 					_systemTimerTick = result;
@@ -210,7 +210,7 @@ namespace UICatalog.Scenarios {
 			};
 
 			mainLoopTimeoutDemo.Speed.Text = $"{_mainLooopTimeoutTick}";
-			mainLoopTimeoutDemo.Speed.TextChanged += (s, a) => {
+			mainLoopTimeoutDemo.Speed.TextChanged += (a) => {
 				uint result;
 				if (uint.TryParse (mainLoopTimeoutDemo.Speed.Text.ToString (), out result)) {
 					_mainLooopTimeoutTick = result;

+ 2 - 2
UICatalog/Scenarios/Text.cs

@@ -41,7 +41,7 @@ namespace UICatalog.Scenarios {
 			};
 			Win.Add (labelMirroringTextField);
 
-			textField.TextChanged += (s, prev) => {
+			textField.TextChanged += (prev) => {
 				labelMirroringTextField.Text = textField.Text;
 			};
 
@@ -159,7 +159,7 @@ namespace UICatalog.Scenarios {
 			};
 			Win.Add (labelMirroringDateField);
 
-			dateField.TextChanged += (s, prev) => {
+			dateField.TextChanged += (prev) => {
 				labelMirroringDateField.Text = dateField.Text;
 			};
 

+ 1 - 1
UICatalog/Scenarios/TileViewNesting.cs

@@ -36,7 +36,7 @@ namespace UICatalog.Scenarios {
 				Text = "2",
 			};
 
-			textField.TextChanged += (s, e) => SetupTileView ();
+			textField.TextChanged += (s) => SetupTileView ();
 
 
 			cbHorizontal = new CheckBox ("Horizontal") {

+ 4 - 4
UnitTests/UICatalog/ScenarioTests.cs

@@ -312,7 +312,7 @@ namespace UICatalog.Tests {
 
 			_xRadioGroup.SelectedItemChanged += (s, selected) => DimPosChanged (_curView);
 
-			_xText.TextChanged += (s,args) => {
+			_xText.TextChanged += (args) => {
 				try {
 					_xVal = int.Parse (_xText.Text.ToString ());
 					DimPosChanged (_curView);
@@ -321,7 +321,7 @@ namespace UICatalog.Tests {
 				}
 			};
 
-			_yText.TextChanged += (s, args) => {
+			_yText.TextChanged += (args) => {
 				try {
 					_yVal = int.Parse (_yText.Text.ToString ());
 					DimPosChanged (_curView);
@@ -334,7 +334,7 @@ namespace UICatalog.Tests {
 
 			_wRadioGroup.SelectedItemChanged += (s, selected) => DimPosChanged (_curView);
 
-			_wText.TextChanged += (s, args) => {
+			_wText.TextChanged += (args) => {
 				try {
 					_wVal = int.Parse (_wText.Text.ToString ());
 					DimPosChanged (_curView);
@@ -343,7 +343,7 @@ namespace UICatalog.Tests {
 				}
 			};
 
-			_hText.TextChanged += (s, args) => {
+			_hText.TextChanged += (args) => {
 				try {
 					_hVal = int.Parse (_hText.Text.ToString ());
 					DimPosChanged (_curView);

+ 3 - 4
UnitTests/Views/TextFieldTests.cs

@@ -681,9 +681,8 @@ namespace Terminal.Gui.ViewTests {
 		[TextFieldTestsAutoInitShutdown]
 		public void TextChanged_Event ()
 		{
-			_textField.TextChanged += (s,e) => {
-				Assert.Equal ("TAB to jump between text fields.", e.OldValue);
-				Assert.Equal ("changed", e.NewValue);
+			_textField.TextChanged += (e) => {
+				Assert.Equal ("TAB to jump between text fields.", e);
 			};
 
 			_textField.Text = "changed";
@@ -1139,7 +1138,7 @@ namespace Terminal.Gui.ViewTests {
 			var tf = new TextField () { Width = 10, Text = "-1" };
 
 			tf.TextChanging += (s,e) => newText = e.NewText.ToString ();
-			tf.TextChanged += (s,e) => oldText = e.ToString ();
+			tf.TextChanged += (e) => oldText = e.ToString ();
 
 			Application.Top.Add (tf);
 			Application.Begin (Application.Top);