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;
|
|
|
|
|
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;
|
2023-04-17 03:39:32 +12:00
|
|
|
|
private bool alreadyOpened;
|
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-05-08 10:14:23 +12:00
|
|
|
|
internal event Action<Menu>? 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-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-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-08 10:14:23 +12:00
|
|
|
|
Menu? menuToClose = menu?.SubMenu;
|
|
|
|
|
if (menuToClose != null)
|
|
|
|
|
{
|
|
|
|
|
CloseMenu?.Invoke(menuToClose);
|
|
|
|
|
}
|
2023-05-03 08:04:32 +12:00
|
|
|
|
|
2023-05-08 10:14:23 +12:00
|
|
|
|
if (rowData.IsPointingToFolder)
|
2022-10-23 11:02:31 +13:00
|
|
|
|
{
|
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-05-06 06:01:49 +12:00
|
|
|
|
|
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;
|
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
|
|
|
|
}
|