2020-07-07 09:37:55 +12:00
|
|
|
|
// <copyright file="Menus.cs" company="PlaceholderCompany">
|
|
|
|
|
// Copyright (c) PlaceholderCompany. All rights reserved.
|
|
|
|
|
// </copyright>
|
|
|
|
|
|
2020-04-30 23:22:47 +12:00
|
|
|
|
namespace SystemTrayMenu.Business
|
|
|
|
|
{
|
2020-07-07 07:15:45 +12:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.ComponentModel;
|
|
|
|
|
using System.Data;
|
|
|
|
|
using System.Diagnostics;
|
|
|
|
|
using System.Drawing;
|
|
|
|
|
using System.IO;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Security;
|
|
|
|
|
using System.Windows.Forms;
|
|
|
|
|
using SystemTrayMenu.DataClasses;
|
|
|
|
|
using SystemTrayMenu.Handler;
|
|
|
|
|
using SystemTrayMenu.Helper;
|
|
|
|
|
using SystemTrayMenu.Utilities;
|
|
|
|
|
using Menu = SystemTrayMenu.UserInterface.Menu;
|
|
|
|
|
using Timer = System.Windows.Forms.Timer;
|
|
|
|
|
|
2020-04-30 23:22:47 +12:00
|
|
|
|
internal class Menus : IDisposable
|
|
|
|
|
{
|
|
|
|
|
private readonly Menu[] menus = new Menu[MenuDefines.MenusMax];
|
2020-06-21 03:38:21 +12:00
|
|
|
|
private readonly BackgroundWorker workerMainMenu = new BackgroundWorker();
|
|
|
|
|
private readonly List<BackgroundWorker> workersSubMenu = new List<BackgroundWorker>();
|
2020-04-30 23:22:47 +12:00
|
|
|
|
|
2020-07-07 09:37:55 +12:00
|
|
|
|
private readonly int screenHeight = Screen.PrimaryScreen.Bounds.Height;
|
|
|
|
|
private readonly int screenWidth = Screen.PrimaryScreen.Bounds.Width;
|
|
|
|
|
private readonly int screenRight = Screen.PrimaryScreen.Bounds.Right;
|
|
|
|
|
private readonly int taskbarHeight = new WindowsTaskbar().Size.Height;
|
|
|
|
|
|
2020-07-13 00:21:29 +12:00
|
|
|
|
private readonly DgvMouseRow dgvMouseRow = new DgvMouseRow();
|
2020-06-21 03:38:21 +12:00
|
|
|
|
private readonly WaitToLoadMenu waitToOpenMenu = new WaitToLoadMenu();
|
2020-07-04 08:02:16 +12:00
|
|
|
|
private readonly KeyboardInput keyboardInput = null;
|
2020-04-30 23:22:47 +12:00
|
|
|
|
private readonly Timer timerStillActiveCheck = new Timer();
|
|
|
|
|
private readonly WaitLeave waitLeave = new WaitLeave(MenuDefines.TimeUntilClose);
|
|
|
|
|
private DateTime deactivatedTime = DateTime.MinValue;
|
2020-07-07 09:37:55 +12:00
|
|
|
|
private OpenCloseState openCloseState = OpenCloseState.Default;
|
2020-07-09 03:54:19 +12:00
|
|
|
|
private RowData loadingRowData = null;
|
|
|
|
|
private bool showingMessageBox = false;
|
2020-07-04 08:02:16 +12:00
|
|
|
|
|
2020-04-30 23:22:47 +12:00
|
|
|
|
public Menus()
|
|
|
|
|
{
|
2020-06-21 03:38:21 +12:00
|
|
|
|
workerMainMenu.WorkerSupportsCancellation = true;
|
|
|
|
|
workerMainMenu.DoWork += LoadMenu;
|
2020-07-07 02:46:47 +12:00
|
|
|
|
static void LoadMenu(object senderDoWork, DoWorkEventArgs eDoWork)
|
2020-04-30 23:22:47 +12:00
|
|
|
|
{
|
2020-06-21 03:38:21 +12:00
|
|
|
|
string path = Config.Path;
|
|
|
|
|
int level = 0;
|
|
|
|
|
RowData rowData = eDoWork.Argument as RowData;
|
|
|
|
|
if (rowData != null)
|
|
|
|
|
{
|
|
|
|
|
path = rowData.TargetFilePath;
|
|
|
|
|
level = rowData.MenuLevel + 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
MenuData menuData = GetData((BackgroundWorker)senderDoWork, path, level);
|
|
|
|
|
menuData.RowDataParent = rowData;
|
|
|
|
|
eDoWork.Result = menuData;
|
2020-04-30 23:22:47 +12:00
|
|
|
|
}
|
|
|
|
|
|
2020-06-21 03:38:21 +12:00
|
|
|
|
workerMainMenu.RunWorkerCompleted += LoadMainMenuCompleted;
|
|
|
|
|
void LoadMainMenuCompleted(object sender, RunWorkerCompletedEventArgs e)
|
2020-04-30 23:22:47 +12:00
|
|
|
|
{
|
|
|
|
|
keyboardInput.ResetSelectedByKey();
|
|
|
|
|
LoadStopped();
|
|
|
|
|
MenuData menuData = (MenuData)e.Result;
|
2020-07-09 03:54:19 +12:00
|
|
|
|
switch (menuData.Validity)
|
2020-04-30 23:22:47 +12:00
|
|
|
|
{
|
2020-07-09 03:54:19 +12:00
|
|
|
|
case MenuDataValidity.Valid:
|
|
|
|
|
DisposeMenu(menus[menuData.Level]);
|
|
|
|
|
menus[0] = Create(menuData, Path.GetFileName(Config.Path));
|
|
|
|
|
AsEnumerable.ToList().ForEach(m => { m.ShowWithFade(); });
|
|
|
|
|
break;
|
|
|
|
|
case MenuDataValidity.Empty:
|
|
|
|
|
if (!showingMessageBox)
|
|
|
|
|
{
|
|
|
|
|
showingMessageBox = true;
|
|
|
|
|
MessageBox.Show(Translator.GetText(
|
|
|
|
|
"MessageRootFolderEmpty"));
|
|
|
|
|
OpenFolder();
|
|
|
|
|
showingMessageBox = false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
case MenuDataValidity.NoAccess:
|
|
|
|
|
if (!showingMessageBox)
|
|
|
|
|
{
|
|
|
|
|
showingMessageBox = true;
|
|
|
|
|
MessageBox.Show(Translator.GetText(
|
|
|
|
|
"MessageRootFolderNoAccess"));
|
|
|
|
|
OpenFolder();
|
|
|
|
|
showingMessageBox = false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
case MenuDataValidity.AbortedOrUnknown:
|
|
|
|
|
Log.Info("MenuDataValidity.AbortedOrUnknown");
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
break;
|
2020-04-30 23:22:47 +12:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-06-21 03:38:21 +12:00
|
|
|
|
waitToOpenMenu.StopLoadMenu += WaitToOpenMenu_StopLoadMenu;
|
|
|
|
|
void WaitToOpenMenu_StopLoadMenu()
|
|
|
|
|
{
|
|
|
|
|
foreach (BackgroundWorker workerSubMenu in workersSubMenu.
|
|
|
|
|
Where(w => w.IsBusy))
|
|
|
|
|
{
|
|
|
|
|
workerSubMenu.CancelAsync();
|
|
|
|
|
}
|
2020-07-12 03:57:14 +12:00
|
|
|
|
|
|
|
|
|
LoadStopped();
|
2020-06-21 03:38:21 +12:00
|
|
|
|
}
|
2020-06-23 03:52:19 +12:00
|
|
|
|
|
2020-06-21 03:38:21 +12:00
|
|
|
|
waitToOpenMenu.StartLoadMenu += StartLoadMenu;
|
|
|
|
|
void StartLoadMenu(RowData rowData)
|
|
|
|
|
{
|
|
|
|
|
if (menus[0].IsUsable &&
|
2020-07-09 03:54:19 +12:00
|
|
|
|
loadingRowData != rowData &&
|
2020-06-27 22:37:52 +12:00
|
|
|
|
(menus[rowData.MenuLevel + 1] == null ||
|
|
|
|
|
menus[rowData.MenuLevel + 1].Tag as RowData != rowData))
|
2020-06-21 03:38:21 +12:00
|
|
|
|
{
|
2020-07-09 03:54:19 +12:00
|
|
|
|
loadingRowData = rowData;
|
2020-06-21 03:38:21 +12:00
|
|
|
|
LoadStarted();
|
|
|
|
|
BackgroundWorker workerSubMenu = workersSubMenu.
|
|
|
|
|
Where(w => !w.IsBusy).FirstOrDefault();
|
|
|
|
|
if (workerSubMenu == null)
|
|
|
|
|
{
|
|
|
|
|
workerSubMenu = new BackgroundWorker
|
|
|
|
|
{
|
2020-07-07 07:15:45 +12:00
|
|
|
|
WorkerSupportsCancellation = true,
|
2020-06-21 03:38:21 +12:00
|
|
|
|
};
|
|
|
|
|
workerSubMenu.DoWork += LoadMenu;
|
|
|
|
|
workerSubMenu.RunWorkerCompleted += LoadSubMenuCompleted;
|
|
|
|
|
workersSubMenu.Add(workerSubMenu);
|
|
|
|
|
}
|
2020-07-07 07:15:45 +12:00
|
|
|
|
|
2020-07-07 09:37:55 +12:00
|
|
|
|
workerSubMenu.RunWorkerAsync(rowData);
|
2020-06-21 03:38:21 +12:00
|
|
|
|
}
|
|
|
|
|
|
2020-07-07 09:37:55 +12:00
|
|
|
|
void LoadSubMenuCompleted(object senderCompleted, RunWorkerCompletedEventArgs e)
|
2020-06-21 03:38:21 +12:00
|
|
|
|
{
|
|
|
|
|
LoadStopped();
|
|
|
|
|
MenuData menuData = (MenuData)e.Result;
|
|
|
|
|
if (menus[0].IsUsable &&
|
|
|
|
|
menuData.Validity != MenuDataValidity.AbortedOrUnknown)
|
|
|
|
|
{
|
|
|
|
|
Menu menu = Create(menuData);
|
|
|
|
|
switch (menuData.Validity)
|
|
|
|
|
{
|
|
|
|
|
case MenuDataValidity.Valid:
|
|
|
|
|
menu.SetTypeSub();
|
|
|
|
|
break;
|
|
|
|
|
case MenuDataValidity.Empty:
|
|
|
|
|
menu.SetTypeEmpty();
|
|
|
|
|
break;
|
|
|
|
|
case MenuDataValidity.NoAccess:
|
|
|
|
|
menu.SetTypeNoAccess();
|
|
|
|
|
break;
|
|
|
|
|
}
|
2020-07-07 07:15:45 +12:00
|
|
|
|
|
2020-06-21 03:38:21 +12:00
|
|
|
|
menu.Tag = menuData.RowDataParent;
|
|
|
|
|
menuData.RowDataParent.SubMenu = menu;
|
|
|
|
|
if (menus[0].IsUsable)
|
|
|
|
|
{
|
|
|
|
|
ShowSubMenu(menu);
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-07-09 03:54:19 +12:00
|
|
|
|
|
|
|
|
|
loadingRowData = null;
|
2020-06-21 03:38:21 +12:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-06-26 06:28:36 +12:00
|
|
|
|
waitToOpenMenu.CloseMenu += CloseMenu;
|
|
|
|
|
void CloseMenu(int level)
|
|
|
|
|
{
|
|
|
|
|
if (menus[level] != null)
|
|
|
|
|
{
|
|
|
|
|
menus[level - 1].FocusTextBox();
|
|
|
|
|
HideOldMenu(menus[level]);
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-06-27 21:01:12 +12:00
|
|
|
|
|
2020-07-13 00:21:29 +12:00
|
|
|
|
waitToOpenMenu.MouseEnterOk += MouseEnterOk;
|
|
|
|
|
void MouseEnterOk(DataGridView dgv, int rowIndex)
|
|
|
|
|
{
|
|
|
|
|
if (menus[0].IsUsable)
|
|
|
|
|
{
|
|
|
|
|
if (keyboardInput.InUse)
|
|
|
|
|
{
|
|
|
|
|
keyboardInput.ClearIsSelectedByKey();
|
|
|
|
|
keyboardInput.InUse = false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
keyboardInput.Select(dgv, rowIndex, false);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
dgvMouseRow.RowMouseEnter += waitToOpenMenu.MouseEnter;
|
|
|
|
|
dgvMouseRow.RowMouseLeave += waitToOpenMenu.MouseLeave;
|
|
|
|
|
|
2020-04-30 23:22:47 +12:00
|
|
|
|
keyboardInput = new KeyboardInput(menus);
|
|
|
|
|
keyboardInput.RegisterHotKey();
|
2020-05-01 22:41:35 +12:00
|
|
|
|
keyboardInput.HotKeyPressed += KeyboardInput_HotKeyPressed;
|
2020-05-14 05:14:51 +12:00
|
|
|
|
void KeyboardInput_HotKeyPressed()
|
|
|
|
|
{
|
|
|
|
|
SwitchOpenClose(false);
|
|
|
|
|
}
|
|
|
|
|
|
2020-04-30 23:22:47 +12:00
|
|
|
|
keyboardInput.ClosePressed += MenusFadeOut;
|
2020-06-21 03:38:21 +12:00
|
|
|
|
keyboardInput.RowDeselected += waitToOpenMenu.RowDeselected;
|
|
|
|
|
keyboardInput.RowSelected += waitToOpenMenu.RowSelected;
|
2020-06-28 01:50:36 +12:00
|
|
|
|
keyboardInput.EnterPressed += waitToOpenMenu.EnterOpensInstantly;
|
2020-06-21 03:38:21 +12:00
|
|
|
|
|
|
|
|
|
timerStillActiveCheck.Interval = 1000;
|
|
|
|
|
timerStillActiveCheck.Tick += StillActiveTick;
|
|
|
|
|
void StillActiveTick(object senderTimer, EventArgs eTimer)
|
2020-04-30 23:22:47 +12:00
|
|
|
|
{
|
2020-06-21 03:38:21 +12:00
|
|
|
|
if (!IsActive())
|
|
|
|
|
{
|
|
|
|
|
FadeHalfOrOutIfNeeded();
|
|
|
|
|
timerStillActiveCheck.Stop();
|
|
|
|
|
}
|
2020-04-30 23:22:47 +12:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
waitLeave.LeaveTriggered += LeaveTriggered;
|
2020-05-14 05:14:51 +12:00
|
|
|
|
void LeaveTriggered()
|
|
|
|
|
{
|
|
|
|
|
FadeHalfOrOutIfNeeded();
|
|
|
|
|
}
|
2020-04-30 23:22:47 +12:00
|
|
|
|
}
|
|
|
|
|
|
2020-07-07 09:37:55 +12:00
|
|
|
|
internal event EventHandlerEmpty LoadStarted;
|
|
|
|
|
|
|
|
|
|
internal event EventHandlerEmpty LoadStopped;
|
|
|
|
|
|
|
|
|
|
private enum OpenCloseState
|
|
|
|
|
{
|
|
|
|
|
Default,
|
|
|
|
|
Opening,
|
|
|
|
|
Closing,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private IEnumerable<Menu> AsEnumerable => menus.Where(m => m != null && !m.IsDisposed);
|
|
|
|
|
|
|
|
|
|
private List<Menu> AsList => AsEnumerable.ToList();
|
|
|
|
|
|
2020-04-30 23:22:47 +12:00
|
|
|
|
public void Dispose()
|
|
|
|
|
{
|
2020-06-21 03:38:21 +12:00
|
|
|
|
workerMainMenu.Dispose();
|
2020-06-21 10:30:43 +12:00
|
|
|
|
foreach (BackgroundWorker worker in workersSubMenu)
|
|
|
|
|
{
|
|
|
|
|
worker.Dispose();
|
|
|
|
|
}
|
2020-07-07 07:15:45 +12:00
|
|
|
|
|
2020-07-04 08:02:16 +12:00
|
|
|
|
waitToOpenMenu.Dispose();
|
2020-04-30 23:22:47 +12:00
|
|
|
|
keyboardInput.Dispose();
|
|
|
|
|
timerStillActiveCheck.Dispose();
|
2020-07-04 08:02:16 +12:00
|
|
|
|
waitLeave.Dispose();
|
2020-04-30 23:22:47 +12:00
|
|
|
|
IconReader.Dispose();
|
|
|
|
|
DisposeMenu(menus[0]);
|
2020-07-12 03:57:14 +12:00
|
|
|
|
loadingRowData?.Dispose();
|
2020-07-13 00:21:29 +12:00
|
|
|
|
dgvMouseRow.Dispose();
|
2020-04-30 23:22:47 +12:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
internal static MenuData GetData(BackgroundWorker worker, string path, int level)
|
|
|
|
|
{
|
|
|
|
|
MenuData menuData = new MenuData
|
|
|
|
|
{
|
|
|
|
|
RowDatas = new List<RowData>(),
|
2020-06-21 03:38:21 +12:00
|
|
|
|
Validity = MenuDataValidity.AbortedOrUnknown,
|
2020-07-07 07:15:45 +12:00
|
|
|
|
Level = level,
|
2020-04-30 23:22:47 +12:00
|
|
|
|
};
|
|
|
|
|
if (!worker.CancellationPending)
|
|
|
|
|
{
|
|
|
|
|
string[] directories = Array.Empty<string>();
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
2020-07-07 07:15:45 +12:00
|
|
|
|
if (FileLnk.IsNetworkRoot(path))
|
2020-07-05 07:20:56 +12:00
|
|
|
|
{
|
|
|
|
|
directories = GetDirectoriesInNetworkLocation(path);
|
|
|
|
|
static string[] GetDirectoriesInNetworkLocation(string networkLocationRootPath)
|
|
|
|
|
{
|
2020-07-09 03:54:19 +12:00
|
|
|
|
List<string> directories = new List<string>();
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
Process cmd = new Process();
|
|
|
|
|
cmd.StartInfo.FileName = "cmd.exe";
|
|
|
|
|
cmd.StartInfo.RedirectStandardInput = true;
|
|
|
|
|
cmd.StartInfo.RedirectStandardOutput = true;
|
|
|
|
|
cmd.StartInfo.CreateNoWindow = true;
|
|
|
|
|
cmd.StartInfo.UseShellExecute = false;
|
|
|
|
|
cmd.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
|
|
|
|
|
cmd.Start();
|
|
|
|
|
cmd.StandardInput.WriteLine($"net view {networkLocationRootPath}");
|
|
|
|
|
cmd.StandardInput.Flush();
|
|
|
|
|
cmd.StandardInput.Close();
|
|
|
|
|
|
|
|
|
|
string output = cmd.StandardOutput.ReadToEnd();
|
|
|
|
|
|
|
|
|
|
cmd.WaitForExit();
|
|
|
|
|
cmd.Close();
|
|
|
|
|
|
|
|
|
|
output = output.Substring(output.LastIndexOf('-') + 2);
|
|
|
|
|
output = output.Substring(0, output.IndexOf("The command completed successfully.", StringComparison.InvariantCulture));
|
|
|
|
|
|
|
|
|
|
foreach (string line in output
|
|
|
|
|
.Split(new[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries))
|
|
|
|
|
{
|
|
|
|
|
int indexOfSecondColumnTypeDisk = line.IndexOf("Disk", StringComparison.InvariantCulture);
|
|
|
|
|
if (indexOfSecondColumnTypeDisk > 0)
|
|
|
|
|
{
|
|
|
|
|
string directory = Path.Combine(
|
|
|
|
|
networkLocationRootPath,
|
|
|
|
|
line.Substring(0, indexOfSecondColumnTypeDisk));
|
|
|
|
|
directories.Add(directory);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (ArgumentOutOfRangeException ex)
|
|
|
|
|
{
|
|
|
|
|
Log.Warn($"Could not resolve network root folder: {networkLocationRootPath}", ex);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return directories.ToArray();
|
2020-07-05 07:20:56 +12:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
directories = Directory.GetDirectories(path);
|
|
|
|
|
}
|
2020-07-07 07:15:45 +12:00
|
|
|
|
|
2020-04-30 23:22:47 +12:00
|
|
|
|
Array.Sort(directories, new WindowsExplorerSort());
|
|
|
|
|
}
|
|
|
|
|
catch (UnauthorizedAccessException ex)
|
|
|
|
|
{
|
|
|
|
|
Log.Warn($"path:'{path}'", ex);
|
|
|
|
|
menuData.Validity = MenuDataValidity.NoAccess;
|
|
|
|
|
}
|
|
|
|
|
catch (IOException ex)
|
|
|
|
|
{
|
|
|
|
|
Log.Warn($"path:'{path}'", ex);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
foreach (string directory in directories)
|
|
|
|
|
{
|
|
|
|
|
if (worker != null && worker.CancellationPending)
|
|
|
|
|
{
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool hiddenEntry = false;
|
|
|
|
|
if (FolderOptions.IsHidden(directory, ref hiddenEntry))
|
|
|
|
|
{
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
RowData rowData = ReadRowData(directory, false);
|
|
|
|
|
rowData.ContainsMenu = true;
|
|
|
|
|
rowData.HiddenEntry = hiddenEntry;
|
|
|
|
|
string resolvedLnkPath = string.Empty;
|
|
|
|
|
rowData.ReadIcon(true, ref resolvedLnkPath);
|
2020-06-21 03:38:21 +12:00
|
|
|
|
rowData.MenuLevel = level;
|
2020-04-30 23:22:47 +12:00
|
|
|
|
menuData.RowDatas.Add(rowData);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!worker.CancellationPending)
|
|
|
|
|
{
|
|
|
|
|
string[] files = Array.Empty<string>();
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
2020-07-07 07:15:45 +12:00
|
|
|
|
if (!FileLnk.IsNetworkRoot(path))
|
2020-07-05 07:20:56 +12:00
|
|
|
|
{
|
|
|
|
|
files = Directory.GetFiles(path);
|
|
|
|
|
}
|
2020-07-07 07:15:45 +12:00
|
|
|
|
|
2020-04-30 23:22:47 +12:00
|
|
|
|
Array.Sort(files, new WindowsExplorerSort());
|
|
|
|
|
}
|
|
|
|
|
catch (UnauthorizedAccessException ex)
|
|
|
|
|
{
|
|
|
|
|
Log.Warn($"path:'{path}'", ex);
|
|
|
|
|
menuData.Validity = MenuDataValidity.NoAccess;
|
|
|
|
|
}
|
|
|
|
|
catch (IOException ex)
|
|
|
|
|
{
|
|
|
|
|
Log.Warn($"path:'{path}'", ex);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
foreach (string file in files)
|
|
|
|
|
{
|
|
|
|
|
if (worker != null && worker.CancellationPending)
|
|
|
|
|
{
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool hiddenEntry = false;
|
|
|
|
|
if (FolderOptions.IsHidden(file, ref hiddenEntry))
|
|
|
|
|
{
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
RowData rowData = ReadRowData(file, false);
|
|
|
|
|
string resolvedLnkPath = string.Empty;
|
|
|
|
|
if (rowData.ReadIcon(false, ref resolvedLnkPath))
|
|
|
|
|
{
|
|
|
|
|
rowData = ReadRowData(resolvedLnkPath, true, rowData);
|
|
|
|
|
rowData.ContainsMenu = true;
|
|
|
|
|
rowData.HiddenEntry = hiddenEntry;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
menuData.RowDatas.Add(rowData);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!worker.CancellationPending)
|
|
|
|
|
{
|
2020-06-21 03:38:21 +12:00
|
|
|
|
if (menuData.Validity == MenuDataValidity.AbortedOrUnknown)
|
2020-04-30 23:22:47 +12:00
|
|
|
|
{
|
2020-06-21 03:38:21 +12:00
|
|
|
|
if (menuData.RowDatas.Count == 0)
|
|
|
|
|
{
|
|
|
|
|
menuData.Validity = MenuDataValidity.Empty;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
menuData.Validity = MenuDataValidity.Valid;
|
|
|
|
|
}
|
2020-04-30 23:22:47 +12:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return menuData;
|
|
|
|
|
}
|
|
|
|
|
|
2020-07-08 03:05:19 +12:00
|
|
|
|
internal void SwitchOpenCloseByTaskbarItem()
|
|
|
|
|
{
|
|
|
|
|
SwitchOpenClose(true);
|
|
|
|
|
timerStillActiveCheck.Start();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
internal void SwitchOpenClose(bool byClick)
|
|
|
|
|
{
|
|
|
|
|
waitToOpenMenu.MouseActive = byClick;
|
|
|
|
|
if (byClick && (DateTime.Now - deactivatedTime).TotalMilliseconds < 200)
|
|
|
|
|
{
|
|
|
|
|
// By click on notifyicon the menu gets deactivated and closed
|
|
|
|
|
}
|
|
|
|
|
else if (string.IsNullOrEmpty(Config.Path))
|
|
|
|
|
{
|
|
|
|
|
// Case when Folder Dialog open
|
|
|
|
|
}
|
|
|
|
|
else if (openCloseState == OpenCloseState.Opening ||
|
2020-08-04 20:58:20 +12:00
|
|
|
|
(menus[0] != null && menus[0].Visible && openCloseState == OpenCloseState.Default))
|
2020-07-08 03:05:19 +12:00
|
|
|
|
{
|
|
|
|
|
openCloseState = OpenCloseState.Closing;
|
|
|
|
|
MenusFadeOut();
|
|
|
|
|
StopWorker();
|
|
|
|
|
if (!AsEnumerable.Any(m => m.Visible))
|
|
|
|
|
{
|
|
|
|
|
openCloseState = OpenCloseState.Default;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
openCloseState = OpenCloseState.Opening;
|
|
|
|
|
StartWorker();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
deactivatedTime = DateTime.MinValue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
internal void DisposeMenu(Menu menuToDispose)
|
|
|
|
|
{
|
|
|
|
|
if (menuToDispose != null)
|
|
|
|
|
{
|
|
|
|
|
menuToDispose.MouseWheel -= AdjustMenusSizeAndLocation;
|
|
|
|
|
menuToDispose.MouseLeave -= waitLeave.Start;
|
|
|
|
|
menuToDispose.MouseEnter -= waitLeave.Stop;
|
|
|
|
|
menuToDispose.KeyPress -= keyboardInput.KeyPress;
|
|
|
|
|
menuToDispose.CmdKeyProcessed -= keyboardInput.CmdKeyProcessed;
|
|
|
|
|
menuToDispose.SearchTextChanging -= keyboardInput.SearchTextChanging;
|
|
|
|
|
menuToDispose.SearchTextChanged -= Menu_SearchTextChanged;
|
|
|
|
|
DataGridView dgv = menuToDispose.GetDataGridView();
|
2020-07-13 00:21:29 +12:00
|
|
|
|
dgv.CellMouseEnter -= dgvMouseRow.CellMouseEnter;
|
|
|
|
|
dgv.CellMouseLeave -= dgvMouseRow.CellMouseLeave;
|
|
|
|
|
dgv.MouseLeave -= dgvMouseRow.MouseLeave;
|
2020-07-08 03:05:19 +12:00
|
|
|
|
dgv.MouseMove -= waitToOpenMenu.MouseMove;
|
|
|
|
|
dgv.MouseDown -= Dgv_MouseDown;
|
|
|
|
|
dgv.MouseDoubleClick -= Dgv_MouseDoubleClick;
|
|
|
|
|
dgv.SelectionChanged -= Dgv_SelectionChanged;
|
|
|
|
|
dgv.RowPostPaint -= Dgv_RowPostPaint;
|
|
|
|
|
dgv.ClearSelection();
|
|
|
|
|
|
|
|
|
|
foreach (DataGridViewRow row in dgv.Rows)
|
|
|
|
|
{
|
|
|
|
|
RowData rowData = (RowData)row.Cells[2].Value;
|
|
|
|
|
rowData.Dispose();
|
|
|
|
|
DisposeMenu(rowData.SubMenu);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
menuToDispose.Dispose();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-04-30 23:22:47 +12:00
|
|
|
|
internal void MainPreload()
|
|
|
|
|
{
|
2020-07-07 07:15:45 +12:00
|
|
|
|
menus[0] = Create(
|
|
|
|
|
GetData(workerMainMenu, Config.Path, 0),
|
2020-04-30 23:22:47 +12:00
|
|
|
|
Path.GetFileName(Config.Path));
|
2020-07-07 07:15:45 +12:00
|
|
|
|
menus[0].AdjustSizeAndLocation(screenHeight, screenRight, taskbarHeight);
|
2020-04-30 23:22:47 +12:00
|
|
|
|
DisposeMenu(menus[0]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
internal void StartWorker()
|
|
|
|
|
{
|
2020-06-21 03:38:21 +12:00
|
|
|
|
if (!workerMainMenu.IsBusy)
|
2020-04-30 23:22:47 +12:00
|
|
|
|
{
|
2020-06-21 03:38:21 +12:00
|
|
|
|
LoadStarted();
|
|
|
|
|
workerMainMenu.RunWorkerAsync(
|
|
|
|
|
new object[] { Config.Path, 0 });
|
2020-04-30 23:22:47 +12:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
internal void StopWorker()
|
|
|
|
|
{
|
2020-06-21 03:38:21 +12:00
|
|
|
|
if (workerMainMenu.IsBusy)
|
2020-04-30 23:22:47 +12:00
|
|
|
|
{
|
2020-06-21 03:38:21 +12:00
|
|
|
|
workerMainMenu.CancelAsync();
|
2020-04-30 23:22:47 +12:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-07-07 07:15:45 +12:00
|
|
|
|
private static RowData ReadRowData(string fileName, bool isResolvedLnk, RowData rowData = null)
|
2020-04-30 23:22:47 +12:00
|
|
|
|
{
|
|
|
|
|
if (rowData == null)
|
|
|
|
|
{
|
|
|
|
|
rowData = new RowData();
|
|
|
|
|
}
|
2020-07-07 07:15:45 +12:00
|
|
|
|
|
2020-04-30 23:22:47 +12:00
|
|
|
|
rowData.IsResolvedLnk = isResolvedLnk;
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
rowData.FileInfo = new FileInfo(fileName);
|
|
|
|
|
rowData.TargetFilePath = rowData.FileInfo.FullName;
|
|
|
|
|
if (!isResolvedLnk)
|
|
|
|
|
{
|
2020-07-05 07:20:56 +12:00
|
|
|
|
if (string.IsNullOrEmpty(rowData.FileInfo.Name))
|
|
|
|
|
{
|
|
|
|
|
string path = rowData.FileInfo.FullName;
|
|
|
|
|
int directoryNameBegin = path.LastIndexOf(@"\", StringComparison.InvariantCulture) + 1;
|
|
|
|
|
rowData.SetText(path.Substring(directoryNameBegin));
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
rowData.SetText(rowData.FileInfo.Name);
|
|
|
|
|
}
|
2020-07-07 07:15:45 +12:00
|
|
|
|
|
2020-04-30 23:22:47 +12:00
|
|
|
|
rowData.TargetFilePathOrig = rowData.FileInfo.FullName;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
if (ex is SecurityException ||
|
|
|
|
|
ex is ArgumentException ||
|
|
|
|
|
ex is UnauthorizedAccessException ||
|
|
|
|
|
ex is PathTooLongException ||
|
|
|
|
|
ex is NotSupportedException)
|
|
|
|
|
{
|
|
|
|
|
Log.Warn($"fileName:'{fileName}'", ex);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
throw;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return rowData;
|
|
|
|
|
}
|
|
|
|
|
|
2020-07-08 03:05:19 +12:00
|
|
|
|
private static bool IsActive()
|
|
|
|
|
{
|
|
|
|
|
return Form.ActiveForm is Menu ||
|
|
|
|
|
Form.ActiveForm is UserInterface.TaskbarForm;
|
|
|
|
|
}
|
|
|
|
|
|
2020-07-09 03:54:19 +12:00
|
|
|
|
private static void OpenFolder()
|
|
|
|
|
{
|
2020-07-16 22:42:00 +12:00
|
|
|
|
Log.ProcessStart("explorer.exe", Config.Path, true);
|
2020-07-09 03:54:19 +12:00
|
|
|
|
}
|
|
|
|
|
|
2020-04-30 23:22:47 +12:00
|
|
|
|
private Menu Create(MenuData menuData, string title = null)
|
|
|
|
|
{
|
|
|
|
|
Menu menu = new Menu();
|
|
|
|
|
|
|
|
|
|
if (title != null)
|
|
|
|
|
{
|
|
|
|
|
if (string.IsNullOrEmpty(title))
|
|
|
|
|
{
|
|
|
|
|
title = Path.GetPathRoot(Config.Path);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
menu.SetTitle(title);
|
|
|
|
|
menu.UserClickedOpenFolder += OpenFolder;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
menu.Level = menuData.Level;
|
2020-05-06 12:39:38 +12:00
|
|
|
|
menu.MouseWheel += AdjustMenusSizeAndLocation;
|
2020-04-30 23:22:47 +12:00
|
|
|
|
menu.MouseLeave += waitLeave.Start;
|
|
|
|
|
menu.MouseEnter += waitLeave.Stop;
|
|
|
|
|
menu.KeyPress += keyboardInput.KeyPress;
|
|
|
|
|
menu.CmdKeyProcessed += keyboardInput.CmdKeyProcessed;
|
2020-05-14 05:14:51 +12:00
|
|
|
|
menu.SearchTextChanging += keyboardInput.SearchTextChanging;
|
|
|
|
|
menu.SearchTextChanged += Menu_SearchTextChanged;
|
2020-04-30 23:22:47 +12:00
|
|
|
|
menu.Deactivate += Deactivate;
|
|
|
|
|
void Deactivate(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
FadeHalfOrOutIfNeeded();
|
|
|
|
|
if (!IsActive())
|
|
|
|
|
{
|
|
|
|
|
deactivatedTime = DateTime.Now;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
menu.Activated += Activated;
|
|
|
|
|
void Activated(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (IsActive() &&
|
|
|
|
|
menus[0].IsUsable)
|
|
|
|
|
{
|
|
|
|
|
menus[0].SetTitleColorActive();
|
|
|
|
|
AsList.ForEach(m => m.ShowWithFade());
|
|
|
|
|
timerStillActiveCheck.Start();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
menu.VisibleChanged += MenuVisibleChanged;
|
|
|
|
|
AddItemsToMenu(menuData.RowDatas, menu);
|
2020-07-07 02:46:47 +12:00
|
|
|
|
static void AddItemsToMenu(List<RowData> data, Menu menu)
|
2020-06-21 03:38:21 +12:00
|
|
|
|
{
|
|
|
|
|
DataGridView dgv = menu.GetDataGridView();
|
|
|
|
|
DataTable dataTable = new DataTable();
|
|
|
|
|
dataTable.Columns.Add(dgv.Columns[0].Name, typeof(Icon));
|
|
|
|
|
dataTable.Columns.Add(dgv.Columns[1].Name, typeof(string));
|
|
|
|
|
dataTable.Columns.Add("data", typeof(RowData));
|
|
|
|
|
foreach (RowData rowData in data)
|
|
|
|
|
{
|
|
|
|
|
rowData.SetData(rowData, dataTable);
|
|
|
|
|
}
|
2020-07-07 07:15:45 +12:00
|
|
|
|
|
2020-06-21 03:38:21 +12:00
|
|
|
|
dgv.DataSource = dataTable;
|
|
|
|
|
}
|
2020-07-07 07:15:45 +12:00
|
|
|
|
|
2020-05-06 12:39:38 +12:00
|
|
|
|
DataGridView dgv = menu.GetDataGridView();
|
2020-07-13 00:21:29 +12:00
|
|
|
|
dgv.CellMouseEnter += dgvMouseRow.CellMouseEnter;
|
|
|
|
|
dgv.CellMouseLeave += dgvMouseRow.CellMouseLeave;
|
|
|
|
|
dgv.MouseLeave += dgvMouseRow.MouseLeave;
|
2020-06-21 03:38:21 +12:00
|
|
|
|
dgv.MouseMove += waitToOpenMenu.MouseMove;
|
2020-05-06 12:39:38 +12:00
|
|
|
|
dgv.MouseDown += Dgv_MouseDown;
|
|
|
|
|
dgv.MouseDoubleClick += Dgv_MouseDoubleClick;
|
|
|
|
|
dgv.SelectionChanged += Dgv_SelectionChanged;
|
2020-06-27 21:01:12 +12:00
|
|
|
|
dgv.RowPostPaint += Dgv_RowPostPaint;
|
2020-05-06 12:39:38 +12:00
|
|
|
|
|
2020-04-30 23:22:47 +12:00
|
|
|
|
return menu;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void MenuVisibleChanged(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
Menu menu = (Menu)sender;
|
|
|
|
|
if (menu.IsUsable)
|
|
|
|
|
{
|
2020-05-06 12:39:38 +12:00
|
|
|
|
AdjustMenusSizeAndLocation();
|
2020-04-30 23:22:47 +12:00
|
|
|
|
}
|
2020-07-07 07:15:45 +12:00
|
|
|
|
|
2020-04-30 23:22:47 +12:00
|
|
|
|
if (!menu.Visible)
|
|
|
|
|
{
|
|
|
|
|
DisposeMenu(menu);
|
|
|
|
|
}
|
2020-07-07 07:15:45 +12:00
|
|
|
|
|
2020-04-30 23:22:47 +12:00
|
|
|
|
if (!AsEnumerable.Any(m => m.Visible))
|
|
|
|
|
{
|
|
|
|
|
openCloseState = OpenCloseState.Default;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void Dgv_MouseDown(object sender, MouseEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
DataGridView dgv = (DataGridView)sender;
|
|
|
|
|
DataGridView.HitTestInfo hitTestInfo;
|
|
|
|
|
hitTestInfo = dgv.HitTest(e.X, e.Y);
|
|
|
|
|
if (hitTestInfo.RowIndex > -1 &&
|
|
|
|
|
dgv.Rows.Count > hitTestInfo.RowIndex)
|
|
|
|
|
{
|
2020-06-21 03:38:21 +12:00
|
|
|
|
RowData rowData = (RowData)dgv.Rows[hitTestInfo.RowIndex].Cells[2].Value;
|
|
|
|
|
rowData.MouseDown(dgv, e);
|
|
|
|
|
waitToOpenMenu.ClickOpensInstantly(dgv, hitTestInfo.RowIndex);
|
2020-04-30 23:22:47 +12:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void Dgv_MouseDoubleClick(object sender, MouseEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
DataGridView dgv = (DataGridView)sender;
|
|
|
|
|
DataGridView.HitTestInfo hitTestInfo;
|
|
|
|
|
hitTestInfo = dgv.HitTest(e.X, e.Y);
|
|
|
|
|
if (hitTestInfo.RowIndex > -1 &&
|
|
|
|
|
dgv.Rows.Count > hitTestInfo.RowIndex)
|
|
|
|
|
{
|
2020-05-14 05:14:51 +12:00
|
|
|
|
RowData trigger = (RowData)dgv.Rows[hitTestInfo.RowIndex].Cells[2].Value;
|
2020-05-09 01:57:30 +12:00
|
|
|
|
trigger.DoubleClick(e);
|
2020-04-30 23:22:47 +12:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void Dgv_SelectionChanged(object sender, EventArgs e)
|
|
|
|
|
{
|
2020-06-21 03:38:21 +12:00
|
|
|
|
RefreshSelection((DataGridView)sender);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void RefreshSelection(DataGridView dgv)
|
|
|
|
|
{
|
2020-04-30 23:22:47 +12:00
|
|
|
|
foreach (DataGridViewRow row in dgv.Rows)
|
|
|
|
|
{
|
2020-05-14 05:14:51 +12:00
|
|
|
|
RowData rowData = (RowData)row.Cells[2].Value;
|
2020-04-30 23:22:47 +12:00
|
|
|
|
|
2020-06-29 01:35:04 +12:00
|
|
|
|
if (rowData == null)
|
|
|
|
|
{
|
2020-07-07 07:15:45 +12:00
|
|
|
|
// Case when filtering a previous menu
|
2020-06-29 01:35:04 +12:00
|
|
|
|
}
|
|
|
|
|
else if (!menus[0].IsUsable)
|
2020-04-30 23:22:47 +12:00
|
|
|
|
{
|
|
|
|
|
row.DefaultCellStyle.SelectionBackColor = Color.White;
|
2020-06-21 03:38:21 +12:00
|
|
|
|
row.Selected = false;
|
2020-04-30 23:22:47 +12:00
|
|
|
|
}
|
2020-07-09 03:54:19 +12:00
|
|
|
|
else if (rowData.IsContextMenuOpen || (rowData.IsMenuOpen && rowData.IsSelected))
|
2020-06-25 03:44:30 +12:00
|
|
|
|
{
|
|
|
|
|
row.Selected = true;
|
|
|
|
|
}
|
2020-06-23 03:52:19 +12:00
|
|
|
|
else if (rowData.IsMenuOpen)
|
2020-04-30 23:22:47 +12:00
|
|
|
|
{
|
|
|
|
|
row.Selected = true;
|
|
|
|
|
}
|
2020-06-23 03:52:19 +12:00
|
|
|
|
else if (rowData.IsSelected)
|
2020-04-30 23:22:47 +12:00
|
|
|
|
{
|
2020-06-27 21:01:12 +12:00
|
|
|
|
row.DefaultCellStyle.SelectionBackColor = MenuDefines.ColorSelectedItem;
|
2020-04-30 23:22:47 +12:00
|
|
|
|
row.Selected = true;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2020-06-21 03:38:21 +12:00
|
|
|
|
row.DefaultCellStyle.SelectionBackColor = Color.White;
|
2020-04-30 23:22:47 +12:00
|
|
|
|
row.Selected = false;
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-07-07 07:15:45 +12:00
|
|
|
|
|
2020-06-27 21:01:12 +12:00
|
|
|
|
dgv.Refresh();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void Dgv_RowPostPaint(object sender, DataGridViewRowPostPaintEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
DataGridView dgv = (DataGridView)sender;
|
|
|
|
|
DataGridViewRow row = dgv.Rows[e.RowIndex];
|
|
|
|
|
|
|
|
|
|
if (row.Selected)
|
|
|
|
|
{
|
|
|
|
|
RowData rowData = (RowData)row.Cells[2].Value;
|
|
|
|
|
|
2020-07-07 07:15:45 +12:00
|
|
|
|
int width = dgv.Columns[0].Width + dgv.Columns[1].Width;
|
|
|
|
|
Rectangle rowBounds = new Rectangle(0, e.RowBounds.Top, width, e.RowBounds.Height);
|
2020-06-27 21:01:12 +12:00
|
|
|
|
|
2020-07-09 03:54:19 +12:00
|
|
|
|
if (rowData.IsContextMenuOpen || (rowData.IsMenuOpen && rowData.IsSelected))
|
2020-06-27 21:01:12 +12:00
|
|
|
|
{
|
2020-07-07 07:15:45 +12:00
|
|
|
|
ControlPaint.DrawBorder(e.Graphics, rowBounds, MenuDefines.ColorSelectedItemBorder, ButtonBorderStyle.Solid);
|
2020-06-27 21:01:12 +12:00
|
|
|
|
row.DefaultCellStyle.SelectionBackColor = MenuDefines.ColorSelectedItem;
|
|
|
|
|
}
|
|
|
|
|
else if (rowData.IsMenuOpen)
|
|
|
|
|
{
|
2020-07-07 07:15:45 +12:00
|
|
|
|
ControlPaint.DrawBorder(e.Graphics, rowBounds, MenuDefines.ColorOpenFolderBorder, ButtonBorderStyle.Solid);
|
2020-06-27 21:01:12 +12:00
|
|
|
|
row.DefaultCellStyle.SelectionBackColor = MenuDefines.ColorOpenFolder;
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-04-30 23:22:47 +12:00
|
|
|
|
}
|
|
|
|
|
|
2020-06-21 03:38:21 +12:00
|
|
|
|
private void ShowSubMenu(Menu menuToShow)
|
2020-06-26 06:28:36 +12:00
|
|
|
|
{
|
|
|
|
|
HideOldMenu(menuToShow, true);
|
|
|
|
|
|
|
|
|
|
menus[menuToShow.Level] = menuToShow;
|
|
|
|
|
AdjustMenusSizeAndLocation();
|
|
|
|
|
menus[menuToShow.Level].ShowWithFadeOrTransparent(IsActive());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void HideOldMenu(Menu menuToShow, bool keepOrSetIsMenuOpen = false)
|
2020-04-30 23:22:47 +12:00
|
|
|
|
{
|
2020-07-07 07:15:45 +12:00
|
|
|
|
// Clean up menu status IsMenuOpen for previous one
|
2020-06-21 03:38:21 +12:00
|
|
|
|
Menu menuPrevious = menus[menuToShow.Level - 1];
|
|
|
|
|
DataGridView dgvPrevious = menuPrevious.GetDataGridView();
|
|
|
|
|
foreach (DataRow row in ((DataTable)dgvPrevious.DataSource).Rows)
|
2020-04-30 23:22:47 +12:00
|
|
|
|
{
|
2020-06-21 03:38:21 +12:00
|
|
|
|
RowData rowDataToClear = (RowData)row[2];
|
|
|
|
|
if (rowDataToClear == (RowData)menuToShow.Tag)
|
2020-04-30 23:22:47 +12:00
|
|
|
|
{
|
2020-06-26 06:28:36 +12:00
|
|
|
|
rowDataToClear.IsMenuOpen = keepOrSetIsMenuOpen;
|
2020-04-30 23:22:47 +12:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2020-06-21 03:38:21 +12:00
|
|
|
|
rowDataToClear.IsMenuOpen = false;
|
2020-04-30 23:22:47 +12:00
|
|
|
|
}
|
|
|
|
|
}
|
2020-07-07 07:15:45 +12:00
|
|
|
|
|
2020-06-21 03:38:21 +12:00
|
|
|
|
RefreshSelection(dgvPrevious);
|
2020-04-30 23:22:47 +12:00
|
|
|
|
|
2020-07-07 07:15:45 +12:00
|
|
|
|
// Hide old menu
|
2020-06-21 03:38:21 +12:00
|
|
|
|
foreach (Menu menuToClose in menus.Where(
|
|
|
|
|
m => m != null && m.Level > menuPrevious.Level))
|
2020-04-30 23:22:47 +12:00
|
|
|
|
{
|
2020-06-21 03:38:21 +12:00
|
|
|
|
menuToClose.VisibleChanged += MenuVisibleChanged;
|
|
|
|
|
menuToClose.HideWithFade();
|
|
|
|
|
menus[menuToClose.Level] = null;
|
2020-04-30 23:22:47 +12:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-07-07 07:15:45 +12:00
|
|
|
|
private void FadeHalfOrOutIfNeeded()
|
2020-04-30 23:22:47 +12:00
|
|
|
|
{
|
|
|
|
|
if (menus[0].IsUsable)
|
|
|
|
|
{
|
2020-07-07 07:15:45 +12:00
|
|
|
|
if (!IsActive())
|
2020-04-30 23:22:47 +12:00
|
|
|
|
{
|
|
|
|
|
Point position = Control.MousePosition;
|
|
|
|
|
if (AsList.Any(m => m.IsMouseOn(position)))
|
|
|
|
|
{
|
|
|
|
|
if (!keyboardInput.InUse)
|
|
|
|
|
{
|
|
|
|
|
AsList.ForEach(menu => menu.ShowTransparent());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
MenusFadeOut();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void MenusFadeOut()
|
|
|
|
|
{
|
|
|
|
|
openCloseState = OpenCloseState.Closing;
|
|
|
|
|
AsList.ForEach(menu =>
|
|
|
|
|
{
|
|
|
|
|
if (menu.Level > 0)
|
|
|
|
|
{
|
|
|
|
|
menus[menu.Level] = null;
|
|
|
|
|
}
|
2020-07-07 07:15:45 +12:00
|
|
|
|
|
2020-04-30 23:22:47 +12:00
|
|
|
|
menu.HideWithFade();
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2020-05-06 12:39:38 +12:00
|
|
|
|
private void AdjustMenusSizeAndLocation()
|
2020-04-30 23:22:47 +12:00
|
|
|
|
{
|
|
|
|
|
Menu menuPredecessor = menus[0];
|
|
|
|
|
int widthPredecessors = -1; // -1 padding
|
|
|
|
|
bool directionToRight = false;
|
|
|
|
|
|
2020-07-07 07:15:45 +12:00
|
|
|
|
menus[0].AdjustSizeAndLocation(screenHeight, screenRight, taskbarHeight);
|
2020-05-06 12:39:38 +12:00
|
|
|
|
|
2020-04-30 23:22:47 +12:00
|
|
|
|
foreach (Menu menu in AsEnumerable.Where(m => m.Level > 0))
|
|
|
|
|
{
|
2020-07-07 07:15:45 +12:00
|
|
|
|
int newWith = menu.Width - menu.Padding.Horizontal + menuPredecessor.Width;
|
2020-04-30 23:22:47 +12:00
|
|
|
|
if (directionToRight)
|
|
|
|
|
{
|
2020-06-21 07:02:03 +12:00
|
|
|
|
if (widthPredecessors - menus[0].Width - menu.Width < 0)
|
2020-04-30 23:22:47 +12:00
|
|
|
|
{
|
|
|
|
|
directionToRight = false;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
widthPredecessors -= newWith;
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-07-04 08:02:16 +12:00
|
|
|
|
else if (screenWidth < widthPredecessors + menus[0].Width + menu.Width)
|
2020-04-30 23:22:47 +12:00
|
|
|
|
{
|
|
|
|
|
directionToRight = true;
|
|
|
|
|
widthPredecessors -= newWith;
|
|
|
|
|
}
|
|
|
|
|
|
2020-07-07 07:15:45 +12:00
|
|
|
|
menu.AdjustSizeAndLocation(screenHeight, screenRight, taskbarHeight, menuPredecessor, directionToRight);
|
2020-04-30 23:22:47 +12:00
|
|
|
|
widthPredecessors += menu.Width - menu.Padding.Left;
|
|
|
|
|
menuPredecessor = menu;
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-06-28 01:50:36 +12:00
|
|
|
|
|
|
|
|
|
private void Menu_SearchTextChanged(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
keyboardInput.SearchTextChanged(sender, e);
|
|
|
|
|
AdjustMenusSizeAndLocation();
|
|
|
|
|
}
|
2020-04-30 23:22:47 +12:00
|
|
|
|
}
|
|
|
|
|
}
|