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