Controls: Rewrite UnitTextBox as extension of TextBox instead of UserControl
This commit is contained in:
@ -133,7 +133,6 @@ namespace Elwig.Windows {
|
||||
}
|
||||
|
||||
protected void ValidateInput(Control input, bool valid) {
|
||||
if (input is UnitTextBox utbx) input = utbx.TextBox;
|
||||
Valid[input] = valid;
|
||||
}
|
||||
|
||||
@ -234,7 +233,6 @@ namespace Elwig.Windows {
|
||||
}
|
||||
|
||||
protected void SetOriginalValue(Control input, object? value) {
|
||||
if (input is UnitTextBox utbx) input = utbx.TextBox;
|
||||
OriginalValues[input] = Utils.GetEntityIdentifier(value);
|
||||
if (InputHasChanged(input)) {
|
||||
ControlUtils.SetInputChanged(input);
|
||||
@ -244,18 +242,15 @@ namespace Elwig.Windows {
|
||||
}
|
||||
|
||||
protected void SetOriginalValue(Control input) {
|
||||
if (input is UnitTextBox utbx) input = utbx.TextBox;
|
||||
SetOriginalValue(input, ControlUtils.GetInputHashCode(input));
|
||||
}
|
||||
|
||||
protected void UnsetOriginalValue(Control input) {
|
||||
if (input is UnitTextBox utbx) input = utbx.TextBox;
|
||||
OriginalValues.Remove(input);
|
||||
ControlUtils.ClearInputState(input);
|
||||
}
|
||||
|
||||
protected void SetDefaultValue(Control input, object? value) {
|
||||
if (input is UnitTextBox utbx) input = utbx.TextBox;
|
||||
DefaultValues[input] = Utils.GetEntityIdentifier(value);
|
||||
if (!InputHasChanged(input)) {
|
||||
if (InputIsNotDefault(input)) {
|
||||
@ -267,12 +262,10 @@ namespace Elwig.Windows {
|
||||
}
|
||||
|
||||
protected void SetDefaultValue(Control input) {
|
||||
if (input is UnitTextBox utbx) input = utbx.TextBox;
|
||||
SetDefaultValue(input, ControlUtils.GetInputHashCode(input));
|
||||
}
|
||||
|
||||
protected void UnsetDefaultValue(Control input) {
|
||||
if (input is UnitTextBox utbx) input = utbx.TextBox;
|
||||
DefaultValues.Remove(input);
|
||||
if (!InputHasChanged(input)) {
|
||||
ControlUtils.ClearInputState(input);
|
||||
@ -296,12 +289,10 @@ namespace Elwig.Windows {
|
||||
protected bool IsValid => Valid.All(kv => kv.Value);
|
||||
|
||||
protected bool GetInputValid(Control input) {
|
||||
if (input is UnitTextBox utbx) input = utbx.TextBox;
|
||||
return Valid[input];
|
||||
}
|
||||
|
||||
protected bool InputHasChanged(Control input) {
|
||||
if (input is UnitTextBox utbx) input = utbx.TextBox;
|
||||
if (!OriginalValues.TryGetValue(input, out int? original)) {
|
||||
return false;
|
||||
} else {
|
||||
@ -311,7 +302,6 @@ namespace Elwig.Windows {
|
||||
}
|
||||
|
||||
protected bool InputIsNotDefault(Control input) {
|
||||
if (input is UnitTextBox utbx) input = utbx.TextBox;
|
||||
if (!DefaultValues.TryGetValue(input, out int? defaultValue)) {
|
||||
return false;
|
||||
} else {
|
||||
@ -436,7 +426,7 @@ namespace Elwig.Windows {
|
||||
|
||||
protected void TextBox_TextChanged(object sender, RoutedEventArgs? evt) {
|
||||
var input = (Control)sender;
|
||||
var tb = input as TextBox ?? (input as UnitTextBox)?.TextBox;
|
||||
var tb = input as TextBox;
|
||||
if (SenderIsRequired(input) && tb?.Text.Length == 0) {
|
||||
ValidateInput(input, false);
|
||||
ControlUtils.SetInputInvalid(input);
|
||||
@ -482,12 +472,12 @@ namespace Elwig.Windows {
|
||||
|
||||
protected void IntegerInput_TextChanged(object sender, TextChangedEventArgs evt) {
|
||||
// FIXME
|
||||
InputTextChanged((sender as UnitTextBox)?.TextBox ?? (TextBox)sender, Validator.CheckInteger);
|
||||
InputTextChanged((TextBox)sender, Validator.CheckInteger);
|
||||
}
|
||||
|
||||
protected void DecimalInput_TextChanged(object sender, TextChangedEventArgs evt) {
|
||||
// FIXME
|
||||
InputTextChanged((sender as UnitTextBox)?.TextBox ?? (TextBox)sender, Validator.CheckDecimal);
|
||||
InputTextChanged((TextBox)sender, Validator.CheckDecimal);
|
||||
}
|
||||
|
||||
protected void PartialDateInput_TextChanged(object sender, TextChangedEventArgs evt) {
|
||||
|
Reference in New Issue
Block a user