mirror of
https://github.com/Hofknecht/SystemTrayMenu.git
synced 2024-07-05 22:40:41 +12:00
Simplified some mouse and open events
This commit is contained in:
parent
40871c7e96
commit
6ebfed5f78
|
@ -319,15 +319,8 @@ namespace SystemTrayMenu.Handler
|
||||||
RowData trigger = ((Menu.ListViewItemData)dgv.Items[iRowKey]).data;
|
RowData trigger = ((Menu.ListViewItemData)dgv.Items[iRowKey]).data;
|
||||||
if (trigger.IsMenuOpen || !trigger.ContainsMenu)
|
if (trigger.IsMenuOpen || !trigger.ContainsMenu)
|
||||||
{
|
{
|
||||||
trigger.MouseClick(null, out bool toCloseByMouseClick);
|
trigger.OpenItem(out bool doCloseAfterOpen);
|
||||||
#if TODO // Misc MouseEvents
|
if (doCloseAfterOpen)
|
||||||
trigger.DoubleClick(
|
|
||||||
new MouseButtonEventArgs(MouseButtons.Left, 0, 0, 0, 0),
|
|
||||||
out bool toCloseByDoubleClick);
|
|
||||||
#else
|
|
||||||
bool toCloseByDoubleClick = false;
|
|
||||||
#endif
|
|
||||||
if (toCloseByMouseClick || toCloseByDoubleClick)
|
|
||||||
{
|
{
|
||||||
ClosePressed?.Invoke();
|
ClosePressed?.Invoke();
|
||||||
}
|
}
|
||||||
|
|
|
@ -43,7 +43,9 @@ namespace SystemTrayMenu.Business
|
||||||
private OpenCloseState openCloseState = OpenCloseState.Default;
|
private OpenCloseState openCloseState = OpenCloseState.Default;
|
||||||
private TaskbarPosition taskbarPosition = new WindowsTaskbar().Position;
|
private TaskbarPosition taskbarPosition = new WindowsTaskbar().Position;
|
||||||
private bool searchTextChanging;
|
private bool searchTextChanging;
|
||||||
|
#if TODO // Misc MouseEvents
|
||||||
private int lastMouseDownRowIndex = -1;
|
private int lastMouseDownRowIndex = -1;
|
||||||
|
#endif
|
||||||
private bool showMenuAfterMainPreload;
|
private bool showMenuAfterMainPreload;
|
||||||
private bool hideSubmenuDuringRefreshSearch;
|
private bool hideSubmenuDuringRefreshSearch;
|
||||||
|
|
||||||
|
@ -603,7 +605,8 @@ namespace SystemTrayMenu.Business
|
||||||
menu.CellMouseLeave += dgvMouseRow.CellMouseLeave;
|
menu.CellMouseLeave += dgvMouseRow.CellMouseLeave;
|
||||||
menu.CellMouseDown += Dgv_MouseDown;
|
menu.CellMouseDown += Dgv_MouseDown;
|
||||||
menu.CellMouseUp += Dgv_MouseUp;
|
menu.CellMouseUp += Dgv_MouseUp;
|
||||||
menu.CellMouseClick += Dgv_MouseClick;
|
menu.CellOpenOnClick += Dgv_OpenItemOnClick;
|
||||||
|
menu.ClosePressed += MenusFadeOut;
|
||||||
|
|
||||||
ListView? dgv = menu.GetDataGridView();
|
ListView? dgv = menu.GetDataGridView();
|
||||||
if (dgv != null)
|
if (dgv != null)
|
||||||
|
@ -666,24 +669,23 @@ namespace SystemTrayMenu.Business
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void Dgv_MouseDown(object sender, int index, MouseButtonEventArgs e)
|
private void Dgv_MouseDown(ListView dgv, int index, MouseButtonEventArgs e)
|
||||||
{
|
{
|
||||||
ListView dgv = (ListView)sender;
|
|
||||||
|
|
||||||
MouseEnterOk(dgv, index, true);
|
MouseEnterOk(dgv, index, true);
|
||||||
|
|
||||||
// TODO WPF: Move directly into ListViewItem_PreviewMouseDown ?
|
#if TODO // Misc MouseEvents
|
||||||
((Menu.ListViewItemData)dgv.Items[index]).data.MouseDown(dgv, e);
|
|
||||||
|
|
||||||
if (e.LeftButton == MouseButtonState.Pressed)
|
if (e.LeftButton == MouseButtonState.Pressed)
|
||||||
{
|
{
|
||||||
lastMouseDownRowIndex = index;
|
lastMouseDownRowIndex = index;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
private void Dgv_MouseUp(object sender, int index, MouseButtonEventArgs e)
|
private void Dgv_MouseUp(object sender, int index, MouseButtonEventArgs e)
|
||||||
{
|
{
|
||||||
|
#if TODO // Misc MouseEvents
|
||||||
lastMouseDownRowIndex = -1;
|
lastMouseDownRowIndex = -1;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
private void MouseEnterOk(ListView dgv, int rowIndex)
|
private void MouseEnterOk(ListView dgv, int rowIndex)
|
||||||
|
@ -726,31 +728,12 @@ namespace SystemTrayMenu.Business
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
private void Dgv_MouseClick(ListView sender, int index, MouseButtonEventArgs e)
|
private void Dgv_OpenItemOnClick(ListView sender, ListViewItem item)
|
||||||
{
|
{
|
||||||
bool doClose = false;
|
#if TODO // Misc MouseEvents
|
||||||
|
|
||||||
if (e.ClickCount == 1)
|
|
||||||
{
|
|
||||||
lastMouseDownRowIndex = -1;
|
|
||||||
|
|
||||||
((Menu.ListViewItemData)sender.Items[index]).data.MouseClick(e, out doClose);
|
|
||||||
|
|
||||||
waitToOpenMenu.ClickOpensInstantly(sender, index);
|
|
||||||
}
|
|
||||||
else if (e.ClickCount == 2)
|
|
||||||
{
|
|
||||||
lastMouseDownRowIndex = -1;
|
|
||||||
|
|
||||||
((Menu.ListViewItemData)sender.Items[index]).data.DoubleClick(e, out doClose);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (doClose)
|
|
||||||
{
|
|
||||||
MenusFadeOut();
|
|
||||||
}
|
|
||||||
|
|
||||||
lastMouseDownRowIndex = -1;
|
lastMouseDownRowIndex = -1;
|
||||||
|
#endif
|
||||||
|
waitToOpenMenu.ClickOpensInstantly(sender, item);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void Dgv_SelectionChanged(object sender, EventArgs e)
|
private void Dgv_SelectionChanged(object sender, EventArgs e)
|
||||||
|
|
|
@ -5,6 +5,7 @@
|
||||||
namespace SystemTrayMenu.Handler
|
namespace SystemTrayMenu.Handler
|
||||||
{
|
{
|
||||||
using System;
|
using System;
|
||||||
|
using System.Windows.Controls;
|
||||||
using System.Windows.Input;
|
using System.Windows.Input;
|
||||||
using System.Windows.Threading;
|
using System.Windows.Threading;
|
||||||
using SystemTrayMenu.DataClasses;
|
using SystemTrayMenu.DataClasses;
|
||||||
|
@ -100,16 +101,13 @@ namespace SystemTrayMenu.Handler
|
||||||
MouseActive = false;
|
MouseActive = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
internal void ClickOpensInstantly(ListView dgv, int rowIndex)
|
internal void ClickOpensInstantly(ListView dgv, ListViewItem item)
|
||||||
{
|
{
|
||||||
if (dgv.Items.Count > rowIndex)
|
timerStartLoad.Stop();
|
||||||
{
|
SetData(dgv, dgv.IndexOfSenderItem(item));
|
||||||
timerStartLoad.Stop();
|
MouseActive = true;
|
||||||
SetData(dgv, rowIndex);
|
checkForMouseActive = false;
|
||||||
MouseActive = true;
|
CallOpenMenuNow();
|
||||||
checkForMouseActive = false;
|
|
||||||
CallOpenMenuNow();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
internal void EnterOpensInstantly(ListView dgv, int rowIndex)
|
internal void EnterOpensInstantly(ListView dgv, int rowIndex)
|
||||||
|
|
|
@ -144,8 +144,6 @@ namespace SystemTrayMenu.DataClasses
|
||||||
|
|
||||||
internal bool IconLoading { get; set; }
|
internal bool IconLoading { get; set; }
|
||||||
|
|
||||||
internal bool ProcessStarted { get; set; }
|
|
||||||
|
|
||||||
internal void ReadIcon(bool updateIconInBackground)
|
internal void ReadIcon(bool updateIconInBackground)
|
||||||
{
|
{
|
||||||
if (IsFolder || IsLinkToFolder)
|
if (IsFolder || IsLinkToFolder)
|
||||||
|
@ -227,57 +225,37 @@ namespace SystemTrayMenu.DataClasses
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
internal void MouseClick(MouseEventArgs? e, out bool toCloseByDoubleClick)
|
internal void OpenItem(out bool doCloseAfterOpen, int clickCount = -1)
|
||||||
{
|
{
|
||||||
IsClicking = false;
|
IsClicking = false;
|
||||||
toCloseByDoubleClick = false;
|
doCloseAfterOpen = false;
|
||||||
if (Properties.Settings.Default.OpenItemWithOneClick)
|
|
||||||
{
|
|
||||||
OpenItem(e, ref toCloseByDoubleClick);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (Properties.Settings.Default.OpenDirectoryWithOneClick && Path != null &&
|
if (clickCount == -1 ||
|
||||||
ContainsMenu && (e == null || e.LeftButton == MouseButtonState.Pressed))
|
(clickCount == 1 && Properties.Settings.Default.OpenItemWithOneClick) ||
|
||||||
|
(clickCount == 2 && !Properties.Settings.Default.OpenItemWithOneClick))
|
||||||
{
|
{
|
||||||
Log.ProcessStart(Path);
|
if (!ContainsMenu && Path != null && ResolvedPath != null)
|
||||||
if (!Properties.Settings.Default.StaysOpenWhenItemClicked)
|
|
||||||
{
|
{
|
||||||
toCloseByDoubleClick = true;
|
string? workingDirectory = System.IO.Path.GetDirectoryName(ResolvedPath);
|
||||||
|
Log.ProcessStart(Path, string.Empty, false, workingDirectory, true, ResolvedPath);
|
||||||
|
if (!Properties.Settings.Default.StaysOpenWhenItemClicked)
|
||||||
|
{
|
||||||
|
doCloseAfterOpen = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
internal void DoubleClick(MouseButtonEventArgs e, out bool toCloseByDoubleClick)
|
if (clickCount == -1 ||
|
||||||
{
|
(clickCount == 1 && Properties.Settings.Default.OpenDirectoryWithOneClick) ||
|
||||||
IsClicking = false;
|
(clickCount == 2 && !Properties.Settings.Default.OpenDirectoryWithOneClick))
|
||||||
toCloseByDoubleClick = false;
|
|
||||||
if (!Properties.Settings.Default.OpenItemWithOneClick)
|
|
||||||
{
|
{
|
||||||
OpenItem(e, ref toCloseByDoubleClick);
|
if (Path != null && ContainsMenu)
|
||||||
}
|
|
||||||
|
|
||||||
if (!Properties.Settings.Default.OpenDirectoryWithOneClick && Path != null &&
|
|
||||||
ContainsMenu && (e == null || e.LeftButton == MouseButtonState.Pressed))
|
|
||||||
{
|
|
||||||
Log.ProcessStart(Path);
|
|
||||||
if (!Properties.Settings.Default.StaysOpenWhenItemClicked)
|
|
||||||
{
|
{
|
||||||
toCloseByDoubleClick = true;
|
Log.ProcessStart(Path);
|
||||||
}
|
if (!Properties.Settings.Default.StaysOpenWhenItemClicked)
|
||||||
}
|
{
|
||||||
}
|
doCloseAfterOpen = true;
|
||||||
|
}
|
||||||
private void OpenItem(MouseEventArgs? e, ref bool toCloseByOpenItem)
|
|
||||||
{
|
|
||||||
if (!ContainsMenu && Path != null && ResolvedPath != null &&
|
|
||||||
(e == null || e.LeftButton == MouseButtonState.Pressed))
|
|
||||||
{
|
|
||||||
ProcessStarted = true;
|
|
||||||
string? workingDirectory = System.IO.Path.GetDirectoryName(ResolvedPath);
|
|
||||||
Log.ProcessStart(Path, string.Empty, false, workingDirectory, true, ResolvedPath);
|
|
||||||
if (!Properties.Settings.Default.StaysOpenWhenItemClicked)
|
|
||||||
{
|
|
||||||
toCloseByOpenItem = true;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -56,7 +56,7 @@ namespace SystemTrayMenu.Helpers
|
||||||
senderIndex = index;
|
senderIndex = index;
|
||||||
}
|
}
|
||||||
|
|
||||||
internal void CellMouseLeave(T sender, int index)
|
internal void CellMouseLeave()
|
||||||
{
|
{
|
||||||
timerRaiseRowMouseLeave.Start();
|
timerRaiseRowMouseLeave.Start();
|
||||||
}
|
}
|
||||||
|
|
|
@ -300,13 +300,15 @@ namespace SystemTrayMenu.UserInterface
|
||||||
|
|
||||||
internal event Action<ListView, int>? CellMouseEnter;
|
internal event Action<ListView, int>? CellMouseEnter;
|
||||||
|
|
||||||
internal event Action<ListView, int>? CellMouseLeave;
|
internal event Action? CellMouseLeave;
|
||||||
|
|
||||||
internal event Action<ListView, int, MouseButtonEventArgs>? CellMouseDown;
|
internal event Action<ListView, int, MouseButtonEventArgs>? CellMouseDown;
|
||||||
|
|
||||||
internal event Action<ListView, int, MouseButtonEventArgs>? CellMouseUp;
|
internal event Action<ListView, int, MouseButtonEventArgs>? CellMouseUp;
|
||||||
|
|
||||||
internal event Action<ListView, int, MouseButtonEventArgs>? CellMouseClick;
|
internal event Action<ListView, ListViewItem>? CellOpenOnClick;
|
||||||
|
|
||||||
|
internal event Action? ClosePressed;
|
||||||
|
|
||||||
internal event RoutedEventHandler FadeToTransparent
|
internal event RoutedEventHandler FadeToTransparent
|
||||||
{
|
{
|
||||||
|
@ -1242,12 +1244,16 @@ namespace SystemTrayMenu.UserInterface
|
||||||
|
|
||||||
private void ListViewItem_MouseLeave(object sender, MouseEventArgs e)
|
private void ListViewItem_MouseLeave(object sender, MouseEventArgs e)
|
||||||
{
|
{
|
||||||
CellMouseLeave?.Invoke(dgv, dgv.IndexOfSenderItem((ListViewItem)sender));
|
CellMouseLeave?.Invoke();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void ListViewItem_PreviewMouseDown(object sender, MouseButtonEventArgs e)
|
private void ListViewItem_PreviewMouseDown(object sender, MouseButtonEventArgs e)
|
||||||
{
|
{
|
||||||
CellMouseDown?.Invoke(dgv, dgv.IndexOfSenderItem((ListViewItem)sender), e);
|
int index = dgv.IndexOfSenderItem((ListViewItem)sender);
|
||||||
|
|
||||||
|
CellMouseDown?.Invoke(dgv, index, e);
|
||||||
|
|
||||||
|
((ListViewItemData)dgv.Items[index]).data.MouseDown(dgv, e);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void ListViewItem_MouseUp(object sender, MouseButtonEventArgs e)
|
private void ListViewItem_MouseUp(object sender, MouseButtonEventArgs e)
|
||||||
|
@ -1257,7 +1263,19 @@ namespace SystemTrayMenu.UserInterface
|
||||||
|
|
||||||
private void ListViewxItem_PreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
|
private void ListViewxItem_PreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
|
||||||
{
|
{
|
||||||
CellMouseClick?.Invoke(dgv, dgv.IndexOfSenderItem((ListViewItem)sender), e);
|
ListViewItemData row = (ListViewItemData)((ListViewItem)sender).Content;
|
||||||
|
|
||||||
|
row.data.OpenItem(out bool doClose, e.ClickCount);
|
||||||
|
|
||||||
|
if (e.ClickCount == 1)
|
||||||
|
{
|
||||||
|
CellOpenOnClick?.Invoke(dgv, (ListViewItem)sender);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (doClose)
|
||||||
|
{
|
||||||
|
ClosePressed?.Invoke();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
Loading…
Reference in a new issue