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;
|
2023-05-19 08:48:18 +12:00
|
|
|
|
using SystemTrayMenu.DataClasses;
|
2022-10-23 11:02:31 +13:00
|
|
|
|
|
|
|
|
|
internal class WaitToLoadMenu : IDisposable
|
|
|
|
|
{
|
|
|
|
|
private readonly DispatcherTimer timerStartLoad = new();
|
2023-05-19 09:28:52 +12:00
|
|
|
|
private RowData? currentItemData;
|
2023-04-17 03:39:32 +12:00
|
|
|
|
private bool alreadyOpened;
|
2022-10-23 11:02:31 +13:00
|
|
|
|
|
|
|
|
|
internal WaitToLoadMenu()
|
|
|
|
|
{
|
|
|
|
|
timerStartLoad.Interval = TimeSpan.FromMilliseconds(Properties.Settings.Default.TimeUntilOpens);
|
2023-05-19 06:42:46 +12:00
|
|
|
|
timerStartLoad.Tick += OpenSubMenuByTimer;
|
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-19 09:28:52 +12:00
|
|
|
|
internal event Action<RowData>? MouseSelect;
|
2022-10-23 11:02:31 +13:00
|
|
|
|
|
|
|
|
|
internal bool MouseActive { get; set; }
|
|
|
|
|
|
2023-05-16 08:34:17 +12:00
|
|
|
|
public void Dispose() => timerStartLoad.Stop();
|
2022-10-23 11:02:31 +13:00
|
|
|
|
|
2023-05-19 09:28:52 +12:00
|
|
|
|
internal void MouseEnter(RowData itemData)
|
2022-10-23 11:02:31 +13:00
|
|
|
|
{
|
|
|
|
|
if (MouseActive)
|
|
|
|
|
{
|
2023-05-19 06:42:46 +12:00
|
|
|
|
MouseSelect?.Invoke(itemData);
|
2023-04-25 10:24:48 +12:00
|
|
|
|
timerStartLoad.Stop();
|
|
|
|
|
StopLoadMenu?.Invoke();
|
2023-05-19 06:42:46 +12:00
|
|
|
|
SetData(itemData);
|
2023-04-25 10:24:48 +12:00
|
|
|
|
timerStartLoad.Start();
|
2022-10-23 11:02:31 +13:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-05-16 08:34:17 +12:00
|
|
|
|
internal void MouseLeave()
|
|
|
|
|
{
|
|
|
|
|
if (MouseActive)
|
|
|
|
|
{
|
|
|
|
|
timerStartLoad.Stop();
|
|
|
|
|
StopLoadMenu?.Invoke();
|
2023-05-19 06:42:46 +12:00
|
|
|
|
currentItemData = null;
|
2023-05-16 08:34:17 +12:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-05-19 09:28:52 +12:00
|
|
|
|
internal void RowSelectionChanged(RowData? itemData)
|
2022-10-23 11:02:31 +13:00
|
|
|
|
{
|
2023-05-15 05:13:44 +12:00
|
|
|
|
// Deselect
|
|
|
|
|
timerStartLoad.Stop();
|
|
|
|
|
StopLoadMenu?.Invoke();
|
2023-05-19 06:42:46 +12:00
|
|
|
|
currentItemData = null;
|
2023-05-15 05:13:44 +12:00
|
|
|
|
MouseActive = false;
|
|
|
|
|
|
|
|
|
|
// Select (if any)
|
2023-05-19 06:42:46 +12:00
|
|
|
|
if (itemData != null)
|
2023-05-12 11:13:02 +12:00
|
|
|
|
{
|
2023-05-19 06:42:46 +12:00
|
|
|
|
SetData(itemData);
|
2023-05-15 05:13:44 +12:00
|
|
|
|
timerStartLoad.Start();
|
2023-05-12 11:13:02 +12:00
|
|
|
|
}
|
2022-10-23 11:02:31 +13:00
|
|
|
|
}
|
|
|
|
|
|
2023-05-19 09:28:52 +12:00
|
|
|
|
internal void OpenSubMenuByMouse(RowData itemData)
|
2022-10-23 11:02:31 +13:00
|
|
|
|
{
|
2023-04-25 08:38:36 +12:00
|
|
|
|
timerStartLoad.Stop();
|
2023-05-25 09:47:41 +12:00
|
|
|
|
StopLoadMenu?.Invoke();
|
2023-05-19 06:42:46 +12:00
|
|
|
|
SetData(itemData);
|
2023-04-25 08:38:36 +12:00
|
|
|
|
MouseActive = true;
|
2023-05-19 06:42:46 +12:00
|
|
|
|
OpenSubMenu();
|
2022-10-23 11:02:31 +13:00
|
|
|
|
}
|
|
|
|
|
|
2023-05-19 09:28:52 +12:00
|
|
|
|
internal void OpenSubMenuByKey(RowData itemData)
|
2022-10-23 11:02:31 +13:00
|
|
|
|
{
|
2023-04-25 10:24:48 +12:00
|
|
|
|
timerStartLoad.Stop();
|
|
|
|
|
StopLoadMenu?.Invoke();
|
2023-05-19 06:42:46 +12:00
|
|
|
|
SetData(itemData);
|
2023-04-25 10:24:48 +12:00
|
|
|
|
MouseActive = false;
|
2023-05-19 06:42:46 +12:00
|
|
|
|
OpenSubMenu();
|
2022-10-23 11:02:31 +13:00
|
|
|
|
}
|
|
|
|
|
|
2023-05-19 06:42:46 +12:00
|
|
|
|
private void OpenSubMenuByTimer(object? sender, EventArgs e)
|
2022-10-23 11:02:31 +13:00
|
|
|
|
{
|
|
|
|
|
timerStartLoad.Stop();
|
2023-05-25 09:47:41 +12:00
|
|
|
|
StopLoadMenu?.Invoke();
|
2023-05-19 06:42:46 +12:00
|
|
|
|
OpenSubMenu();
|
2022-10-23 11:02:31 +13:00
|
|
|
|
}
|
|
|
|
|
|
2023-05-19 06:42:46 +12:00
|
|
|
|
private void OpenSubMenu()
|
2022-10-23 11:02:31 +13:00
|
|
|
|
{
|
2023-05-19 06:42:46 +12:00
|
|
|
|
if (!alreadyOpened && currentItemData != null)
|
2022-10-23 11:02:31 +13:00
|
|
|
|
{
|
2023-05-15 05:13:44 +12:00
|
|
|
|
alreadyOpened = true; // TODO: Check if this bool is still needed?
|
2023-04-28 08:19:02 +12:00
|
|
|
|
|
2023-05-19 06:42:46 +12:00
|
|
|
|
currentItemData.OpenSubMenu();
|
2022-10-23 11:02:31 +13:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-05-19 09:28:52 +12:00
|
|
|
|
private void SetData(RowData itemData)
|
2022-10-23 11:02:31 +13:00
|
|
|
|
{
|
2023-05-19 06:42:46 +12:00
|
|
|
|
if (currentItemData != itemData)
|
2023-04-17 03:39:32 +12:00
|
|
|
|
{
|
2023-05-10 10:55:18 +12:00
|
|
|
|
alreadyOpened = false;
|
2023-04-17 03:39:32 +12:00
|
|
|
|
|
2023-05-15 09:25:34 +12:00
|
|
|
|
currentItemData = itemData;
|
2023-05-10 10:55:18 +12:00
|
|
|
|
}
|
2022-10-23 11:02:31 +13:00
|
|
|
|
}
|
|
|
|
|
}
|
2023-04-25 10:24:48 +12:00
|
|
|
|
}
|