2022-10-23 11:02:31 +13:00
|
|
|
|
// <copyright file="WaitToLoadMenu.cs" company="PlaceholderCompany">
|
|
|
|
|
// Copyright (c) PlaceholderCompany. All rights reserved.
|
|
|
|
|
// </copyright>
|
|
|
|
|
|
|
|
|
|
namespace SystemTrayMenu.Handler
|
|
|
|
|
{
|
|
|
|
|
using System;
|
2023-04-25 10:24:48 +12:00
|
|
|
|
using System.Collections;
|
2023-04-25 08:38:36 +12:00
|
|
|
|
using System.Windows.Controls;
|
2022-10-23 11:02:31 +13:00
|
|
|
|
using System.Windows.Input;
|
|
|
|
|
using System.Windows.Threading;
|
|
|
|
|
using SystemTrayMenu.DataClasses;
|
|
|
|
|
using SystemTrayMenu.Utilities;
|
2022-11-20 07:33:23 +13:00
|
|
|
|
using static SystemTrayMenu.UserInterface.Menu;
|
2022-10-23 11:02:31 +13:00
|
|
|
|
using ListView = System.Windows.Controls.ListView;
|
|
|
|
|
using Menu = SystemTrayMenu.UserInterface.Menu;
|
|
|
|
|
|
|
|
|
|
internal class WaitToLoadMenu : IDisposable
|
|
|
|
|
{
|
|
|
|
|
private readonly DispatcherTimer timerStartLoad = new();
|
2023-04-17 09:27:27 +12:00
|
|
|
|
private ListView? dgv;
|
2023-04-25 10:24:48 +12:00
|
|
|
|
private ListViewItemData? dgvItemData;
|
|
|
|
|
#if TODO // Misc MouseEvents
|
2023-04-30 10:06:00 +12:00
|
|
|
|
private ListView? dgvTmp;
|
2023-05-01 09:36:26 +12:00
|
|
|
|
private ListViewItemData rowItemDataTmp;
|
2023-04-25 10:24:48 +12:00
|
|
|
|
#endif
|
2023-04-17 03:39:32 +12:00
|
|
|
|
private bool alreadyOpened;
|
2022-10-23 11:02:31 +13:00
|
|
|
|
|
2023-04-25 10:24:48 +12:00
|
|
|
|
#if TODO // Misc MouseEvents
|
2022-10-23 11:02:31 +13:00
|
|
|
|
private int mouseMoveEvents;
|
|
|
|
|
private DateTime dateTimeLastMouseMoveEvent = DateTime.Now;
|
2023-04-30 10:06:00 +12:00
|
|
|
|
#endif
|
2022-10-23 11:02:31 +13:00
|
|
|
|
private bool checkForMouseActive = true;
|
|
|
|
|
|
|
|
|
|
internal WaitToLoadMenu()
|
|
|
|
|
{
|
|
|
|
|
timerStartLoad.Interval = TimeSpan.FromMilliseconds(Properties.Settings.Default.TimeUntilOpens);
|
|
|
|
|
timerStartLoad.Tick += WaitStartLoad_Tick;
|
|
|
|
|
}
|
|
|
|
|
|
2023-04-17 09:27:27 +12:00
|
|
|
|
internal event Action<RowData>? StartLoadMenu;
|
2022-10-23 11:02:31 +13:00
|
|
|
|
|
2023-04-17 09:27:27 +12:00
|
|
|
|
internal event Action<int>? CloseMenu;
|
2022-10-23 11:02:31 +13:00
|
|
|
|
|
2023-04-17 09:27:27 +12:00
|
|
|
|
internal event Action? StopLoadMenu;
|
2022-10-23 11:02:31 +13:00
|
|
|
|
|
2023-05-06 04:52:05 +12:00
|
|
|
|
internal event Action<Menu, ListViewItemData>? MouseEnterOk;
|
2022-10-23 11:02:31 +13:00
|
|
|
|
|
|
|
|
|
internal bool MouseActive { get; set; }
|
|
|
|
|
|
|
|
|
|
public void Dispose()
|
|
|
|
|
{
|
|
|
|
|
timerStartLoad.Stop();
|
|
|
|
|
}
|
|
|
|
|
|
2023-05-06 04:52:05 +12:00
|
|
|
|
internal void MouseEnter(Menu menu, ListViewItemData itemData)
|
2022-10-23 11:02:31 +13:00
|
|
|
|
{
|
|
|
|
|
if (MouseActive)
|
|
|
|
|
{
|
2023-05-06 04:52:05 +12:00
|
|
|
|
MouseEnterOk?.Invoke(menu, itemData);
|
2023-04-25 10:24:48 +12:00
|
|
|
|
timerStartLoad.Stop();
|
|
|
|
|
StopLoadMenu?.Invoke();
|
|
|
|
|
checkForMouseActive = true;
|
2023-05-06 04:52:05 +12:00
|
|
|
|
SetData(menu.GetDataGridView(), itemData);
|
2023-04-25 10:24:48 +12:00
|
|
|
|
timerStartLoad.Start();
|
2022-10-23 11:02:31 +13:00
|
|
|
|
}
|
2023-04-30 10:06:00 +12:00
|
|
|
|
#if TODO // Misc MouseEvents
|
2022-10-23 11:02:31 +13:00
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
dgvTmp = dgv;
|
2023-05-01 09:36:26 +12:00
|
|
|
|
rowItemDataTmp = itemData;
|
2022-10-23 11:02:31 +13:00
|
|
|
|
}
|
2023-04-30 10:06:00 +12:00
|
|
|
|
#endif
|
2022-10-23 11:02:31 +13:00
|
|
|
|
}
|
|
|
|
|
|
2023-05-05 10:08:39 +12:00
|
|
|
|
internal void RowSelected(Menu menu, ListViewItemData itemData)
|
2022-10-23 11:02:31 +13:00
|
|
|
|
{
|
2023-04-25 10:24:48 +12:00
|
|
|
|
timerStartLoad.Stop();
|
|
|
|
|
StopLoadMenu?.Invoke();
|
2023-05-05 10:08:39 +12:00
|
|
|
|
SetData(menu.GetDataGridView(), itemData);
|
2023-04-25 10:24:48 +12:00
|
|
|
|
MouseActive = false;
|
|
|
|
|
checkForMouseActive = false;
|
|
|
|
|
timerStartLoad.Start();
|
2022-10-23 11:02:31 +13:00
|
|
|
|
}
|
|
|
|
|
|
2023-04-25 10:24:48 +12:00
|
|
|
|
internal void MouseLeave(ListView dgv, ListViewItemData itemData)
|
2022-10-23 11:02:31 +13:00
|
|
|
|
{
|
|
|
|
|
if (MouseActive)
|
|
|
|
|
{
|
|
|
|
|
timerStartLoad.Stop();
|
|
|
|
|
StopLoadMenu?.Invoke();
|
2023-04-25 10:24:48 +12:00
|
|
|
|
ResetData(dgv, itemData);
|
2022-10-23 11:02:31 +13:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-05-05 10:08:39 +12:00
|
|
|
|
internal void RowDeselected(Menu? menu, ListViewItemData? itemData)
|
2022-10-23 11:02:31 +13:00
|
|
|
|
{
|
|
|
|
|
timerStartLoad.Stop();
|
|
|
|
|
StopLoadMenu?.Invoke();
|
2023-05-05 10:08:39 +12:00
|
|
|
|
if (menu != null && itemData != null)
|
2023-04-25 10:24:48 +12:00
|
|
|
|
{
|
2023-05-05 10:08:39 +12:00
|
|
|
|
ResetData(menu.GetDataGridView(), itemData);
|
2023-04-25 10:24:48 +12:00
|
|
|
|
}
|
|
|
|
|
|
2022-10-23 11:02:31 +13:00
|
|
|
|
MouseActive = false;
|
|
|
|
|
}
|
|
|
|
|
|
2023-04-25 10:24:48 +12:00
|
|
|
|
internal void ClickOpensInstantly(ListView dgv, ListViewItemData itemData)
|
2022-10-23 11:02:31 +13:00
|
|
|
|
{
|
2023-04-25 08:38:36 +12:00
|
|
|
|
timerStartLoad.Stop();
|
2023-04-25 10:24:48 +12:00
|
|
|
|
SetData(dgv, itemData);
|
2023-04-25 08:38:36 +12:00
|
|
|
|
MouseActive = true;
|
|
|
|
|
checkForMouseActive = false;
|
|
|
|
|
CallOpenMenuNow();
|
2022-10-23 11:02:31 +13:00
|
|
|
|
}
|
|
|
|
|
|
2023-05-05 10:08:39 +12:00
|
|
|
|
internal void EnterOpensInstantly(Menu menu, ListViewItemData itemData)
|
2022-10-23 11:02:31 +13:00
|
|
|
|
{
|
2023-04-25 10:24:48 +12:00
|
|
|
|
timerStartLoad.Stop();
|
|
|
|
|
StopLoadMenu?.Invoke();
|
2023-05-05 10:08:39 +12:00
|
|
|
|
SetData(menu.GetDataGridView(), itemData);
|
2023-04-25 10:24:48 +12:00
|
|
|
|
MouseActive = false;
|
|
|
|
|
checkForMouseActive = false;
|
|
|
|
|
CallOpenMenuNow();
|
2022-10-23 11:02:31 +13:00
|
|
|
|
}
|
|
|
|
|
|
2023-04-25 10:24:48 +12:00
|
|
|
|
#if TODO // Misc MouseEvents
|
2022-10-23 11:02:31 +13:00
|
|
|
|
internal void MouseMove(object sender, MouseEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (!MouseActive)
|
|
|
|
|
{
|
|
|
|
|
if (mouseMoveEvents > 6)
|
|
|
|
|
{
|
|
|
|
|
MouseActive = true;
|
2023-04-17 09:27:27 +12:00
|
|
|
|
if (dgvTmp != null)
|
2022-10-23 11:02:31 +13:00
|
|
|
|
{
|
2023-05-01 09:36:26 +12:00
|
|
|
|
MouseEnter(dgvTmp, rowItemDataTmp);
|
2022-10-23 11:02:31 +13:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
mouseMoveEvents = 0;
|
|
|
|
|
}
|
|
|
|
|
else if (DateTime.Now - dateTimeLastMouseMoveEvent <
|
|
|
|
|
new TimeSpan(0, 0, 0, 0, 200))
|
|
|
|
|
{
|
|
|
|
|
mouseMoveEvents++;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
dateTimeLastMouseMoveEvent = DateTime.Now;
|
|
|
|
|
mouseMoveEvents = 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-04-25 10:24:48 +12:00
|
|
|
|
#endif
|
2022-10-23 11:02:31 +13:00
|
|
|
|
|
2023-04-17 09:27:27 +12:00
|
|
|
|
private void WaitStartLoad_Tick(object? sender, EventArgs e)
|
2022-10-23 11:02:31 +13:00
|
|
|
|
{
|
|
|
|
|
timerStartLoad.Stop();
|
|
|
|
|
if (!checkForMouseActive || MouseActive)
|
|
|
|
|
{
|
|
|
|
|
CallOpenMenuNow();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void CallOpenMenuNow()
|
|
|
|
|
{
|
2023-04-25 10:24:48 +12:00
|
|
|
|
if (!alreadyOpened && dgv != null && dgvItemData != null && dgv.Items.Contains(dgvItemData))
|
2022-10-23 11:02:31 +13:00
|
|
|
|
{
|
2023-04-17 03:39:32 +12:00
|
|
|
|
alreadyOpened = true;
|
|
|
|
|
|
2023-04-25 10:24:48 +12:00
|
|
|
|
RowData rowData = dgvItemData.data;
|
2022-10-23 11:02:31 +13:00
|
|
|
|
Menu menu = (Menu)dgv.GetParentWindow();
|
|
|
|
|
rowData.Level = menu.Level;
|
|
|
|
|
|
2023-05-03 08:04:32 +12:00
|
|
|
|
// Give the opening window focus
|
|
|
|
|
// if closing window lose focus no window would have focus any more
|
|
|
|
|
menu?.Activate();
|
2023-04-28 08:19:02 +12:00
|
|
|
|
menu?.FocusTextBox();
|
|
|
|
|
|
2023-05-03 08:04:32 +12:00
|
|
|
|
CloseMenu?.Invoke(rowData.Level + 1);
|
|
|
|
|
|
2023-04-30 04:57:39 +12:00
|
|
|
|
if (rowData.IsPointingToFolder &&
|
2022-10-23 11:02:31 +13:00
|
|
|
|
rowData.Level + 1 < MenuDefines.MenusMax)
|
|
|
|
|
{
|
2023-04-17 09:27:27 +12:00
|
|
|
|
StartLoadMenu?.Invoke(rowData);
|
2022-10-23 11:02:31 +13:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-04-25 10:24:48 +12:00
|
|
|
|
private void SetData(ListView dgv, ListViewItemData itemData)
|
2022-10-23 11:02:31 +13:00
|
|
|
|
{
|
2023-04-25 10:24:48 +12:00
|
|
|
|
if (this.dgv == dgv && dgvItemData == itemData)
|
2023-04-17 03:39:32 +12:00
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
alreadyOpened = false;
|
2023-04-30 10:06:00 +12:00
|
|
|
|
#if TODO // Misc MouseEvents
|
2022-10-23 11:02:31 +13:00
|
|
|
|
dgvTmp = null;
|
2023-04-30 10:06:00 +12:00
|
|
|
|
#endif
|
2022-10-23 11:02:31 +13:00
|
|
|
|
this.dgv = dgv;
|
2023-04-25 10:24:48 +12:00
|
|
|
|
dgvItemData = itemData;
|
2023-05-05 10:08:39 +12:00
|
|
|
|
dgvItemData.data.IsSelected = true;
|
2022-10-23 11:02:31 +13:00
|
|
|
|
|
2023-04-25 10:24:48 +12:00
|
|
|
|
dgv.SelectedItem = dgvItemData;
|
2022-10-23 11:02:31 +13:00
|
|
|
|
}
|
|
|
|
|
|
2023-04-25 10:24:48 +12:00
|
|
|
|
private void ResetData(ListView dgv, ListViewItemData itemData)
|
2022-10-23 11:02:31 +13:00
|
|
|
|
{
|
2023-04-25 10:24:48 +12:00
|
|
|
|
RowData rowData = itemData.data;
|
2023-05-05 10:08:39 +12:00
|
|
|
|
rowData.IsSelected = false;
|
|
|
|
|
rowData.IsClicking = false;
|
|
|
|
|
dgv.SelectedItem = null;
|
|
|
|
|
this.dgv = null;
|
|
|
|
|
dgvItemData = null;
|
2022-10-23 11:02:31 +13:00
|
|
|
|
}
|
|
|
|
|
}
|
2023-04-25 10:24:48 +12:00
|
|
|
|
}
|