mirror of
https://github.com/Hofknecht/SystemTrayMenu.git
synced 2024-10-03 10:36:30 +13:00
Adjusted naming and variables for menu selection with keys
Remove obsolete mouse events (non active code)
This commit is contained in:
parent
189e45099c
commit
97185b1989
4 changed files with 51 additions and 133 deletions
|
@ -251,23 +251,20 @@ namespace SystemTrayMenu.Handler
|
||||||
{
|
{
|
||||||
Menu? menuFromSelected;
|
Menu? menuFromSelected;
|
||||||
Menu? menuBefore;
|
Menu? menuBefore;
|
||||||
ListView? dgvBefore;
|
|
||||||
ListViewItemData? rowBefore = focussedRow;
|
ListViewItemData? rowBefore = focussedRow;
|
||||||
bool toClear = false;
|
bool doClearOldSelection = false;
|
||||||
bool isSelected = focussedRow?.data.IsSelected ?? false;
|
bool wasSelected = focussedRow?.data.IsSelected ?? false;
|
||||||
|
|
||||||
if (isSelected)
|
if (wasSelected)
|
||||||
{
|
{
|
||||||
menuFromSelected = focussedRow?.data.SubMenu;
|
menuFromSelected = focussedRow?.data.SubMenu;
|
||||||
menuBefore = focussedMenu;
|
menuBefore = focussedMenu;
|
||||||
dgvBefore = menuBefore?.GetDataGridView();
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
ResetSelectedByKey();
|
ResetSelectedByKey();
|
||||||
menuFromSelected = null;
|
menuFromSelected = null;
|
||||||
menuBefore = null;
|
menuBefore = null;
|
||||||
dgvBefore = null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (key)
|
switch (key)
|
||||||
|
@ -294,50 +291,50 @@ namespace SystemTrayMenu.Handler
|
||||||
break;
|
break;
|
||||||
case Key.Up:
|
case Key.Up:
|
||||||
if ((modifiers == ModifierKeys.None) &&
|
if ((modifiers == ModifierKeys.None) &&
|
||||||
dgvBefore != null &&
|
menuBefore != null &&
|
||||||
(TrySelectPrevious(dgvBefore, dgvBefore.Items.IndexOf(rowBefore)) ||
|
(TrySelectPrevious(menuBefore, menuBefore.GetDataGridView().Items.IndexOf(rowBefore)) ||
|
||||||
TrySelectPrevious(dgvBefore, dgvBefore.Items.Count - 1)))
|
TrySelectPrevious(menuBefore, menuBefore.GetDataGridView().Items.Count - 1)))
|
||||||
{
|
{
|
||||||
RaiseRowSelectionChanged(menuBefore, rowBefore);
|
RaiseRowSelectionChanged(menuBefore, rowBefore);
|
||||||
toClear = true;
|
doClearOldSelection = wasSelected;
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
case Key.Down:
|
case Key.Down:
|
||||||
if ((modifiers == ModifierKeys.None) &&
|
if ((modifiers == ModifierKeys.None) &&
|
||||||
dgvBefore != null &&
|
menuBefore != null &&
|
||||||
(TrySelectNext(dgvBefore, dgvBefore.Items.IndexOf(rowBefore)) ||
|
(TrySelectNext(menuBefore, menuBefore.GetDataGridView().Items.IndexOf(rowBefore)) ||
|
||||||
TrySelectNext(dgvBefore, 0)))
|
TrySelectNext(menuBefore, 0)))
|
||||||
{
|
{
|
||||||
RaiseRowSelectionChanged(menuBefore, rowBefore);
|
RaiseRowSelectionChanged(menuBefore, rowBefore);
|
||||||
toClear = true;
|
doClearOldSelection = wasSelected;
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
case Key.Home:
|
case Key.Home:
|
||||||
if ((modifiers == ModifierKeys.None) &&
|
if ((modifiers == ModifierKeys.None) &&
|
||||||
dgvBefore != null &&
|
menuBefore != null &&
|
||||||
TrySelectNext(dgvBefore, 0))
|
TrySelectNext(menuBefore, 0))
|
||||||
{
|
{
|
||||||
RaiseRowSelectionChanged(menuBefore, rowBefore);
|
RaiseRowSelectionChanged(menuBefore, rowBefore);
|
||||||
toClear = true;
|
doClearOldSelection = wasSelected;
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
case Key.End:
|
case Key.End:
|
||||||
if ((modifiers == ModifierKeys.None) &&
|
if ((modifiers == ModifierKeys.None) &&
|
||||||
dgvBefore != null &&
|
menuBefore != null &&
|
||||||
TrySelectPrevious(dgvBefore, dgvBefore.Items.Count - 1))
|
TrySelectPrevious(menuBefore, menuBefore.GetDataGridView().Items.Count - 1))
|
||||||
{
|
{
|
||||||
RaiseRowSelectionChanged(menuBefore, rowBefore);
|
RaiseRowSelectionChanged(menuBefore, rowBefore);
|
||||||
toClear = true;
|
doClearOldSelection = wasSelected;
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
case Key.Left:
|
case Key.Left:
|
||||||
case Key.Right:
|
case Key.Right:
|
||||||
if (modifiers == ModifierKeys.None &&
|
if (modifiers == ModifierKeys.None &&
|
||||||
dgvBefore != null &&
|
menuBefore != null &&
|
||||||
focussedMenu != null)
|
focussedMenu != null)
|
||||||
{
|
{
|
||||||
// True, when next is left and key is left = true OR next is right (=not left) and key is right (not left)
|
// True, when next is left and key is left = true OR next is right (=not left) and key is right (not left)
|
||||||
|
@ -350,22 +347,18 @@ namespace SystemTrayMenu.Handler
|
||||||
|
|
||||||
if (nextMenuInKeyDirection || prevMenuAgainstKeyDirection)
|
if (nextMenuInKeyDirection || prevMenuAgainstKeyDirection)
|
||||||
{
|
{
|
||||||
// Next is in key direction or prev is opposite of key direction ==> TrySelect sub/next menu
|
// Next is in key direction or prev is opposite of key direction ==> Select sub/next menu
|
||||||
if (isSelected)
|
if (wasSelected)
|
||||||
{
|
{
|
||||||
if (menuFromSelected != null &&
|
if (menuFromSelected != null &&
|
||||||
menuFromSelected == focussedMenu?.SubMenu)
|
menuFromSelected == focussedMenu?.SubMenu)
|
||||||
{
|
{
|
||||||
ListView dgv = menuFromSelected.GetDataGridView();
|
focussedMenu = menuFromSelected;
|
||||||
if (dgv != null && dgv.Items.Count > 0)
|
focussedRow = null;
|
||||||
|
if (TrySelectNext(menuFromSelected, 0))
|
||||||
{
|
{
|
||||||
focussedMenu = menuFromSelected;
|
RaiseRowSelectionChanged(menuBefore, rowBefore);
|
||||||
focussedRow = null;
|
doClearOldSelection = wasSelected;
|
||||||
if (TrySelectNext(dgv, 0))
|
|
||||||
{
|
|
||||||
RaiseRowSelectionChanged(menuBefore, rowBefore);
|
|
||||||
toClear = true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -379,28 +372,24 @@ namespace SystemTrayMenu.Handler
|
||||||
|
|
||||||
focussedRow = null;
|
focussedRow = null;
|
||||||
Menu? lastMenu = focussedMenu;
|
Menu? lastMenu = focussedMenu;
|
||||||
if (lastMenu != null)
|
if (lastMenu != null && TrySelectNext(lastMenu, 0))
|
||||||
{
|
{
|
||||||
ListView dgv = lastMenu.GetDataGridView();
|
RaiseRowSelectionChanged(menuBefore, rowBefore);
|
||||||
if (TrySelectNext(dgv, 0))
|
doClearOldSelection = wasSelected;
|
||||||
{
|
|
||||||
RaiseRowSelectionChanged(menuBefore, rowBefore);
|
|
||||||
toClear = true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (focussedMenu?.ParentMenu != null)
|
else if (focussedMenu?.ParentMenu != null)
|
||||||
{
|
{
|
||||||
// Next is in opposite key direction and prev is in key direction ==> TrySelect parent/prev menu
|
// Next is in opposite key direction and prev is in key direction ==> Select parent/prev menu
|
||||||
focussedMenu = focussedMenu.ParentMenu;
|
focussedMenu = focussedMenu.ParentMenu;
|
||||||
focussedRow = null;
|
focussedRow = null;
|
||||||
ListView dgv = focussedMenu.GetDataGridView();
|
ListView dgv = focussedMenu.GetDataGridView();
|
||||||
if (TrySelectNext(dgv, dgv.Items.IndexOf(dgv.SelectedItems.Count > 0 ? dgv.SelectedItems[0] : null)) ||
|
if (TrySelectNext(focussedMenu, dgv.Items.IndexOf(dgv.SelectedItems.Count > 0 ? dgv.SelectedItems[0] : null)) ||
|
||||||
TrySelectNext(dgv, 0))
|
TrySelectNext(focussedMenu, 0))
|
||||||
{
|
{
|
||||||
RaiseRowSelectionChanged(menuBefore, rowBefore);
|
RaiseRowSelectionChanged(menuBefore, rowBefore);
|
||||||
toClear = true;
|
doClearOldSelection = wasSelected;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -413,7 +402,7 @@ namespace SystemTrayMenu.Handler
|
||||||
{
|
{
|
||||||
RowDeselected?.Invoke(menuBefore, rowBefore);
|
RowDeselected?.Invoke(menuBefore, rowBefore);
|
||||||
ResetSelectedByKey();
|
ResetSelectedByKey();
|
||||||
toClear = true;
|
doClearOldSelection = wasSelected;
|
||||||
ClosePressed?.Invoke();
|
ClosePressed?.Invoke();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -422,7 +411,7 @@ namespace SystemTrayMenu.Handler
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isSelected && toClear)
|
if (doClearOldSelection)
|
||||||
{
|
{
|
||||||
ClearIsSelectedByKey(menuBefore, rowBefore);
|
ClearIsSelectedByKey(menuBefore, rowBefore);
|
||||||
}
|
}
|
||||||
|
@ -439,15 +428,18 @@ namespace SystemTrayMenu.Handler
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private bool TrySelectNext(ListView dgv, int indexStart)
|
private bool TrySelectNext(Menu menu, int indexStart)
|
||||||
{
|
{
|
||||||
bool found = false;
|
bool found = false;
|
||||||
if (indexStart >= 0)
|
if (indexStart >= 0)
|
||||||
{
|
{
|
||||||
|
ListView dgv = menu.GetDataGridView();
|
||||||
for (uint i = (uint)indexStart; i < dgv.Items.Count; i++)
|
for (uint i = (uint)indexStart; i < dgv.Items.Count; i++)
|
||||||
{
|
{
|
||||||
if (TrySelect(dgv, (ListViewItemData)dgv.Items[(int)i]))
|
ListViewItemData itemData = (ListViewItemData)dgv.Items[(int)i];
|
||||||
|
if (itemData != focussedRow)
|
||||||
{
|
{
|
||||||
|
Select(dgv, itemData);
|
||||||
found = true;
|
found = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -457,11 +449,12 @@ namespace SystemTrayMenu.Handler
|
||||||
return found;
|
return found;
|
||||||
}
|
}
|
||||||
|
|
||||||
private bool TrySelectPrevious(ListView dgv, int indexStart)
|
private bool TrySelectPrevious(Menu menu, int indexStart)
|
||||||
{
|
{
|
||||||
bool found = false;
|
bool found = false;
|
||||||
if (indexStart > 0)
|
if (indexStart > 0)
|
||||||
{
|
{
|
||||||
|
ListView dgv = menu.GetDataGridView();
|
||||||
if (dgv.Items.Count <= indexStart)
|
if (dgv.Items.Count <= indexStart)
|
||||||
{
|
{
|
||||||
indexStart = dgv.Items.Count - 1;
|
indexStart = dgv.Items.Count - 1;
|
||||||
|
@ -469,8 +462,10 @@ namespace SystemTrayMenu.Handler
|
||||||
|
|
||||||
for (int i = indexStart; i > -1; i--)
|
for (int i = indexStart; i > -1; i--)
|
||||||
{
|
{
|
||||||
if (TrySelect(dgv, (ListViewItemData)dgv.Items[i]))
|
ListViewItemData itemData = (ListViewItemData)dgv.Items[i];
|
||||||
|
if (itemData != focussedRow)
|
||||||
{
|
{
|
||||||
|
Select(dgv, itemData);
|
||||||
found = true;
|
found = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -480,25 +475,12 @@ namespace SystemTrayMenu.Handler
|
||||||
return found;
|
return found;
|
||||||
}
|
}
|
||||||
|
|
||||||
private bool TrySelect(ListView dgv, ListViewItemData itemData)
|
private void Select(ListView dgv, ListViewItemData itemData)
|
||||||
{
|
{
|
||||||
bool found = false;
|
focussedRow = itemData;
|
||||||
if (itemData != focussedRow)
|
itemData.data.IsSelected = true;
|
||||||
{
|
dgv.SelectedItems.Add(itemData);
|
||||||
focussedRow = itemData;
|
dgv.ScrollIntoView(itemData);
|
||||||
itemData.data.IsSelected = true;
|
|
||||||
if (dgv.SelectedItems.Contains(itemData))
|
|
||||||
{
|
|
||||||
dgv.SelectedItems.Remove(itemData);
|
|
||||||
}
|
|
||||||
|
|
||||||
dgv.SelectedItems.Add(itemData);
|
|
||||||
dgv.ScrollIntoView(itemData);
|
|
||||||
|
|
||||||
found = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
return found;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,7 +12,6 @@ namespace SystemTrayMenu.Business
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Windows;
|
using System.Windows;
|
||||||
using System.Windows.Controls;
|
using System.Windows.Controls;
|
||||||
using System.Windows.Input;
|
|
||||||
using System.Windows.Media;
|
using System.Windows.Media;
|
||||||
using System.Windows.Threading;
|
using System.Windows.Threading;
|
||||||
using Microsoft.Win32;
|
using Microsoft.Win32;
|
||||||
|
@ -536,9 +535,6 @@ namespace SystemTrayMenu.Business
|
||||||
|
|
||||||
ListView dgv = menu.GetDataGridView();
|
ListView dgv = menu.GetDataGridView();
|
||||||
dgv.SelectionChanged += Dgv_SelectionChanged;
|
dgv.SelectionChanged += Dgv_SelectionChanged;
|
||||||
#if TODO // Misc MouseEvents
|
|
||||||
dgv.MouseMove += waitToOpenMenu.MouseMove;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
if (menu.Level == 0)
|
if (menu.Level == 0)
|
||||||
{
|
{
|
||||||
|
@ -600,10 +596,7 @@ namespace SystemTrayMenu.Business
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void Dgv_SelectionChanged(object sender, EventArgs e)
|
private void Dgv_SelectionChanged(object sender, EventArgs e) => RefreshSelection((ListView)sender);
|
||||||
{
|
|
||||||
RefreshSelection((ListView)sender);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void RefreshSelection(ListView dgv)
|
private void RefreshSelection(ListView dgv)
|
||||||
{
|
{
|
||||||
|
|
|
@ -5,9 +5,6 @@
|
||||||
namespace SystemTrayMenu.Handler
|
namespace SystemTrayMenu.Handler
|
||||||
{
|
{
|
||||||
using System;
|
using System;
|
||||||
using System.Collections;
|
|
||||||
using System.Windows.Controls;
|
|
||||||
using System.Windows.Input;
|
|
||||||
using System.Windows.Threading;
|
using System.Windows.Threading;
|
||||||
using SystemTrayMenu.DataClasses;
|
using SystemTrayMenu.DataClasses;
|
||||||
using SystemTrayMenu.Utilities;
|
using SystemTrayMenu.Utilities;
|
||||||
|
@ -20,16 +17,7 @@ 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;
|
||||||
#if TODO // Misc MouseEvents
|
|
||||||
private ListView? dgvTmp;
|
|
||||||
private ListViewItemData rowItemDataTmp;
|
|
||||||
#endif
|
|
||||||
private bool alreadyOpened;
|
private bool alreadyOpened;
|
||||||
|
|
||||||
#if TODO // Misc MouseEvents
|
|
||||||
private int mouseMoveEvents;
|
|
||||||
private DateTime dateTimeLastMouseMoveEvent = DateTime.Now;
|
|
||||||
#endif
|
|
||||||
private bool checkForMouseActive = true;
|
private bool checkForMouseActive = true;
|
||||||
|
|
||||||
internal WaitToLoadMenu()
|
internal WaitToLoadMenu()
|
||||||
|
@ -64,13 +52,6 @@ namespace SystemTrayMenu.Handler
|
||||||
SetData(menu.GetDataGridView(), itemData);
|
SetData(menu.GetDataGridView(), itemData);
|
||||||
timerStartLoad.Start();
|
timerStartLoad.Start();
|
||||||
}
|
}
|
||||||
#if TODO // Misc MouseEvents
|
|
||||||
else
|
|
||||||
{
|
|
||||||
dgvTmp = dgv;
|
|
||||||
rowItemDataTmp = itemData;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
internal void RowSelected(Menu menu, ListViewItemData itemData)
|
internal void RowSelected(Menu menu, ListViewItemData itemData)
|
||||||
|
@ -124,35 +105,6 @@ namespace SystemTrayMenu.Handler
|
||||||
CallOpenMenuNow();
|
CallOpenMenuNow();
|
||||||
}
|
}
|
||||||
|
|
||||||
#if TODO // Misc MouseEvents
|
|
||||||
internal void MouseMove(object sender, MouseEventArgs e)
|
|
||||||
{
|
|
||||||
if (!MouseActive)
|
|
||||||
{
|
|
||||||
if (mouseMoveEvents > 6)
|
|
||||||
{
|
|
||||||
MouseActive = true;
|
|
||||||
if (dgvTmp != null)
|
|
||||||
{
|
|
||||||
MouseEnter(dgvTmp, rowItemDataTmp);
|
|
||||||
}
|
|
||||||
|
|
||||||
mouseMoveEvents = 0;
|
|
||||||
}
|
|
||||||
else if (DateTime.Now - dateTimeLastMouseMoveEvent <
|
|
||||||
new TimeSpan(0, 0, 0, 0, 200))
|
|
||||||
{
|
|
||||||
mouseMoveEvents++;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
dateTimeLastMouseMoveEvent = DateTime.Now;
|
|
||||||
mouseMoveEvents = 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
private void WaitStartLoad_Tick(object? sender, EventArgs e)
|
private void WaitStartLoad_Tick(object? sender, EventArgs e)
|
||||||
{
|
{
|
||||||
timerStartLoad.Stop();
|
timerStartLoad.Stop();
|
||||||
|
@ -195,13 +147,10 @@ namespace SystemTrayMenu.Handler
|
||||||
}
|
}
|
||||||
|
|
||||||
alreadyOpened = false;
|
alreadyOpened = false;
|
||||||
#if TODO // Misc MouseEvents
|
|
||||||
dgvTmp = null;
|
|
||||||
#endif
|
|
||||||
this.dgv = dgv;
|
this.dgv = dgv;
|
||||||
dgvItemData = itemData;
|
dgvItemData = itemData;
|
||||||
dgvItemData.data.IsSelected = true;
|
dgvItemData.data.IsSelected = true;
|
||||||
|
|
||||||
dgv.SelectedItem = dgvItemData;
|
dgv.SelectedItem = dgvItemData;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -263,12 +263,6 @@ namespace SystemTrayMenu.UserInterface
|
||||||
|
|
||||||
internal event Action? MenuScrolled;
|
internal event Action? MenuScrolled;
|
||||||
|
|
||||||
#if TODO // Misc MouseEvents
|
|
||||||
internal new event Action MouseEnter;
|
|
||||||
|
|
||||||
internal new event Action MouseLeave;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
internal event Action<Menu, Key, ModifierKeys>? CmdKeyProcessed;
|
internal event Action<Menu, Key, ModifierKeys>? CmdKeyProcessed;
|
||||||
|
|
||||||
internal event Action? SearchTextChanging;
|
internal event Action? SearchTextChanging;
|
||||||
|
|
Loading…
Reference in a new issue