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