diff --git a/Business/App.cs b/Business/App.cs
index dfedba3..a07201f 100644
--- a/Business/App.cs
+++ b/Business/App.cs
@@ -24,27 +24,20 @@ namespace SystemTrayMenu
public App()
{
AppRestart.BeforeRestarting += Dispose;
- SystemEvents.DisplaySettingsChanged += (s, e) => SystemEvents_DisplaySettingsChanged();
+ SystemEvents.DisplaySettingsChanged += SystemEvents_DisplaySettingsChanged;
menus.LoadStarted += menuNotifyIcon.LoadingStart;
menus.LoadStopped += menuNotifyIcon.LoadingStop;
- menuNotifyIcon.Click += () => menus.SwitchOpenClose(true);
+ menuNotifyIcon.Click += MenuNotifyIcon_Click;
menuNotifyIcon.OpenLog += Log.OpenLogFile;
menus.MainPreload();
if (Properties.Settings.Default.ShowInTaskbar)
{
taskbarForm = new TaskbarForm();
- taskbarForm.FormClosed += (s, e) => Application.Exit();
- taskbarForm.Deactivate += (s, e) => SetStateNormal();
- taskbarForm.Resize += (s, e) => SetStateNormal();
+ taskbarForm.FormClosed += TaskbarForm_FormClosed;
+ taskbarForm.Deactivate += SetStateNormal;
+ taskbarForm.Resize += SetStateNormal;
taskbarForm.Activated += TasbkarItemActivated;
- void TasbkarItemActivated(object sender, EventArgs e)
- {
- SetStateNormal();
- taskbarForm.Activate();
- taskbarForm.Focus();
- menus.SwitchOpenCloseByTaskbarItem();
- }
}
DllImports.NativeMethods.User32ShowInactiveTopmost(taskbarForm);
@@ -65,27 +58,57 @@ namespace SystemTrayMenu
}
else
{
- taskbarForm?.Dispose();
- SystemEvents.DisplaySettingsChanged -= (s, e) => SystemEvents_DisplaySettingsChanged();
+ AppRestart.BeforeRestarting -= Dispose;
+ SystemEvents.DisplaySettingsChanged -= SystemEvents_DisplaySettingsChanged;
+ menus.LoadStarted -= menuNotifyIcon.LoadingStart;
+ menus.LoadStopped -= menuNotifyIcon.LoadingStop;
menus.Dispose();
+ menuNotifyIcon.Click -= MenuNotifyIcon_Click;
+ menuNotifyIcon.OpenLog -= Log.OpenLogFile;
menuNotifyIcon.Dispose();
+ if (taskbarForm != null)
+ {
+ taskbarForm.FormClosed -= TaskbarForm_FormClosed;
+ taskbarForm.Deactivate -= SetStateNormal;
+ taskbarForm.Resize -= SetStateNormal;
+ taskbarForm.Activated -= TasbkarItemActivated;
+ taskbarForm.Dispose();
+ }
}
}
- private void SystemEvents_DisplaySettingsChanged()
+ private void SystemEvents_DisplaySettingsChanged(object sender, EventArgs e)
{
menus.ReAdjustSizeAndLocation();
}
+ private void MenuNotifyIcon_Click()
+ {
+ menus.SwitchOpenClose(true);
+ }
+
+ private void TaskbarForm_FormClosed(object sender, FormClosedEventArgs e)
+ {
+ Application.Exit();
+ }
+
///
/// This ensures that next click on taskbaritem works as activate event/click event.
///
- private void SetStateNormal()
+ private void SetStateNormal(object sender, EventArgs e)
{
if (Form.ActiveForm == taskbarForm)
{
taskbarForm.WindowState = FormWindowState.Normal;
}
}
+
+ private void TasbkarItemActivated(object sender, EventArgs e)
+ {
+ SetStateNormal(sender, e);
+ taskbarForm.Activate();
+ taskbarForm.Focus();
+ menus.SwitchOpenCloseByTaskbarItem();
+ }
}
}
\ No newline at end of file
diff --git a/Business/KeyboardInput.cs b/Business/KeyboardInput.cs
index 6c52848..bbc56ab 100644
--- a/Business/KeyboardInput.cs
+++ b/Business/KeyboardInput.cs
@@ -27,33 +27,34 @@ namespace SystemTrayMenu.Handler
this.menus = menus;
}
- internal event EventHandlerEmpty HotKeyPressed;
+ public event Action HotKeyPressed;
- internal event EventHandlerEmpty ClosePressed;
+ public event Action ClosePressed;
- internal event Action RowSelected;
+ public event Action RowSelected;
- internal event Action RowDeselected;
+ public event Action RowDeselected;
- internal event Action EnterPressed;
+ public event Action EnterPressed;
- internal event EventHandlerEmpty Cleared;
+ public event Action Cleared;
- internal bool InUse { get; set; }
+ public bool InUse { get; set; }
public void Dispose()
{
+ hook.KeyPressed -= Hook_KeyPressed;
hook.Dispose();
}
- internal void RegisterHotKey()
+ public void RegisterHotKey()
{
if (!string.IsNullOrEmpty(Properties.Settings.Default.HotKey))
{
try
{
hook.RegisterHotKey();
- hook.KeyPressed += (sender, e) => HotKeyPressed?.Invoke();
+ hook.KeyPressed += Hook_KeyPressed;
}
catch (InvalidOperationException ex)
{
@@ -64,13 +65,13 @@ namespace SystemTrayMenu.Handler
}
}
- internal void ResetSelectedByKey()
+ public void ResetSelectedByKey()
{
iRowKey = -1;
iMenuKey = 0;
}
- internal void CmdKeyProcessed(object sender, Keys keys)
+ public void CmdKeyProcessed(object sender, Keys keys)
{
sender ??= menus[iMenuKey];
@@ -171,12 +172,12 @@ namespace SystemTrayMenu.Handler
}
}
- internal void SearchTextChanging()
+ public void SearchTextChanging()
{
ClearIsSelectedByKey();
}
- internal void SearchTextChanged(Menu menu, bool isSearchStringEmpty)
+ public void SearchTextChanged(Menu menu, bool isSearchStringEmpty)
{
DataGridView dgv = menu.GetDataGridView();
if (isSearchStringEmpty)
@@ -189,12 +190,12 @@ namespace SystemTrayMenu.Handler
}
}
- internal void ClearIsSelectedByKey()
+ public void ClearIsSelectedByKey()
{
ClearIsSelectedByKey(iMenuKey, iRowKey);
}
- internal void Select(DataGridView dgv, int i, bool refreshview)
+ public void Select(DataGridView dgv, int i, bool refreshview)
{
int newiMenuKey = ((Menu)dgv.TopLevelControl).Level;
if (i != iRowKey || newiMenuKey != iMenuKey)
@@ -222,6 +223,11 @@ namespace SystemTrayMenu.Handler
}
}
+ private void Hook_KeyPressed(object sender, KeyPressedEventArgs e)
+ {
+ HotKeyPressed?.Invoke();
+ }
+
private bool IsAnyMenuSelectedByKey(
ref DataGridView dgv,
ref Menu menuFromSelected,
@@ -307,7 +313,7 @@ namespace SystemTrayMenu.Handler
}
else
{
- RowDeselected(iRowBefore, dgvBefore);
+ RowDeselected(dgvBefore, iRowBefore);
SelectRow(dgv, iRowKey);
EnterPressed.Invoke(dgv, iRowKey);
}
@@ -318,7 +324,7 @@ namespace SystemTrayMenu.Handler
if (SelectMatchedReverse(dgv, iRowKey) ||
SelectMatchedReverse(dgv, dgv.Rows.Count - 1))
{
- RowDeselected(iRowBefore, dgvBefore);
+ RowDeselected(dgvBefore, iRowBefore);
SelectRow(dgv, iRowKey);
toClear = true;
}
@@ -328,7 +334,7 @@ namespace SystemTrayMenu.Handler
if (SelectMatched(dgv, iRowKey) ||
SelectMatched(dgv, 0))
{
- RowDeselected(iRowBefore, dgvBefore);
+ RowDeselected(dgvBefore, iRowBefore);
SelectRow(dgv, iRowKey);
toClear = true;
}
@@ -337,7 +343,7 @@ namespace SystemTrayMenu.Handler
case Keys.Home:
if (SelectMatched(dgv, 0))
{
- RowDeselected(iRowBefore, dgvBefore);
+ RowDeselected(dgvBefore, iRowBefore);
SelectRow(dgv, iRowKey);
toClear = true;
}
@@ -346,7 +352,7 @@ namespace SystemTrayMenu.Handler
case Keys.End:
if (SelectMatchedReverse(dgv, dgv.Rows.Count - 1))
{
- RowDeselected(iRowBefore, dgvBefore);
+ RowDeselected(dgvBefore, iRowBefore);
SelectRow(dgv, iRowKey);
toClear = true;
}
@@ -380,7 +386,7 @@ namespace SystemTrayMenu.Handler
break;
case Keys.Escape:
case Keys.Alt | Keys.F4:
- RowDeselected(iRowBefore, dgvBefore);
+ RowDeselected(dgvBefore, iRowBefore);
iMenuKey = 0;
iRowKey = -1;
toClear = true;
@@ -392,7 +398,7 @@ namespace SystemTrayMenu.Handler
if (SelectMatched(dgv, iRowKey, keyInput) ||
SelectMatched(dgv, 0, keyInput))
{
- RowDeselected(iRowBefore, null);
+ RowDeselected(null, iRowBefore);
SelectRow(dgv, iRowKey);
toClear = true;
}
@@ -402,7 +408,7 @@ namespace SystemTrayMenu.Handler
if (SelectMatched(dgv, iRowKey, keyInput) ||
SelectMatched(dgv, 0, keyInput))
{
- RowDeselected(iRowBefore, null);
+ RowDeselected(null, iRowBefore);
SelectRow(dgv, iRowKey);
}
else
@@ -434,7 +440,7 @@ namespace SystemTrayMenu.Handler
if (SelectMatched(dgv, dgv.SelectedRows[0].Index) ||
SelectMatched(dgv, 0))
{
- RowDeselected(iRowBefore, dgvBefore);
+ RowDeselected(dgvBefore, iRowBefore);
SelectRow(dgv, iRowKey);
toClear = true;
}
@@ -442,7 +448,7 @@ namespace SystemTrayMenu.Handler
}
else
{
- RowDeselected(iRowBefore, dgvBefore);
+ RowDeselected(dgvBefore, iRowBefore);
iMenuKey = 0;
iRowKey = -1;
toClear = true;
@@ -466,7 +472,7 @@ namespace SystemTrayMenu.Handler
if (SelectMatched(dgv, iRowKey) ||
SelectMatched(dgv, 0))
{
- RowDeselected(iRowBefore, dgvBefore);
+ RowDeselected(dgvBefore, iRowBefore);
SelectRow(dgv, iRowKey);
toClear = true;
}
@@ -483,7 +489,7 @@ namespace SystemTrayMenu.Handler
if (SelectMatched(dgv, iRowKey) ||
SelectMatched(dgv, 0))
{
- RowDeselected(iRowBefore, dgvBefore);
+ RowDeselected(dgvBefore, iRowBefore);
SelectRow(dgv, iRowKey);
toClear = true;
}
diff --git a/Business/Menus.cs b/Business/Menus.cs
index bbb49e9..f92080a 100644
--- a/Business/Menus.cs
+++ b/Business/Menus.cs
@@ -12,6 +12,7 @@ namespace SystemTrayMenu.Business
using System.IO;
using System.Linq;
using System.Windows.Forms;
+ using SharpDX.DirectInput;
using SystemTrayMenu.DataClasses;
using SystemTrayMenu.DllImports;
using SystemTrayMenu.Handler;
@@ -19,6 +20,7 @@ namespace SystemTrayMenu.Business
using SystemTrayMenu.Helpers;
using SystemTrayMenu.UserInterface;
using SystemTrayMenu.Utilities;
+ using static System.Windows.Forms.VisualStyles.VisualStyleElement;
using Menu = SystemTrayMenu.UserInterface.Menu;
using Timer = System.Windows.Forms.Timer;
@@ -53,275 +55,33 @@ namespace SystemTrayMenu.Business
workerMainMenu.WorkerSupportsCancellation = true;
workerMainMenu.DoWork += LoadMenu;
workerMainMenu.RunWorkerCompleted += LoadMainMenuCompleted;
- void LoadMainMenuCompleted(object sender, RunWorkerCompletedEventArgs e)
- {
- keyboardInput.ResetSelectedByKey();
- LoadStopped();
-
- if (e.Result == null)
- {
- // Clean up menu status IsMenuOpen for previous one
- DataGridView dgvMainMenu = menus[0].GetDataGridView();
- foreach (DataRow row in ((DataTable)dgvMainMenu.DataSource).Rows)
- {
- RowData rowDataToClear = (RowData)row[2];
- rowDataToClear.IsMenuOpen = false;
- rowDataToClear.IsClicking = false;
- rowDataToClear.IsSelected = false;
- rowDataToClear.IsContextMenuOpen = false;
- }
-
- RefreshSelection(dgvMainMenu);
-
- if (Properties.Settings.Default.AppearAtMouseLocation)
- {
- menus[0].Tag = null;
- }
-
- AsEnumerable.ToList().ForEach(m => { m.ShowWithFade(); });
- }
- else
- {
- MenuData menuData = (MenuData)e.Result;
- switch (menuData.Validity)
- {
- case MenuDataValidity.Valid:
- if (IconReader.MainPreload)
- {
- workerMainMenu.DoWork -= LoadMenu;
- menus[0] = Create(menuData, new DirectoryInfo(Config.Path).Name);
- menus[0].HandleCreated += (s, e) => ExecuteWatcherHistory();
- Scaling.CalculateFactorByDpi(menus[0].GetDataGridView().CreateGraphics());
- IconReader.MainPreload = false;
- if (showMenuAfterMainPreload)
- {
- AsEnumerable.ToList().ForEach(m => { m.ShowWithFade(); });
- }
- }
- else
- {
- AsEnumerable.ToList().ForEach(m => { m.ShowWithFade(); });
- }
-
- break;
- case MenuDataValidity.Empty:
- MessageBox.Show(Translator.GetText("Your root directory for the app does not exist or is empty! Change the root directory or put some files, directories or shortcuts into the root directory."));
- OpenFolder();
- Config.SetFolderByUser();
- AppRestart.ByConfigChange();
- break;
- case MenuDataValidity.NoAccess:
- MessageBox.Show(Translator.GetText("You have no access to the root directory of the app. Grant access to the directory or change the root directory."));
- OpenFolder();
- Config.SetFolderByUser();
- AppRestart.ByConfigChange();
- break;
- case MenuDataValidity.Undefined:
- Log.Info($"{nameof(MenuDataValidity)}.{nameof(MenuDataValidity.Undefined)}");
- break;
- default:
- break;
- }
- }
-
- openCloseState = OpenCloseState.Default;
- }
-
waitToOpenMenu.StopLoadMenu += WaitToOpenMenu_StopLoadMenu;
- void WaitToOpenMenu_StopLoadMenu()
- {
- foreach (BackgroundWorker workerSubMenu in workersSubMenu.
- Where(w => w.IsBusy))
- {
- workerSubMenu.CancelAsync();
- }
-
- LoadStopped();
- }
-
waitToOpenMenu.StartLoadMenu += StartLoadMenu;
- void StartLoadMenu(RowData rowData)
- {
- if (menus[0].IsUsable &&
- (menus[rowData.Level + 1] == null ||
- menus[rowData.Level + 1].Tag as RowData != rowData))
- {
- CreateAndShowLoadingMenu(rowData);
- void CreateAndShowLoadingMenu(RowData rowData)
- {
- MenuData menuDataLoading = new(rowData.Level + 1)
- {
- Validity = MenuDataValidity.Valid,
- };
-
- Menu menuLoading = Create(menuDataLoading, new DirectoryInfo(rowData.Path).Name);
- menuLoading.IsLoadingMenu = true;
- AdjustMenusSizeAndLocation();
- menus[rowData.Level + 1] = menuLoading;
- menuLoading.Tag = menuDataLoading.RowDataParent = rowData;
- menuDataLoading.RowDataParent.SubMenu = menuLoading;
- menuLoading.SetTypeLoading();
- ShowSubMenu(menuLoading);
- }
-
- BackgroundWorker workerSubMenu = workersSubMenu.
- Where(w => !w.IsBusy).FirstOrDefault();
- if (workerSubMenu == null)
- {
- workerSubMenu = new BackgroundWorker
- {
- WorkerSupportsCancellation = true,
- };
- workerSubMenu.DoWork += LoadMenu;
- workerSubMenu.RunWorkerCompleted += LoadSubMenuCompleted;
- workersSubMenu.Add(workerSubMenu);
- }
-
- workerSubMenu.RunWorkerAsync(rowData);
- }
-
- void LoadSubMenuCompleted(object senderCompleted, RunWorkerCompletedEventArgs e)
- {
- MenuData menuData = (MenuData)e.Result;
-
- Menu menuLoading = menus[menuData.Level];
- string userSearchText = string.Empty;
- bool closedLoadingMenu = false;
- if (menuLoading != null && menuLoading.IsLoadingMenu)
- {
- menuLoading.HideWithFade();
- userSearchText = menuLoading.GetSearchText();
- menus[menuLoading.Level] = null;
- closedLoadingMenu = true;
- }
-
- if (menuData.Validity != MenuDataValidity.Undefined &&
- menus[0].IsUsable)
- {
- 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;
- }
-
- menu.Tag = menuData.RowDataParent;
- menuData.RowDataParent.SubMenu = menu;
- if (menus[0].IsUsable)
- {
- ShowSubMenu(menu);
- menu.SetSearchText(userSearchText);
- }
- }
- else if (closedLoadingMenu && menus[0].IsUsable)
- {
- menuData.RowDataParent.IsMenuOpen = false;
- menuData.RowDataParent.IsClicking = false;
- menuData.RowDataParent.IsSelected = false;
- Menu menuPrevious = menus[menuData.Level - 1];
- if (menuPrevious != null)
- {
- RefreshSelection(menuPrevious.GetDataGridView());
- }
- }
- }
- }
-
waitToOpenMenu.CloseMenu += CloseMenu;
- void CloseMenu(int level)
- {
- if (level < menus.Length && menus[level] != null)
- {
- HideOldMenu(menus[level]);
- }
-
- if (level - 1 < menus.Length && menus[level - 1] != null)
- {
- menus[level - 1].FocusTextBox();
- }
- }
-
waitToOpenMenu.MouseEnterOk += MouseEnterOk;
dgvMouseRow.RowMouseEnter += waitToOpenMenu.MouseEnter;
dgvMouseRow.RowMouseLeave += waitToOpenMenu.MouseLeave;
dgvMouseRow.RowMouseLeave += Dgv_RowMouseLeave;
-
keyboardInput = new(menus);
keyboardInput.RegisterHotKey();
- keyboardInput.HotKeyPressed += () => SwitchOpenClose(false);
+ keyboardInput.HotKeyPressed += KeyboardInput_HotKeyPressed;
keyboardInput.ClosePressed += MenusFadeOut;
keyboardInput.RowDeselected += waitToOpenMenu.RowDeselected;
keyboardInput.EnterPressed += waitToOpenMenu.EnterOpensInstantly;
keyboardInput.RowSelected += waitToOpenMenu.RowSelected;
keyboardInput.RowSelected += AdjustScrollbarToDisplayedRow;
- void AdjustScrollbarToDisplayedRow(DataGridView dgv, int index)
- {
- Menu menu = (Menu)dgv.FindForm();
- menu.AdjustScrollbar();
- }
-
joystickHelper = new();
- joystickHelper.KeyPressed += (key) => menus[0].Invoke(keyboardInput.CmdKeyProcessed, null, key);
-
+ joystickHelper.KeyPressed += JoystickHelper_KeyPressed;
timerShowProcessStartedAsLoadingIcon.Interval = Properties.Settings.Default.TimeUntilClosesAfterEnterPressed;
timerStillActiveCheck.Interval = Properties.Settings.Default.TimeUntilClosesAfterEnterPressed + 20;
- timerStillActiveCheck.Tick += (sender, e) => StillActiveTick();
- void StillActiveTick()
- {
- if (!IsActive())
- {
- FadeHalfOrOutIfNeeded();
- }
-
- timerStillActiveCheck.Stop();
- }
-
+ timerStillActiveCheck.Tick += TimerStillActiveCheck_Tick;
waitLeave.LeaveTriggered += FadeHalfOrOutIfNeeded;
-
- CreateWatcher(Config.Path, false);
- foreach (var pathAndFlags in MenusHelpers.GetAddionalPathsForMainMenu())
- {
- CreateWatcher(pathAndFlags.Path, pathAndFlags.Recursive);
- }
-
- void CreateWatcher(string path, bool recursiv)
- {
- try
- {
- FileSystemWatcher watcher = new()
- {
- Path = path,
- NotifyFilter = NotifyFilters.Attributes |
- NotifyFilters.DirectoryName |
- NotifyFilters.FileName |
- NotifyFilters.LastWrite,
- Filter = "*.*",
- };
- watcher.Created += WatcherProcessItem;
- watcher.Deleted += WatcherProcessItem;
- watcher.Renamed += WatcherProcessItem;
- watcher.Changed += WatcherProcessItem;
- watcher.IncludeSubdirectories = recursiv;
- watcher.EnableRaisingEvents = true;
- watchers.Add(watcher);
- }
- catch (Exception ex)
- {
- Log.Warn($"Failed to {nameof(CreateWatcher)}: {path}", ex);
- }
- }
+ CreateWatchers();
}
- internal event EventHandlerEmpty LoadStarted;
+ public event Action LoadStarted;
- internal event EventHandlerEmpty LoadStopped;
+ public event Action LoadStopped;
private enum OpenCloseState
{
@@ -334,34 +94,7 @@ namespace SystemTrayMenu.Business
private List