diff --git a/WGneu/Print/Pdf.cs b/WGneu/Print/Pdf.cs index ef5caae..a942662 100644 --- a/WGneu/Print/Pdf.cs +++ b/WGneu/Print/Pdf.cs @@ -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); diff --git a/WGneu/Utils.cs b/WGneu/Utils.cs index b92fb82..b7fc5bd 100644 --- a/WGneu/Utils.cs +++ b/WGneu/Utils.cs @@ -35,6 +35,10 @@ namespace WGneu { } } + public static IEnumerable FindVisualChilds(DependencyObject depObj, IEnumerable exempt) where T : DependencyObject { + return FindVisualChilds(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"); diff --git a/WGneu/Windows/MemberListWindow.xaml.cs b/WGneu/Windows/MemberListWindow.xaml.cs index 3fb6dd5..8891672 100644 --- a/WGneu/Windows/MemberListWindow.xaml.cs +++ b/WGneu/Windows/MemberListWindow.xaml.cs @@ -24,17 +24,23 @@ namespace WGneu.Windows { private bool IsEditing = false; private bool IsCreating = false; private List TextFilter = new(); + private readonly Control[] ExemptInputs; private readonly Dictionary Valid = new(); private readonly Dictionary 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(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(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(this)) - if (tb.Name != "SearchInput") Utils.ClearInputState(tb); - foreach (var cb in Utils.FindVisualChilds(this)) + foreach (var tb in Utils.FindVisualChilds(this, ExemptInputs)) + Utils.ClearInputState(tb); + foreach (var cb in Utils.FindVisualChilds(this, ExemptInputs)) Utils.ClearInputState(cb); - foreach (var cb in Utils.FindVisualChilds(this)) - if (cb.Name != "ActiveMemberInput") Utils.ClearInputState(cb); - foreach (var rb in Utils.FindVisualChilds(this)) + foreach (var cb in Utils.FindVisualChilds(this, ExemptInputs)) + Utils.ClearInputState(cb); + foreach (var rb in Utils.FindVisualChilds(this, ExemptInputs)) Utils.ClearInputState(rb); } @@ -305,24 +311,24 @@ namespace WGneu.Windows { } private void LockInputs() { - foreach (var tb in Utils.FindVisualChilds(this)) - if (tb.Name != "SearchInput") tb.IsReadOnly = true; - foreach (var cb in Utils.FindVisualChilds(this)) + foreach (var tb in Utils.FindVisualChilds(this, ExemptInputs)) + tb.IsReadOnly = true; + foreach (var cb in Utils.FindVisualChilds(this, ExemptInputs)) cb.IsEnabled = false; - foreach (var cb in Utils.FindVisualChilds(this)) - if (cb.Name != "ActiveMemberInput") cb.IsEnabled = false; - foreach (var rb in Utils.FindVisualChilds(this)) + foreach (var cb in Utils.FindVisualChilds(this, ExemptInputs)) + cb.IsEnabled = false; + foreach (var rb in Utils.FindVisualChilds(this, ExemptInputs)) rb.IsEnabled = false; } private void UnlockInputs() { - foreach (var tb in Utils.FindVisualChilds(this)) - if (tb.Name != "SearchInput") tb.IsReadOnly = false; - foreach (var cb in Utils.FindVisualChilds(this)) + foreach (var tb in Utils.FindVisualChilds(this, ExemptInputs)) + tb.IsReadOnly = false; + foreach (var cb in Utils.FindVisualChilds(this, ExemptInputs)) cb.IsEnabled = true; - foreach (var cb in Utils.FindVisualChilds(this)) - if (cb.Name != "ActiveMemberInput") cb.IsEnabled = true; - foreach (var rb in Utils.FindVisualChilds(this)) + foreach (var cb in Utils.FindVisualChilds(this, ExemptInputs)) + cb.IsEnabled = true; + foreach (var rb in Utils.FindVisualChilds(this, ExemptInputs)) rb.IsEnabled = true; } @@ -387,31 +393,31 @@ namespace WGneu.Windows { case "email": ContactEmailInput.IsChecked = true; break; } - foreach (var tb in Utils.FindVisualChilds(this)) - if (tb.Name != "SearchInput") OriginalValues[tb] = tb.Text; - foreach (var cb in Utils.FindVisualChilds(this)) + foreach (var tb in Utils.FindVisualChilds(this, ExemptInputs)) + OriginalValues[tb] = tb.Text; + foreach (var cb in Utils.FindVisualChilds(this, ExemptInputs)) OriginalValues[cb] = cb.SelectedItem; - foreach (var cb in Utils.FindVisualChilds(this)) - if (cb.Name != "ActiveMemberInput") OriginalValues[cb] = (cb.IsChecked ?? false) ? bool.TrueString : null; - foreach (var rb in Utils.FindVisualChilds(this)) + foreach (var cb in Utils.FindVisualChilds(this, ExemptInputs)) + OriginalValues[cb] = (cb.IsChecked ?? false) ? bool.TrueString : null; + foreach (var rb in Utils.FindVisualChilds(this, ExemptInputs)) OriginalValues[rb] = (rb.IsChecked ?? false) ? bool.TrueString : null; } private void ClearInputs() { - foreach (var tb in Utils.FindVisualChilds(this)) - if (tb.Name != "SearchInput") tb.Text = ""; - foreach (var cb in Utils.FindVisualChilds(this)) - cb.SelectedItem = null; - foreach (var cb in Utils.FindVisualChilds(this)) - if (cb.Name != "ActiveMemberInput") cb.IsChecked = false; - foreach (var rb in Utils.FindVisualChilds(this)) - rb.IsChecked = false; OriginalValues.Clear(); + foreach (var tb in Utils.FindVisualChilds(this, ExemptInputs)) + tb.Text = ""; + foreach (var cb in Utils.FindVisualChilds(this, ExemptInputs)) + cb.SelectedItem = null; + foreach (var cb in Utils.FindVisualChilds(this, ExemptInputs)) + cb.IsChecked = false; + foreach (var rb in Utils.FindVisualChilds(this, ExemptInputs)) + rb.IsChecked = false; } private bool IsValid() { return Valid.All(kv => kv.Value) && - Utils.FindVisualChilds(this).All(cb => cb.ItemsSource == null || cb.SelectedItem != null); + Utils.FindVisualChilds(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(this).Any(InputHasChanged) || - Utils.FindVisualChilds(this).Any(InputHasChanged) || - Utils.FindVisualChilds(this).Any(InputHasChanged) || - Utils.FindVisualChilds(this).Any(InputHasChanged); + Utils.FindVisualChilds(this, ExemptInputs).Any(InputHasChanged) || + Utils.FindVisualChilds(this, ExemptInputs).Any(InputHasChanged) || + Utils.FindVisualChilds(this, ExemptInputs).Any(InputHasChanged) || + Utils.FindVisualChilds(this, ExemptInputs).Any(InputHasChanged); } private void UpdatePlz(TextBox plzInput, ComboBox ortInput) {