diff --git a/Business/App.xaml.cs b/Business/App.xaml.cs index a870986..b5ddcba 100644 --- a/Business/App.xaml.cs +++ b/Business/App.xaml.cs @@ -27,7 +27,7 @@ namespace SystemTrayMenu AppRestart.BeforeRestarting += Dispose; menus.LoadStarted += menuNotifyIcon.LoadingStart; menus.LoadStopped += menuNotifyIcon.LoadingStop; - menuNotifyIcon.Click += () => menus.SwitchOpenClose(true); + menuNotifyIcon.Click += () => menus.SwitchOpenClose(true, false); if (Settings.Default.ShowInTaskbar) { diff --git a/Business/Menus.cs b/Business/Menus.cs index 07ce654..c9958ad 100644 --- a/Business/Menus.cs +++ b/Business/Menus.cs @@ -52,7 +52,7 @@ namespace SystemTrayMenu.Business { keyboardInput = new(menus); keyboardInput.RegisterHotKey(); - keyboardInput.HotKeyPressed += () => SwitchOpenClose(false); + keyboardInput.HotKeyPressed += () => SwitchOpenClose(false, false); keyboardInput.ClosePressed += MenusFadeOut; keyboardInput.RowDeselected += waitToOpenMenu.RowDeselected; keyboardInput.EnterPressed += waitToOpenMenu.EnterOpensInstantly; @@ -247,7 +247,7 @@ namespace SystemTrayMenu.Business dispatchter.Invoke(() => SwitchOpenClose(false, true)); } - internal void SwitchOpenClose(bool byClick, bool allowPreloading = false) + internal void SwitchOpenClose(bool byClick, bool allowPreloading) { // Ignore open close events during main preload #248 if (IconReader.IsPreloading && !allowPreloading) @@ -447,32 +447,7 @@ namespace SystemTrayMenu.Business private bool IsActive() { - bool IsShellContextMenuOpen() - { - foreach (Menu? menu in menus.Where(m => m != null)) - { - ListView? dgv = menu?.GetDataGridView(); - if (dgv != null) - { - foreach (ListViewItemData item in dgv.Items) - { - if (item.data != null) - { - return true; - } - } - } - } - - return false; - } - - foreach (Menu? menu in menus.Where(m => m != null && m.IsActive)) - { - return true; - } - - return (App.TaskbarLogo != null && App.TaskbarLogo.IsActive) || IsShellContextMenuOpen(); + return menus.Where(m => m != null && m.IsActive).FirstOrDefault() != null || (App.TaskbarLogo?.IsActive ?? false); } private Menu Create(MenuData menuData, string path) @@ -605,6 +580,7 @@ namespace SystemTrayMenu.Business if (menu.Level == 0) { menu.ResetSearchText(); + menu.Activate(); } } diff --git a/Business/WaitToLoadMenu.cs b/Business/WaitToLoadMenu.cs index e59c90d..f0aa1ed 100644 --- a/Business/WaitToLoadMenu.cs +++ b/Business/WaitToLoadMenu.cs @@ -20,16 +20,16 @@ namespace SystemTrayMenu.Handler private readonly DispatcherTimer timerStartLoad = new(); private ListView? dgv; private ListViewItemData? dgvItemData; - private ListView? dgvTmp; #if TODO // Misc MouseEvents + private ListView? dgvTmp; private int rowIndexTmp; #endif private bool alreadyOpened; #if TODO // Misc MouseEvents private int mouseMoveEvents; -#endif private DateTime dateTimeLastMouseMoveEvent = DateTime.Now; +#endif private bool checkForMouseActive = true; internal WaitToLoadMenu() @@ -64,13 +64,13 @@ namespace SystemTrayMenu.Handler SetData(dgv, itemData); timerStartLoad.Start(); } +#if TODO // Misc MouseEvents else { dgvTmp = dgv; -#if TODO // Misc MouseEvents rowIndexTmp = dgv.IndexOfSenderItem(item); -#endif } +#endif } internal void RowSelected(ListView dgv, ListViewItemData itemData) @@ -192,7 +192,9 @@ namespace SystemTrayMenu.Handler } alreadyOpened = false; +#if TODO // Misc MouseEvents dgvTmp = null; +#endif this.dgv = dgv; dgvItemData = itemData; diff --git a/Utilities/IconToImageSourceConverter.cs b/Utilities/IconToImageSourceConverter.cs index bceefb1..ffcb125 100644 --- a/Utilities/IconToImageSourceConverter.cs +++ b/Utilities/IconToImageSourceConverter.cs @@ -2,7 +2,7 @@ // Copyright (c) PlaceholderCompany. All rights reserved. // // -// Copyright (c) 2022-2022 Peter Kirmeier +// Copyright (c) 2022-2023 Peter Kirmeier namespace SystemTrayMenu.Utilities { @@ -24,7 +24,7 @@ namespace SystemTrayMenu.Utilities if (value != null) { // Invalid Icon happens usually only during design time with dummy default data - Icon icon = value is Icon ? (Icon)value : SystemIcons.Error; + Icon icon = value is Icon validIcon ? validIcon : SystemIcons.Error; return Imaging.CreateBitmapSourceFromHIcon( icon.Handle, Int32Rect.Empty, diff --git a/Utilities/WPFExtensions.cs b/Utilities/WPFExtensions.cs index e588574..94ec21e 100644 --- a/Utilities/WPFExtensions.cs +++ b/Utilities/WPFExtensions.cs @@ -34,7 +34,7 @@ namespace SystemTrayMenu.Utilities { var parent = VisualTreeHelper.GetParent(listView); - while (!(parent is Window)) + while (parent is not Window) { parent = VisualTreeHelper.GetParent(parent); } @@ -72,11 +72,11 @@ namespace SystemTrayMenu.Utilities DependencyObject child = VisualTreeHelper.GetChild(depObj, i); if (child != null) { - if (child is T) + if (child is T validChild) { if (index-- == 0) { - return (T)child; + return validChild; } continue;