Move input states from Validator to Utils
This commit is contained in:
@ -5,9 +5,22 @@ using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Media;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
|
||||
namespace WGneu {
|
||||
class Utils {
|
||||
public static void SetInputChanged(Control input) {
|
||||
input.BorderBrush = Brushes.Orange;
|
||||
}
|
||||
|
||||
public static void SetInputInvalid(Control input) {
|
||||
input.BorderBrush = Brushes.Red;
|
||||
}
|
||||
|
||||
public static void ClearInputState(Control input) {
|
||||
input.ClearValue(Control.BorderBrushProperty);
|
||||
}
|
||||
|
||||
public static IEnumerable<T> FindVisualChilds<T>(DependencyObject depObj) where T : DependencyObject {
|
||||
if (depObj == null)
|
||||
yield return (T)Enumerable.Empty<T>();
|
||||
|
@ -32,18 +32,6 @@ namespace WGneu {
|
||||
{ "423", Array.Empty<string[]>() },
|
||||
};
|
||||
|
||||
public static void SetInputChanged(Control input) {
|
||||
input.BorderBrush = System.Windows.Media.Brushes.Orange;
|
||||
}
|
||||
|
||||
public static void SetInputInvalid(Control input) {
|
||||
input.BorderBrush = System.Windows.Media.Brushes.Red;
|
||||
}
|
||||
|
||||
public static void ClearInputStatus(Control input) {
|
||||
input.ClearValue(Control.BorderBrushProperty);
|
||||
}
|
||||
|
||||
public static ValidationResult CheckNumericInput(TextBox input, bool optional) {
|
||||
return CheckNumericInput(input, optional, -1);
|
||||
}
|
||||
|
@ -82,13 +82,13 @@ namespace WGneu.Windows {
|
||||
|
||||
private void ClearInputStates() {
|
||||
foreach (var tb in Utils.FindVisualChilds<TextBox>(this))
|
||||
if (tb.Name != "SearchInput") Validator.ClearInputStatus(tb);
|
||||
if (tb.Name != "SearchInput") Utils.ClearInputState(tb);
|
||||
foreach (var cb in Utils.FindVisualChilds<ComboBox>(this))
|
||||
Validator.ClearInputStatus(cb);
|
||||
Utils.ClearInputState(cb);
|
||||
foreach (var cb in Utils.FindVisualChilds<CheckBox>(this))
|
||||
Validator.ClearInputStatus(cb);
|
||||
Utils.ClearInputState(cb);
|
||||
foreach (var rb in Utils.FindVisualChilds<RadioButton>(this))
|
||||
Validator.ClearInputStatus(rb);
|
||||
Utils.ClearInputState(rb);
|
||||
}
|
||||
|
||||
private void RefreshInputs() {
|
||||
@ -439,12 +439,12 @@ namespace WGneu.Windows {
|
||||
Valid[input] = res.IsValid;
|
||||
if (res.IsValid) {
|
||||
if (InputHasChanged(input)) {
|
||||
Validator.SetInputChanged(input);
|
||||
Utils.SetInputChanged(input);
|
||||
} else {
|
||||
Validator.ClearInputStatus(input);
|
||||
Utils.ClearInputState(input);
|
||||
}
|
||||
} else {
|
||||
Validator.SetInputInvalid(input);
|
||||
Utils.SetInputInvalid(input);
|
||||
}
|
||||
UpdateButtons();
|
||||
}
|
||||
@ -458,9 +458,9 @@ namespace WGneu.Windows {
|
||||
private void CheckBox_Changed(object sender, RoutedEventArgs e) {
|
||||
var input = (CheckBox)sender;
|
||||
if (InputHasChanged(input)) {
|
||||
Validator.SetInputChanged(input);
|
||||
Utils.SetInputChanged(input);
|
||||
} else {
|
||||
Validator.ClearInputStatus(input);
|
||||
Utils.ClearInputState(input);
|
||||
}
|
||||
UpdateButtons();
|
||||
}
|
||||
@ -468,9 +468,9 @@ namespace WGneu.Windows {
|
||||
private void RadioButton_Changed(object sender, RoutedEventArgs e) {
|
||||
var input = (RadioButton)sender;
|
||||
if (InputHasChanged(input)) {
|
||||
Validator.SetInputChanged(input);
|
||||
Utils.SetInputChanged(input);
|
||||
} else {
|
||||
Validator.ClearInputStatus(input);
|
||||
Utils.ClearInputState(input);
|
||||
}
|
||||
UpdateButtons();
|
||||
}
|
||||
@ -478,9 +478,9 @@ namespace WGneu.Windows {
|
||||
private void TextBox_TextChanged(object sender, RoutedEventArgs e) {
|
||||
var input = (TextBox)sender;
|
||||
if (InputHasChanged(input)) {
|
||||
Validator.SetInputChanged(input);
|
||||
Utils.SetInputChanged(input);
|
||||
} else {
|
||||
Validator.ClearInputStatus(input);
|
||||
Utils.ClearInputState(input);
|
||||
}
|
||||
UpdateButtons();
|
||||
}
|
||||
@ -489,9 +489,9 @@ namespace WGneu.Windows {
|
||||
var input = (ComboBox)sender;
|
||||
if (InputHasChanged(input)) {
|
||||
// TODO not working
|
||||
Validator.SetInputChanged(input);
|
||||
Utils.SetInputChanged(input);
|
||||
} else {
|
||||
Validator.ClearInputStatus(input);
|
||||
Utils.ClearInputState(input);
|
||||
}
|
||||
UpdateButtons();
|
||||
}
|
||||
|
Reference in New Issue
Block a user