Small fixes
This commit is contained in:
		| @@ -14,7 +14,7 @@ namespace WGneu.Print { | ||||
|         private static readonly string CHROMIUM = @"C:\Program Files (x86)\Microsoft\Edge\Application\msedge.exe"; | ||||
|         private static IBrowser? Browser = null; | ||||
|  | ||||
|         public static async void Init() { | ||||
|         public static async Task Init() { | ||||
|             Browser = await Puppeteer.LaunchAsync(new LaunchOptions { | ||||
|                 Headless = true, | ||||
|                 ExecutablePath = CHROMIUM, | ||||
| @@ -23,7 +23,7 @@ namespace WGneu.Print { | ||||
|  | ||||
|         public static async Task Convert(string path_html, string path_pdf) { | ||||
|             if (Browser == null) | ||||
|                 Init(); | ||||
|                 await Init(); | ||||
|  | ||||
|             using var page = await Browser?.NewPageAsync(); | ||||
|             await page.GoToAsync("file://" + path_html); | ||||
|   | ||||
| @@ -35,6 +35,10 @@ namespace WGneu { | ||||
|             } | ||||
|         } | ||||
|  | ||||
|         public static IEnumerable<T> FindVisualChilds<T>(DependencyObject depObj, IEnumerable<DependencyObject> exempt) where T : DependencyObject { | ||||
|             return FindVisualChilds<T>(depObj).Where(c => !exempt.Contains(c)); | ||||
|         } | ||||
|  | ||||
|         public static int Modulo(string a, int b) { | ||||
|             if (!a.All(char.IsDigit)) | ||||
|                 throw new ArgumentException("First argument has to be a decimal string"); | ||||
|   | ||||
| @@ -24,17 +24,23 @@ namespace WGneu.Windows { | ||||
|         private bool IsEditing = false; | ||||
|         private bool IsCreating = false; | ||||
|         private List<string> TextFilter = new(); | ||||
|         private readonly Control[] ExemptInputs; | ||||
|         private readonly Dictionary<Control, bool> Valid = new(); | ||||
|         private readonly Dictionary<Control, object?> OriginalValues = new(); | ||||
|         private static readonly RoutedCommand CtrlF = new(); | ||||
|         private readonly RoutedCommand CtrlF = new(); | ||||
|         private readonly WgContext Context = new(); | ||||
|  | ||||
|         public MemberListWindow() { | ||||
|             InitializeComponent(); | ||||
|             CtrlF.InputGestures.Add(new KeyGesture(Key.F, ModifierKeys.Control)); | ||||
|             CommandBindings.Add(new CommandBinding(CtrlF, FocusSearchInput)); | ||||
|             foreach (var tb in Utils.FindVisualChilds<TextBox>(this)) | ||||
|                 if (tb.Name != "SearchInput") Valid[tb] = true; | ||||
|             ExemptInputs = new Control[] { | ||||
|                 SearchInput, ActiveMemberInput, MemberList, | ||||
|                 NewMemberButton, EditMemberButton, DeleteMemberButton, | ||||
|                 ResetButton, SaveButton, CancelButton | ||||
|             }; | ||||
|             foreach (var tb in Utils.FindVisualChilds<TextBox>(this, ExemptInputs)) | ||||
|                 Valid[tb] = true; | ||||
|         } | ||||
|  | ||||
|         private void Window_Loaded(object sender, RoutedEventArgs e) { | ||||
| @@ -86,13 +92,13 @@ namespace WGneu.Windows { | ||||
|         } | ||||
|  | ||||
|         private void ClearInputStates() { | ||||
|             foreach (var tb in Utils.FindVisualChilds<TextBox>(this)) | ||||
|                 if (tb.Name != "SearchInput") Utils.ClearInputState(tb); | ||||
|             foreach (var cb in Utils.FindVisualChilds<ComboBox>(this)) | ||||
|             foreach (var tb in Utils.FindVisualChilds<TextBox>(this, ExemptInputs)) | ||||
|                 Utils.ClearInputState(tb); | ||||
|             foreach (var cb in Utils.FindVisualChilds<ComboBox>(this, ExemptInputs)) | ||||
|                 Utils.ClearInputState(cb); | ||||
|             foreach (var cb in Utils.FindVisualChilds<CheckBox>(this)) | ||||
|                 if (cb.Name != "ActiveMemberInput") Utils.ClearInputState(cb); | ||||
|             foreach (var rb in Utils.FindVisualChilds<RadioButton>(this)) | ||||
|             foreach (var cb in Utils.FindVisualChilds<CheckBox>(this, ExemptInputs)) | ||||
|                 Utils.ClearInputState(cb); | ||||
|             foreach (var rb in Utils.FindVisualChilds<RadioButton>(this, ExemptInputs)) | ||||
|                 Utils.ClearInputState(rb); | ||||
|         } | ||||
|  | ||||
| @@ -305,24 +311,24 @@ namespace WGneu.Windows { | ||||
|         } | ||||
|  | ||||
|         private void LockInputs() { | ||||
|             foreach (var tb in Utils.FindVisualChilds<TextBox>(this)) | ||||
|                 if (tb.Name != "SearchInput") tb.IsReadOnly = true; | ||||
|             foreach (var cb in Utils.FindVisualChilds<ComboBox>(this)) | ||||
|             foreach (var tb in Utils.FindVisualChilds<TextBox>(this, ExemptInputs)) | ||||
|                 tb.IsReadOnly = true; | ||||
|             foreach (var cb in Utils.FindVisualChilds<ComboBox>(this, ExemptInputs)) | ||||
|                 cb.IsEnabled = false; | ||||
|             foreach (var cb in Utils.FindVisualChilds<CheckBox>(this)) | ||||
|                 if (cb.Name != "ActiveMemberInput") cb.IsEnabled = false; | ||||
|             foreach (var rb in Utils.FindVisualChilds<RadioButton>(this)) | ||||
|             foreach (var cb in Utils.FindVisualChilds<CheckBox>(this, ExemptInputs)) | ||||
|                 cb.IsEnabled = false; | ||||
|             foreach (var rb in Utils.FindVisualChilds<RadioButton>(this, ExemptInputs)) | ||||
|                 rb.IsEnabled = false; | ||||
|         } | ||||
|  | ||||
|         private void UnlockInputs() { | ||||
|             foreach (var tb in Utils.FindVisualChilds<TextBox>(this)) | ||||
|                 if (tb.Name != "SearchInput") tb.IsReadOnly = false; | ||||
|             foreach (var cb in Utils.FindVisualChilds<ComboBox>(this)) | ||||
|             foreach (var tb in Utils.FindVisualChilds<TextBox>(this, ExemptInputs)) | ||||
|                 tb.IsReadOnly = false; | ||||
|             foreach (var cb in Utils.FindVisualChilds<ComboBox>(this, ExemptInputs)) | ||||
|                 cb.IsEnabled = true; | ||||
|             foreach (var cb in Utils.FindVisualChilds<CheckBox>(this)) | ||||
|                 if (cb.Name != "ActiveMemberInput") cb.IsEnabled = true; | ||||
|             foreach (var rb in Utils.FindVisualChilds<RadioButton>(this)) | ||||
|             foreach (var cb in Utils.FindVisualChilds<CheckBox>(this, ExemptInputs)) | ||||
|                 cb.IsEnabled = true; | ||||
|             foreach (var rb in Utils.FindVisualChilds<RadioButton>(this, ExemptInputs)) | ||||
|                 rb.IsEnabled = true; | ||||
|         } | ||||
|  | ||||
| @@ -387,31 +393,31 @@ namespace WGneu.Windows { | ||||
|                 case "email": ContactEmailInput.IsChecked = true; break; | ||||
|             } | ||||
|  | ||||
|             foreach (var tb in Utils.FindVisualChilds<TextBox>(this)) | ||||
|                 if (tb.Name != "SearchInput") OriginalValues[tb] = tb.Text; | ||||
|             foreach (var cb in Utils.FindVisualChilds<ComboBox>(this)) | ||||
|             foreach (var tb in Utils.FindVisualChilds<TextBox>(this, ExemptInputs)) | ||||
|                 OriginalValues[tb] = tb.Text; | ||||
|             foreach (var cb in Utils.FindVisualChilds<ComboBox>(this, ExemptInputs)) | ||||
|                 OriginalValues[cb] = cb.SelectedItem; | ||||
|             foreach (var cb in Utils.FindVisualChilds<CheckBox>(this)) | ||||
|                 if (cb.Name != "ActiveMemberInput") OriginalValues[cb] = (cb.IsChecked ?? false) ? bool.TrueString : null; | ||||
|             foreach (var rb in Utils.FindVisualChilds<RadioButton>(this)) | ||||
|             foreach (var cb in Utils.FindVisualChilds<CheckBox>(this, ExemptInputs)) | ||||
|                 OriginalValues[cb] = (cb.IsChecked ?? false) ? bool.TrueString : null; | ||||
|             foreach (var rb in Utils.FindVisualChilds<RadioButton>(this, ExemptInputs)) | ||||
|                 OriginalValues[rb] = (rb.IsChecked ?? false) ? bool.TrueString : null; | ||||
|         } | ||||
|  | ||||
|         private void ClearInputs() { | ||||
|             foreach (var tb in Utils.FindVisualChilds<TextBox>(this)) | ||||
|                 if (tb.Name != "SearchInput") tb.Text = ""; | ||||
|             foreach (var cb in Utils.FindVisualChilds<ComboBox>(this)) | ||||
|                 cb.SelectedItem = null; | ||||
|             foreach (var cb in Utils.FindVisualChilds<CheckBox>(this)) | ||||
|                 if (cb.Name != "ActiveMemberInput") cb.IsChecked = false; | ||||
|             foreach (var rb in Utils.FindVisualChilds<RadioButton>(this)) | ||||
|                 rb.IsChecked = false; | ||||
|             OriginalValues.Clear(); | ||||
|             foreach (var tb in Utils.FindVisualChilds<TextBox>(this, ExemptInputs)) | ||||
|                 tb.Text = ""; | ||||
|             foreach (var cb in Utils.FindVisualChilds<ComboBox>(this, ExemptInputs)) | ||||
|                 cb.SelectedItem = null; | ||||
|             foreach (var cb in Utils.FindVisualChilds<CheckBox>(this, ExemptInputs)) | ||||
|                 cb.IsChecked = false; | ||||
|             foreach (var rb in Utils.FindVisualChilds<RadioButton>(this, ExemptInputs)) | ||||
|                 rb.IsChecked = false; | ||||
|         } | ||||
|  | ||||
|         private bool IsValid() { | ||||
|             return Valid.All(kv => kv.Value) && | ||||
|                 Utils.FindVisualChilds<ComboBox>(this).All(cb => cb.ItemsSource == null || cb.SelectedItem != null); | ||||
|                 Utils.FindVisualChilds<ComboBox>(this, ExemptInputs).All(cb => cb.ItemsSource == null || cb.SelectedItem != null); | ||||
|         } | ||||
|  | ||||
|         private void UpdateButtons() { | ||||
| @@ -439,10 +445,10 @@ namespace WGneu.Windows { | ||||
|  | ||||
|         private bool HasChanged() { | ||||
|             return !IsValid() || | ||||
|                 Utils.FindVisualChilds<TextBox>(this).Any(InputHasChanged) || | ||||
|                 Utils.FindVisualChilds<ComboBox>(this).Any(InputHasChanged) || | ||||
|                 Utils.FindVisualChilds<CheckBox>(this).Any(InputHasChanged) || | ||||
|                 Utils.FindVisualChilds<RadioButton>(this).Any(InputHasChanged); | ||||
|                 Utils.FindVisualChilds<TextBox>(this, ExemptInputs).Any(InputHasChanged) || | ||||
|                 Utils.FindVisualChilds<ComboBox>(this, ExemptInputs).Any(InputHasChanged) || | ||||
|                 Utils.FindVisualChilds<CheckBox>(this, ExemptInputs).Any(InputHasChanged) || | ||||
|                 Utils.FindVisualChilds<RadioButton>(this, ExemptInputs).Any(InputHasChanged); | ||||
|         } | ||||
|  | ||||
|         private void UpdatePlz(TextBox plzInput, ComboBox ortInput) { | ||||
|   | ||||
		Reference in New Issue
	
	Block a user