mirror of
https://github.com/Hofknecht/SystemTrayMenu.git
synced 2024-09-30 17:16:52 +13:00
Fix menu activation when opened from notify icon
This commit is contained in:
parent
55fccd17d5
commit
6ffddc7e02
5 changed files with 16 additions and 38 deletions
|
@ -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)
|
||||
{
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
// Copyright (c) PlaceholderCompany. All rights reserved.
|
||||
// </copyright>
|
||||
//
|
||||
// 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,
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in a new issue