-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTextFieldExtensions.cs
More file actions
54 lines (50 loc) · 2.25 KB
/
Copy pathTextFieldExtensions.cs
File metadata and controls
54 lines (50 loc) · 2.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
using Terminal.Gui.App;
using Terminal.Gui.Views;
namespace TerminalGui.Extensions.Extensions.ViewExtensions;
/// <summary>
/// Extension methods for <see cref="TextField" />.
/// </summary>
public static class TextFieldExtensions
{
extension(TextField textField)
{
/// <summary>
/// Subscribes to the <see cref="TextField.ValueChanged" /> event.
/// </summary>
/// <param name="callback">
/// The callback to invoke with the <see cref="ValueChangedEventArgs{T}" /> containing old and new
/// values.
/// </param>
/// <returns>The <see cref="TextField" /> instance.</returns>
public TextField OnValueChanged(Action<ValueChangedEventArgs<string?>> callback)
{
textField.ValueChanged += (_, e) => callback(e);
return textField;
}
/// <summary>
/// Subscribes to the <see cref="TextField.TextChanging" /> event.
/// Set <see cref="ResultEventArgs{T}.Result" /> to <see langword="null" /> in the callback to cancel the change.
/// </summary>
/// <param name="callback">The callback to invoke with the <see cref="ResultEventArgs{T}" /> containing the proposed text.</param>
/// <returns>The <see cref="TextField" /> instance.</returns>
public TextField OnTextChanging(Action<ResultEventArgs<string>> callback)
{
textField.TextChanging += (_, e) => callback(e);
return textField;
}
/// <summary>
/// Subscribes to the <see cref="TextField.ValueChanging" /> event.
/// Set <see cref="ValueChangingEventArgs{T}.Handled" /> to <see langword="true" /> to cancel the change.
/// </summary>
/// <param name="callback">
/// The callback to invoke with the <see cref="ValueChangingEventArgs{T}" /> containing current and
/// proposed values.
/// </param>
/// <returns>The <see cref="TextField" /> instance.</returns>
public TextField OnValueChanging(Action<ValueChangingEventArgs<string?>> callback)
{
textField.ValueChanging += (_, e) => callback(e);
return textField;
}
}
}