-
-
Notifications
You must be signed in to change notification settings - Fork 44
/
WaitToLoadMenu.cs
114 lines (96 loc) · 3.14 KB
/
WaitToLoadMenu.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
// <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;
internal class WaitToLoadMenu : IDisposable
{
private readonly DispatcherTimer timerStartLoad = new();
private RowData? currentItemData;
private bool alreadyOpened;
internal WaitToLoadMenu()
{
timerStartLoad.Interval = TimeSpan.FromMilliseconds(Properties.Settings.Default.TimeUntilOpens);
timerStartLoad.Tick += OpenSubMenuByTimer;
}
internal event Action? StopLoadMenu;
internal event Action<RowData>? MouseSelect;
internal bool MouseActive { get; set; }
public void Dispose() => timerStartLoad.Stop();
internal void MouseEnter(RowData itemData)
{
if (MouseActive)
{
MouseSelect?.Invoke(itemData);
timerStartLoad.Stop();
StopLoadMenu?.Invoke();
SetData(itemData);
timerStartLoad.Start();
}
}
internal void MouseLeave()
{
if (MouseActive)
{
timerStartLoad.Stop();
StopLoadMenu?.Invoke();
currentItemData = null;
}
}
internal void RowSelectionChanged(RowData? itemData)
{
// Deselect
timerStartLoad.Stop();
StopLoadMenu?.Invoke();
currentItemData = null;
MouseActive = false;
// Select (if any)
if (itemData != null)
{
SetData(itemData);
timerStartLoad.Start();
}
}
internal void OpenSubMenuByMouse(RowData itemData)
{
timerStartLoad.Stop();
StopLoadMenu?.Invoke(); // TODO: Missing in v1 ?
SetData(itemData);
MouseActive = true;
OpenSubMenu();
}
internal void OpenSubMenuByKey(RowData itemData)
{
timerStartLoad.Stop();
StopLoadMenu?.Invoke();
SetData(itemData);
MouseActive = false;
OpenSubMenu();
}
private void OpenSubMenuByTimer(object? sender, EventArgs e)
{
timerStartLoad.Stop();
StopLoadMenu?.Invoke(); // TODO: Missing in v1 ?
OpenSubMenu();
}
private void OpenSubMenu()
{
if (!alreadyOpened && currentItemData != null)
{
alreadyOpened = true; // TODO: Check if this bool is still needed?
currentItemData.OpenSubMenu();
}
}
private void SetData(RowData itemData)
{
if (currentItemData != itemData)
{
alreadyOpened = false;
currentItemData = itemData;
}
}
}
}