2020-06-21 03:38:21 +12:00
|
|
|
|
using System;
|
|
|
|
|
using System.Windows.Forms;
|
|
|
|
|
using SystemTrayMenu.DataClasses;
|
|
|
|
|
using SystemTrayMenu.UserInterface;
|
|
|
|
|
using SystemTrayMenu.Utilities;
|
|
|
|
|
using Timer = System.Windows.Forms.Timer;
|
|
|
|
|
|
|
|
|
|
namespace SystemTrayMenu.Handler
|
|
|
|
|
{
|
|
|
|
|
internal class WaitToLoadMenu : IDisposable
|
|
|
|
|
{
|
|
|
|
|
internal event Action<RowData> StartLoadMenu;
|
|
|
|
|
internal event EventHandlerEmpty StopLoadMenu;
|
|
|
|
|
|
2020-06-21 06:11:25 +12:00
|
|
|
|
private readonly Timer timerStartLoad = new Timer();
|
2020-06-21 03:38:21 +12:00
|
|
|
|
private DataGridView dgv = null;
|
|
|
|
|
private int rowIndex = 0;
|
|
|
|
|
|
2020-06-21 06:11:25 +12:00
|
|
|
|
internal bool MouseActive = false;
|
|
|
|
|
private int mouseMoveEvents = 0;
|
|
|
|
|
private DateTime dateTimeLastMouseMoveEvent = DateTime.Now;
|
2020-06-21 03:38:21 +12:00
|
|
|
|
private bool checkForMouseActive = false;
|
|
|
|
|
|
|
|
|
|
internal WaitToLoadMenu()
|
|
|
|
|
{
|
2020-06-21 06:11:25 +12:00
|
|
|
|
timerStartLoad.Interval = 200;
|
|
|
|
|
timerStartLoad.Tick += WaitStartLoad_Tick;
|
2020-06-21 03:38:21 +12:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
internal void MouseEnter(object sender, DataGridViewCellEventArgs e)
|
|
|
|
|
{
|
2020-06-21 06:11:25 +12:00
|
|
|
|
timerStartLoad.Stop();
|
2020-06-21 03:38:21 +12:00
|
|
|
|
StopLoadMenu.Invoke();
|
2020-06-21 06:11:25 +12:00
|
|
|
|
SetData((DataGridView)sender, e.RowIndex, MouseActive);
|
2020-06-21 03:38:21 +12:00
|
|
|
|
checkForMouseActive = true;
|
2020-06-21 06:11:25 +12:00
|
|
|
|
timerStartLoad.Start();
|
2020-06-21 03:38:21 +12:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
internal void RowSelected(DataGridView dgv, int rowIndex)
|
|
|
|
|
{
|
2020-06-21 06:11:25 +12:00
|
|
|
|
timerStartLoad.Stop();
|
2020-06-21 03:38:21 +12:00
|
|
|
|
StopLoadMenu.Invoke();
|
|
|
|
|
SetData(dgv, rowIndex);
|
2020-06-21 06:11:25 +12:00
|
|
|
|
MouseActive = false;
|
2020-06-21 03:38:21 +12:00
|
|
|
|
checkForMouseActive = false;
|
2020-06-21 06:11:25 +12:00
|
|
|
|
timerStartLoad.Start();
|
2020-06-21 03:38:21 +12:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
internal void MouseLeave(object sender, DataGridViewCellEventArgs e)
|
|
|
|
|
{
|
2020-06-21 06:11:25 +12:00
|
|
|
|
timerStartLoad.Stop();
|
2020-06-21 03:38:21 +12:00
|
|
|
|
StopLoadMenu.Invoke();
|
|
|
|
|
ResetData((DataGridView)sender, e.RowIndex);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
internal void RowDeselected(int iMenuBefore, int rowIndex, DataGridView dgv) //iMenuBefore not needed
|
|
|
|
|
{
|
2020-06-21 06:11:25 +12:00
|
|
|
|
timerStartLoad.Stop();
|
2020-06-21 03:38:21 +12:00
|
|
|
|
StopLoadMenu.Invoke();
|
|
|
|
|
ResetData(dgv, rowIndex);
|
2020-06-21 06:11:25 +12:00
|
|
|
|
MouseActive = false;
|
2020-06-21 03:38:21 +12:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
internal void ClickOpensInstantly(DataGridView dgv, int rowIndex)
|
|
|
|
|
{
|
2020-06-21 06:11:25 +12:00
|
|
|
|
timerStartLoad.Stop();
|
2020-06-21 03:38:21 +12:00
|
|
|
|
StopLoadMenu.Invoke();
|
|
|
|
|
SetData(dgv, rowIndex);
|
2020-06-21 06:11:25 +12:00
|
|
|
|
MouseActive = true;
|
2020-06-21 03:38:21 +12:00
|
|
|
|
checkForMouseActive = false;
|
|
|
|
|
CallOpenMenuNow();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
internal void EnterOpensInstantly(DataGridView dgv, int rowIndex)
|
|
|
|
|
{
|
2020-06-21 06:11:25 +12:00
|
|
|
|
timerStartLoad.Stop();
|
2020-06-21 03:38:21 +12:00
|
|
|
|
StopLoadMenu.Invoke();
|
|
|
|
|
SetData(dgv, rowIndex);
|
2020-06-21 06:11:25 +12:00
|
|
|
|
MouseActive = false;
|
2020-06-21 03:38:21 +12:00
|
|
|
|
checkForMouseActive = false;
|
|
|
|
|
CallOpenMenuNow();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
internal void MouseMove(object sender, MouseEventArgs e)
|
|
|
|
|
{
|
2020-06-21 06:11:25 +12:00
|
|
|
|
if (!MouseActive)
|
|
|
|
|
{
|
|
|
|
|
if (mouseMoveEvents > 3)
|
|
|
|
|
{
|
|
|
|
|
MouseActive = true;
|
|
|
|
|
mouseMoveEvents = 0;
|
|
|
|
|
}
|
|
|
|
|
else if (DateTime.Now - dateTimeLastMouseMoveEvent <
|
|
|
|
|
new TimeSpan(0, 0, 0, 0, 200))
|
|
|
|
|
{
|
|
|
|
|
mouseMoveEvents++;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
dateTimeLastMouseMoveEvent = DateTime.Now;
|
|
|
|
|
mouseMoveEvents = 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-06-21 03:38:21 +12:00
|
|
|
|
}
|
|
|
|
|
|
2020-06-21 06:11:25 +12:00
|
|
|
|
private void WaitStartLoad_Tick(object sender, EventArgs e)
|
2020-06-21 03:38:21 +12:00
|
|
|
|
{
|
2020-06-21 06:11:25 +12:00
|
|
|
|
timerStartLoad.Stop();
|
|
|
|
|
if (!checkForMouseActive || MouseActive)
|
2020-06-21 03:38:21 +12:00
|
|
|
|
{
|
|
|
|
|
CallOpenMenuNow();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void CallOpenMenuNow()
|
|
|
|
|
{
|
|
|
|
|
if (dgv.Rows.Count > rowIndex)
|
|
|
|
|
{
|
|
|
|
|
RowData rowData = (RowData)dgv.Rows[rowIndex].Cells[2].Value;
|
|
|
|
|
Menu menu = (Menu)dgv.FindForm();
|
|
|
|
|
rowData.MenuLevel = menu.Level;
|
|
|
|
|
if (!rowData.IsContextMenuOpen &&
|
|
|
|
|
rowData.ContainsMenu &&
|
2020-06-21 07:02:03 +12:00
|
|
|
|
rowData.MenuLevel + 1 < MenuDefines.MenusMax)
|
2020-06-21 03:38:21 +12:00
|
|
|
|
{
|
|
|
|
|
StartLoadMenu.Invoke(rowData);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-06-21 06:11:25 +12:00
|
|
|
|
private void SetData(DataGridView dgv, int rowIndex, bool select = true)
|
2020-06-21 03:38:21 +12:00
|
|
|
|
{
|
|
|
|
|
this.dgv = dgv;
|
|
|
|
|
this.rowIndex = rowIndex;
|
|
|
|
|
RowData rowData = (RowData)dgv.Rows[rowIndex].Cells[2].Value;
|
2020-06-21 06:11:25 +12:00
|
|
|
|
if (select)
|
|
|
|
|
{
|
|
|
|
|
rowData.IsSelected = true;
|
|
|
|
|
dgv.Rows[rowIndex].Selected = true;
|
|
|
|
|
}
|
2020-06-21 03:38:21 +12:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void ResetData(DataGridView dgv, int rowIndex)
|
|
|
|
|
{
|
|
|
|
|
if (dgv != null)
|
|
|
|
|
{
|
|
|
|
|
RowData rowData = (RowData)dgv.Rows[rowIndex].Cells[2].Value;
|
|
|
|
|
rowData.IsSelected = false;
|
|
|
|
|
dgv.Rows[rowIndex].Selected = false;
|
|
|
|
|
this.dgv = null;
|
|
|
|
|
this.rowIndex = 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Dispose()
|
|
|
|
|
{
|
2020-06-21 06:11:25 +12:00
|
|
|
|
timerStartLoad.Stop();
|
|
|
|
|
timerStartLoad.Dispose();
|
2020-06-21 03:38:21 +12:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|