2020-07-07 07:15:45 +12:00
|
|
|
|
// <copyright file="WaitToLoadMenu.cs" company="PlaceholderCompany">
|
|
|
|
|
// Copyright (c) PlaceholderCompany. All rights reserved.
|
|
|
|
|
// </copyright>
|
2020-06-21 03:38:21 +12:00
|
|
|
|
|
|
|
|
|
namespace SystemTrayMenu.Handler
|
|
|
|
|
{
|
2020-07-07 07:15:45 +12:00
|
|
|
|
using System;
|
|
|
|
|
using System.Windows.Forms;
|
|
|
|
|
using SystemTrayMenu.DataClasses;
|
|
|
|
|
using SystemTrayMenu.UserInterface;
|
|
|
|
|
using SystemTrayMenu.Utilities;
|
|
|
|
|
using Timer = System.Windows.Forms.Timer;
|
|
|
|
|
|
2020-06-21 03:38:21 +12:00
|
|
|
|
internal class WaitToLoadMenu : IDisposable
|
|
|
|
|
{
|
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-23 03:52:19 +12:00
|
|
|
|
private DataGridView dgvTmp = null;
|
|
|
|
|
private int rowIndexTmp = 0;
|
2020-06-21 03:38:21 +12:00
|
|
|
|
|
2020-06-21 06:11:25 +12:00
|
|
|
|
private int mouseMoveEvents = 0;
|
|
|
|
|
private DateTime dateTimeLastMouseMoveEvent = DateTime.Now;
|
2020-06-23 03:52:19 +12:00
|
|
|
|
private bool checkForMouseActive = true;
|
2020-06-21 03:38:21 +12:00
|
|
|
|
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
|
2020-07-07 09:37:55 +12:00
|
|
|
|
internal event Action<RowData> StartLoadMenu;
|
|
|
|
|
|
|
|
|
|
internal event Action<int> CloseMenu;
|
|
|
|
|
|
|
|
|
|
internal event EventHandlerEmpty StopLoadMenu;
|
|
|
|
|
|
|
|
|
|
internal event Action<DataGridView, int> MouseEnterOk;
|
|
|
|
|
|
2020-07-08 03:05:19 +12:00
|
|
|
|
internal bool MouseActive { get; set; } = false;
|
|
|
|
|
|
|
|
|
|
public void Dispose()
|
|
|
|
|
{
|
|
|
|
|
timerStartLoad.Stop();
|
|
|
|
|
timerStartLoad.Dispose();
|
|
|
|
|
dgv?.Dispose();
|
|
|
|
|
dgvTmp?.Dispose();
|
|
|
|
|
}
|
|
|
|
|
|
2020-06-21 03:38:21 +12:00
|
|
|
|
internal void MouseEnter(object sender, DataGridViewCellEventArgs e)
|
|
|
|
|
{
|
2020-06-23 03:52:19 +12:00
|
|
|
|
if (MouseActive)
|
|
|
|
|
{
|
|
|
|
|
DataGridView dgv = (DataGridView)sender;
|
|
|
|
|
MouseEnterOk(dgv, e.RowIndex);
|
|
|
|
|
timerStartLoad.Stop();
|
2020-06-29 06:56:03 +12:00
|
|
|
|
StopLoadMenu?.Invoke();
|
2020-06-23 03:52:19 +12:00
|
|
|
|
checkForMouseActive = true;
|
|
|
|
|
SetData(dgv, e.RowIndex);
|
|
|
|
|
timerStartLoad.Start();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2020-07-07 02:46:47 +12:00
|
|
|
|
dgvTmp = (DataGridView)sender;
|
|
|
|
|
rowIndexTmp = e.RowIndex;
|
2020-06-23 03:52:19 +12:00
|
|
|
|
}
|
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-29 06:56:03 +12:00
|
|
|
|
StopLoadMenu?.Invoke();
|
2020-06-21 03:38:21 +12:00
|
|
|
|
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-23 03:52:19 +12:00
|
|
|
|
if (MouseActive)
|
|
|
|
|
{
|
|
|
|
|
timerStartLoad.Stop();
|
2020-06-29 06:56:03 +12:00
|
|
|
|
StopLoadMenu?.Invoke();
|
2020-06-23 03:52:19 +12:00
|
|
|
|
ResetData((DataGridView)sender, e.RowIndex);
|
|
|
|
|
}
|
2020-06-21 03:38:21 +12:00
|
|
|
|
}
|
|
|
|
|
|
2020-07-07 07:15:45 +12:00
|
|
|
|
internal void RowDeselected(int rowIndex, DataGridView dgv)
|
2020-06-21 03:38:21 +12:00
|
|
|
|
{
|
2020-06-21 06:11:25 +12:00
|
|
|
|
timerStartLoad.Stop();
|
2020-06-29 06:56:03 +12:00
|
|
|
|
StopLoadMenu?.Invoke();
|
2020-06-21 03:38:21 +12:00
|
|
|
|
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-29 06:56:03 +12:00
|
|
|
|
StopLoadMenu?.Invoke();
|
2020-06-21 03:38:21 +12:00
|
|
|
|
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-23 07:52:35 +12:00
|
|
|
|
if (dgv.Rows.Count > rowIndex)
|
|
|
|
|
{
|
|
|
|
|
timerStartLoad.Stop();
|
2020-06-29 06:56:03 +12:00
|
|
|
|
StopLoadMenu?.Invoke();
|
2020-06-23 07:52:35 +12:00
|
|
|
|
SetData(dgv, rowIndex);
|
|
|
|
|
MouseActive = false;
|
|
|
|
|
checkForMouseActive = false;
|
|
|
|
|
CallOpenMenuNow();
|
|
|
|
|
}
|
2020-06-21 03:38:21 +12:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
internal void MouseMove(object sender, MouseEventArgs e)
|
|
|
|
|
{
|
2020-06-21 06:11:25 +12:00
|
|
|
|
if (!MouseActive)
|
|
|
|
|
{
|
|
|
|
|
if (mouseMoveEvents > 3)
|
|
|
|
|
{
|
|
|
|
|
MouseActive = true;
|
2020-06-23 03:52:19 +12:00
|
|
|
|
if (dgvTmp != null && !dgvTmp.IsDisposed)
|
|
|
|
|
{
|
|
|
|
|
MouseEnter(dgvTmp, new DataGridViewCellEventArgs(
|
|
|
|
|
0, rowIndexTmp));
|
|
|
|
|
}
|
2020-07-07 07:15:45 +12:00
|
|
|
|
|
2020-06-21 06:11:25 +12:00
|
|
|
|
mouseMoveEvents = 0;
|
|
|
|
|
}
|
2020-07-04 08:02:16 +12:00
|
|
|
|
else if (DateTime.Now - dateTimeLastMouseMoveEvent <
|
2020-06-21 06:11:25 +12:00
|
|
|
|
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;
|
2020-06-26 06:28:36 +12:00
|
|
|
|
if (rowData.ContainsMenu)
|
|
|
|
|
{
|
|
|
|
|
CloseMenu.Invoke(rowData.MenuLevel + 2);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
CloseMenu.Invoke(rowData.MenuLevel + 1);
|
|
|
|
|
}
|
|
|
|
|
|
2020-06-21 03:38:21 +12:00
|
|
|
|
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-23 03:52:19 +12:00
|
|
|
|
private void SetData(DataGridView dgv, int rowIndex)
|
2020-06-21 03:38:21 +12:00
|
|
|
|
{
|
2020-06-23 03:52:19 +12:00
|
|
|
|
dgvTmp = null;
|
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-23 03:52:19 +12:00
|
|
|
|
rowData.IsSelected = true;
|
2020-06-25 22:24:06 +12:00
|
|
|
|
dgv.Rows[rowIndex].Selected = false;
|
2020-06-23 03:52:19 +12:00
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|