diff --git a/Terminal.Gui/Views/ComboBox.cs b/Terminal.Gui/Views/ComboBox.cs
index b204d33b8..4bae179bf 100644
--- a/Terminal.Gui/Views/ComboBox.cs
+++ b/Terminal.Gui/Views/ComboBox.cs
@@ -188,7 +188,7 @@ namespace Terminal.Gui {
if (SuperView != null && SuperView.Subviews.Contains (this)) {
SelectedItem = -1;
search.Text = "";
- Search_Changed ("");
+ Search_Changed (this, new TextChangedEventArgs(""));
SetNeedsDisplay ();
}
}
@@ -328,7 +328,7 @@ namespace Terminal.Gui {
SetNeedsLayout ();
SetNeedsDisplay ();
- Search_Changed (Text);
+ Search_Changed (this, new TextChangedEventArgs( Text));
};
// Things this view knows how to do
@@ -750,7 +750,7 @@ namespace Terminal.Gui {
SetValue (searchset [listview.SelectedItem]);
search.CursorPosition = search.Text.ConsoleWidth;
- Search_Changed (search.Text);
+ Search_Changed (this, new TextChangedEventArgs(search.Text));
OnOpenSelectedItem ();
Reset (keepSearchText: true);
HideList ();
@@ -806,15 +806,15 @@ namespace Terminal.Gui {
}
}
- private void Search_Changed (ustring text)
+ private void Search_Changed (object sender, TextChangedEventArgs e)
{
if (source == null) { // Object initialization
return;
}
- if (ustring.IsNullOrEmpty (search.Text) && ustring.IsNullOrEmpty (text)) {
+ if (ustring.IsNullOrEmpty (search.Text) && ustring.IsNullOrEmpty (e.OldValue)) {
ResetSearchSet ();
- } else if (search.Text != text) {
+ } else if (search.Text != e.OldValue) {
isShow = true;
ResetSearchSet (noCopy: true);
diff --git a/Terminal.Gui/Views/DateField.cs b/Terminal.Gui/Views/DateField.cs
index d88648a41..98c1ae095 100644
--- a/Terminal.Gui/Views/DateField.cs
+++ b/Terminal.Gui/Views/DateField.cs
@@ -106,13 +106,13 @@ namespace Terminal.Gui {
AddKeyBinding (Key.F | Key.CtrlMask, Command.Right);
}
- void DateField_Changed (ustring e)
+ void DateField_Changed (object sender, TextChangedEventArgs e)
{
try {
if (!DateTime.TryParseExact (GetDate (Text).ToString (), GetInvarianteFormat (), CultureInfo.CurrentCulture, DateTimeStyles.None, out DateTime result))
- Text = e;
+ Text = e.OldValue;
} catch (Exception) {
- Text = e;
+ Text = e.OldValue;
}
}
diff --git a/Terminal.Gui/Views/TextField.cs b/Terminal.Gui/Views/TextField.cs
index f37e5da9d..f907ad529 100644
--- a/Terminal.Gui/Views/TextField.cs
+++ b/Terminal.Gui/Views/TextField.cs
@@ -53,7 +53,7 @@ namespace Terminal.Gui {
///
/// The passed is a containing the old value.
///
- public event Action TextChanged;
+ public event EventHandler TextChanged;
///
/// Initializes a new instance of the class using positioning.
@@ -308,7 +308,7 @@ namespace Terminal.Gui {
, HistoryText.LineStatus.Replaced);
}
- TextChanged?.Invoke (oldText);
+ TextChanged?.Invoke (this, new TextChangedEventArgs(oldText));
if (point > text.Count) {
point = Math.Max (TextModel.DisplaySize (text, 0).size - 1, 0);
@@ -1331,7 +1331,25 @@ namespace Terminal.Gui {
NewText = newText;
}
}
+ ///
+ /// Event args for the event
+ ///
+ public class TextChangedEventArgs : EventArgs {
+ ///
+ /// Creates a new instance of the class
+ ///
+ ///
+ public TextChangedEventArgs (ustring oldValue)
+ {
+ OldValue = oldValue;
+ }
+
+ ///
+ /// The old value before the text changed
+ ///
+ public ustring OldValue { get; }
+ }
///
/// Renders an overlay on another view at a given point that allows selecting
/// from a range of 'autocomplete' options.
diff --git a/Terminal.Gui/Views/TimeField.cs b/Terminal.Gui/Views/TimeField.cs
index 132803dbc..b2f9ba018 100644
--- a/Terminal.Gui/Views/TimeField.cs
+++ b/Terminal.Gui/Views/TimeField.cs
@@ -106,13 +106,13 @@ namespace Terminal.Gui {
AddKeyBinding (Key.F | Key.CtrlMask, Command.Right);
}
- void TextField_TextChanged (ustring e)
+ void TextField_TextChanged (object sender, TextChangedEventArgs e)
{
try {
if (!TimeSpan.TryParseExact (Text.ToString ().Trim (), format.Trim (), CultureInfo.CurrentCulture, TimeSpanStyles.None, out TimeSpan result))
- Text = e;
+ Text = e.OldValue;
} catch (Exception) {
- Text = e;
+ Text = e.OldValue;
}
}
diff --git a/Terminal.Gui/Windows/FileDialog.cs b/Terminal.Gui/Windows/FileDialog.cs
index 2d2307967..eb8df038f 100644
--- a/Terminal.Gui/Windows/FileDialog.cs
+++ b/Terminal.Gui/Windows/FileDialog.cs
@@ -649,7 +649,7 @@ namespace Terminal.Gui {
Y = 1 + msgLines,
Width = Dim.Fill () - 1,
};
- dirEntry.TextChanged += (e) => {
+ dirEntry.TextChanged += (s, e) => {
DirectoryPath = dirEntry.Text;
nameEntry.Text = ustring.Empty;
};
@@ -731,7 +731,7 @@ namespace Terminal.Gui {
};
AddButton (this.prompt);
- nameEntry.TextChanged += (e) => {
+ nameEntry.TextChanged += (s,e) => {
if (nameEntry.Text.IsEmpty) {
this.prompt.Enabled = false;
} else {
diff --git a/UICatalog/Scenarios/AllViewsTester.cs b/UICatalog/Scenarios/AllViewsTester.cs
index 2c52dc7d5..45cffdbfd 100644
--- a/UICatalog/Scenarios/AllViewsTester.cs
+++ b/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 += (args) => {
+ _xText.TextChanged += (s, 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 += (args) => {
+ _yText.TextChanged += (s,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 += (args) => {
+ _wText.TextChanged += (s,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 += (args) => {
+ _hText.TextChanged += (s, args) => {
try {
switch (_hRadioGroup.SelectedItem) {
case 0:
diff --git a/UICatalog/Scenarios/CharacterMap.cs b/UICatalog/Scenarios/CharacterMap.cs
index 6728d09e4..c9a7a0711 100644
--- a/UICatalog/Scenarios/CharacterMap.cs
+++ b/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) => {
+ jumpEdit.TextChanged += (s, e) => {
uint result = 0;
if (jumpEdit.Text.Length == 0) return;
try {
diff --git a/UICatalog/Scenarios/CsvEditor.cs b/UICatalog/Scenarios/CsvEditor.cs
index 04d49b6f2..14ee9fade 100644
--- a/UICatalog/Scenarios/CsvEditor.cs
+++ b/UICatalog/Scenarios/CsvEditor.cs
@@ -99,7 +99,7 @@ namespace UICatalog.Scenarios {
SetupScrollBar ();
}
- private void SelectedCellLabel_TextChanged (ustring last)
+ private void SelectedCellLabel_TextChanged (object sender, TextChangedEventArgs e)
{
// if user is in the text control and editing the selected cell
if (!selectedCellLabel.HasFocus)
diff --git a/UICatalog/Scenarios/DynamicMenuBar.cs b/UICatalog/Scenarios/DynamicMenuBar.cs
index 542c6897a..ebf710d55 100644
--- a/UICatalog/Scenarios/DynamicMenuBar.cs
+++ b/UICatalog/Scenarios/DynamicMenuBar.cs
@@ -89,7 +89,7 @@ namespace UICatalog.Scenarios {
X = Pos.Center (),
Width = 2,
};
- _txtDelimiter.TextChanged += (_) => MenuBar.ShortcutDelimiter = _txtDelimiter.Text;
+ _txtDelimiter.TextChanged += (s, _) => MenuBar.ShortcutDelimiter = _txtDelimiter.Text;
_frmDelimiter.Add (_txtDelimiter);
Add (_frmDelimiter);
diff --git a/UICatalog/Scenarios/DynamicStatusBar.cs b/UICatalog/Scenarios/DynamicStatusBar.cs
index d78327a63..6d5d1d73e 100644
--- a/UICatalog/Scenarios/DynamicStatusBar.cs
+++ b/UICatalog/Scenarios/DynamicStatusBar.cs
@@ -77,7 +77,7 @@ namespace UICatalog.Scenarios {
X = Pos.Center (),
Width = 2,
};
- _txtDelimiter.TextChanged += (_) => StatusBar.ShortcutDelimiter = _txtDelimiter.Text;
+ _txtDelimiter.TextChanged += (s, _) => StatusBar.ShortcutDelimiter = _txtDelimiter.Text;
_frmDelimiter.Add (_txtDelimiter);
Add (_frmDelimiter);
diff --git a/UICatalog/Scenarios/Editor.cs b/UICatalog/Scenarios/Editor.cs
index b17f5e0da..22b5ce678 100644
--- a/UICatalog/Scenarios/Editor.cs
+++ b/UICatalog/Scenarios/Editor.cs
@@ -813,7 +813,7 @@ namespace UICatalog.Scenarios {
btnFindPrevious.Clicked += (s,e) => FindPrevious ();
d.Add (btnFindPrevious);
- txtToFind.TextChanged += (e) => {
+ txtToFind.TextChanged += (s, 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 += (e) => _textToReplace = txtToReplace.Text.ToString ();
+ txtToReplace.TextChanged += (s, 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 += (e) => {
+ txtToFind.TextChanged += (s, e) => {
_textToFind = txtToFind.Text.ToString ();
_textView.FindTextChanged ();
btnFindNext.Enabled = !txtToFind.Text.IsEmpty;
diff --git a/UICatalog/Scenarios/Progress.cs b/UICatalog/Scenarios/Progress.cs
index a6869607d..40cbb5aa9 100644
--- a/UICatalog/Scenarios/Progress.cs
+++ b/UICatalog/Scenarios/Progress.cs
@@ -167,7 +167,7 @@ namespace UICatalog.Scenarios {
systemTimerDemo.PulseProgressBar.Fraction = 1F;
};
systemTimerDemo.Speed.Text = $"{_systemTimerTick}";
- systemTimerDemo.Speed.TextChanged += (a) => {
+ systemTimerDemo.Speed.TextChanged += (s, 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 += (a) => {
+ mainLoopTimeoutDemo.Speed.TextChanged += (s, a) => {
uint result;
if (uint.TryParse (mainLoopTimeoutDemo.Speed.Text.ToString (), out result)) {
_mainLooopTimeoutTick = result;
diff --git a/UICatalog/Scenarios/Text.cs b/UICatalog/Scenarios/Text.cs
index 7ed983528..8c37b828e 100644
--- a/UICatalog/Scenarios/Text.cs
+++ b/UICatalog/Scenarios/Text.cs
@@ -41,7 +41,7 @@ namespace UICatalog.Scenarios {
};
Win.Add (labelMirroringTextField);
- textField.TextChanged += (prev) => {
+ textField.TextChanged += (s, prev) => {
labelMirroringTextField.Text = textField.Text;
};
@@ -159,7 +159,7 @@ namespace UICatalog.Scenarios {
};
Win.Add (labelMirroringDateField);
- dateField.TextChanged += (prev) => {
+ dateField.TextChanged += (s, prev) => {
labelMirroringDateField.Text = dateField.Text;
};
diff --git a/UICatalog/Scenarios/TileViewNesting.cs b/UICatalog/Scenarios/TileViewNesting.cs
index 3cee1b195..983849c6c 100644
--- a/UICatalog/Scenarios/TileViewNesting.cs
+++ b/UICatalog/Scenarios/TileViewNesting.cs
@@ -36,7 +36,7 @@ namespace UICatalog.Scenarios {
Text = "2",
};
- textField.TextChanged += (s) => SetupTileView ();
+ textField.TextChanged += (s,e) => SetupTileView ();
cbHorizontal = new CheckBox ("Horizontal") {
diff --git a/UnitTests/UICatalog/ScenarioTests.cs b/UnitTests/UICatalog/ScenarioTests.cs
index 1104154b3..b530d1d69 100644
--- a/UnitTests/UICatalog/ScenarioTests.cs
+++ b/UnitTests/UICatalog/ScenarioTests.cs
@@ -312,7 +312,7 @@ namespace UICatalog.Tests {
_xRadioGroup.SelectedItemChanged += (s, selected) => DimPosChanged (_curView);
- _xText.TextChanged += (args) => {
+ _xText.TextChanged += (s, args) => {
try {
_xVal = int.Parse (_xText.Text.ToString ());
DimPosChanged (_curView);
@@ -321,7 +321,7 @@ namespace UICatalog.Tests {
}
};
- _yText.TextChanged += (args) => {
+ _yText.TextChanged += (s,e) => {
try {
_yVal = int.Parse (_yText.Text.ToString ());
DimPosChanged (_curView);
@@ -334,7 +334,7 @@ namespace UICatalog.Tests {
_wRadioGroup.SelectedItemChanged += (s, selected) => DimPosChanged (_curView);
- _wText.TextChanged += (args) => {
+ _wText.TextChanged += (s, args) => {
try {
_wVal = int.Parse (_wText.Text.ToString ());
DimPosChanged (_curView);
@@ -343,7 +343,7 @@ namespace UICatalog.Tests {
}
};
- _hText.TextChanged += (args) => {
+ _hText.TextChanged += (s, args) => {
try {
_hVal = int.Parse (_hText.Text.ToString ());
DimPosChanged (_curView);
diff --git a/UnitTests/Views/TextFieldTests.cs b/UnitTests/Views/TextFieldTests.cs
index 4eaa588ca..c44884818 100644
--- a/UnitTests/Views/TextFieldTests.cs
+++ b/UnitTests/Views/TextFieldTests.cs
@@ -681,8 +681,8 @@ namespace Terminal.Gui.ViewTests {
[TextFieldTestsAutoInitShutdown]
public void TextChanged_Event ()
{
- _textField.TextChanged += (e) => {
- Assert.Equal ("TAB to jump between text fields.", e);
+ _textField.TextChanged += (s,e) => {
+ Assert.Equal ("TAB to jump between text fields.", e.OldValue);
};
_textField.Text = "changed";
@@ -1138,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 += (e) => oldText = e.ToString ();
+ tf.TextChanged += (s, e) => oldText = e.OldValue.ToString ();
Application.Top.Add (tf);
Application.Begin (Application.Top);