-
Notifications
You must be signed in to change notification settings - Fork 0
/
IEditedValue.cs
57 lines (52 loc) · 3.06 KB
/
IEditedValue.cs
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
55
56
57
namespace BaseLib
{
/// <summary> Parsed value has changed, possibly back to the original value. Events only occur when the input
/// text is successfully parsed! notOriginal = the new value != original value. Should not occur for
/// non-significant text formatting differences, e.g. for T = double a value of " 0 " should equal
/// "0.000" so changing 0 to 0.000 should not cause an event. </summary>
/// <param name="sender">Originating object</param>
/// <param name="newValue">New current value</param>
/// <param name="newEqualsOriginal">True if value being set == original value </param>
public delegate void EditedValueChangedEventHandler<in T>(object sender, T newValue, bool newEqualsOriginal);
/// <summary>
/// Base interface for IEditedValue<T>. Edited value supporting editing values as text, change detect,
/// validation and cancel to restore the original state.
/// </summary>
public interface IEditedValueBase : ICloseable
{
/// <summary> Associated control object </summary>
object Control { get; set; }
/// <summary> True if current (last successfully parsed) value == original value. If the InputText value is
/// invalid then the current parsed value will be old! Ignores non-significant text formatting issues such as
/// whitespace and trailing zeroes, e.g. for <double> " 0" == "0.000 " </summary>
bool EqualsOriginal { get; }
/// <summary> True if both current (last successfully parsed) value == original value AND the InputText value
/// matches the original InputText value, ignoring case and leading / trailing whitespace.
/// E.g. " 0 " == "0" </summary>
bool InputAndValueEqualsOriginal { get; }
/// <summary> Null if input text is valid, errorMessage from tryParse if not. </summary>
string InputErrorMessage { get; }
/// <summary> True if changed InputText passes parsing by tryParse. Initial value is not required to be valid.
/// </summary>
bool InputValid { get; }
/// <summary>
/// Cancel changes: restore original value, issuing event on change.
/// </summary>
void Cancel();
}
/// <summary>
/// Edited value <T> supporting editing values as text, change detect, validation and cancel to restore the
/// original state.
/// </summary>
public interface IEditedValue<out T> : IEditedValueBase
{
/// <summary> (Valid) parsed value is about to change </summary>
event EditedValueChangedEventHandler<T> ValuePreChangeEvent;
/// <summary> (Valid) parsed value has just changed </summary>
event EditedValueChangedEventHandler<T> ValueChanged;
/// <summary> Original value. Can be changed by SetOriginal(). </summary>
T OriginalValue { get; }
/// <summary> Current value. Will be old if inputText is invalid. </summary>
T Value { get; }
}
}