mirror of
https://github.com/Hofknecht/SystemTrayMenu.git
synced 2024-07-05 22:40:41 +12:00
Rework and port some events
This commit is contained in:
parent
1245700a13
commit
885a5c85be
|
@ -28,7 +28,6 @@ namespace SystemTrayMenu
|
||||||
public App()
|
public App()
|
||||||
{
|
{
|
||||||
AppRestart.BeforeRestarting += Dispose;
|
AppRestart.BeforeRestarting += Dispose;
|
||||||
SystemEvents.DisplaySettingsChanged += SystemEvents_DisplaySettingsChanged;
|
|
||||||
menus.LoadStarted += menuNotifyIcon.LoadingStart;
|
menus.LoadStarted += menuNotifyIcon.LoadingStart;
|
||||||
menus.LoadStopped += menuNotifyIcon.LoadingStop;
|
menus.LoadStopped += menuNotifyIcon.LoadingStop;
|
||||||
menuNotifyIcon.Click += () => menus.SwitchOpenClose(true);
|
menuNotifyIcon.Click += () => menus.SwitchOpenClose(true);
|
||||||
|
@ -65,17 +64,11 @@ namespace SystemTrayMenu
|
||||||
TaskbarLogo?.Close();
|
TaskbarLogo?.Close();
|
||||||
TaskbarLogo = null;
|
TaskbarLogo = null;
|
||||||
|
|
||||||
SystemEvents.DisplaySettingsChanged -= SystemEvents_DisplaySettingsChanged;
|
|
||||||
menus.Dispose();
|
menus.Dispose();
|
||||||
menuNotifyIcon.Dispose();
|
menuNotifyIcon.Dispose();
|
||||||
|
|
||||||
isDisposed = true;
|
isDisposed = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void SystemEvents_DisplaySettingsChanged(object? sender, EventArgs e)
|
|
||||||
{
|
|
||||||
menus.ReAdjustSizeAndLocation();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,6 +14,7 @@ namespace SystemTrayMenu.Handler
|
||||||
using SystemTrayMenu.DataClasses;
|
using SystemTrayMenu.DataClasses;
|
||||||
using SystemTrayMenu.Helper;
|
using SystemTrayMenu.Helper;
|
||||||
using SystemTrayMenu.Utilities;
|
using SystemTrayMenu.Utilities;
|
||||||
|
using static System.Net.Mime.MediaTypeNames;
|
||||||
using ListView = System.Windows.Controls.ListView;
|
using ListView = System.Windows.Controls.ListView;
|
||||||
using Menu = SystemTrayMenu.UserInterface.Menu;
|
using Menu = SystemTrayMenu.UserInterface.Menu;
|
||||||
|
|
||||||
|
@ -214,9 +215,8 @@ namespace SystemTrayMenu.Handler
|
||||||
|
|
||||||
if (dgv.Items.Count > index)
|
if (dgv.Items.Count > index)
|
||||||
{
|
{
|
||||||
#if TODO
|
Menu.ListViewItemData itemData = (Menu.ListViewItemData)dgv.Items[index];
|
||||||
DataGridViewRow row = dgv.Items[i];
|
RowData rowData = itemData.data;
|
||||||
RowData rowData = (RowData)row.Cells[2].Value;
|
|
||||||
if (rowData != null)
|
if (rowData != null)
|
||||||
{
|
{
|
||||||
rowData.IsSelected = true;
|
rowData.IsSelected = true;
|
||||||
|
@ -224,10 +224,13 @@ namespace SystemTrayMenu.Handler
|
||||||
|
|
||||||
if (refreshview)
|
if (refreshview)
|
||||||
{
|
{
|
||||||
row.Selected = false;
|
if (dgv.SelectedItems.Contains(itemData))
|
||||||
row.Selected = true;
|
{
|
||||||
|
dgv.SelectedItems.Remove(itemData);
|
||||||
|
}
|
||||||
|
|
||||||
|
dgv.SelectedItems.Add(itemData);
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -244,17 +247,14 @@ namespace SystemTrayMenu.Handler
|
||||||
dgv = menu.GetDataGridView();
|
dgv = menu.GetDataGridView();
|
||||||
if (dgv.Items.Count > iRowKey)
|
if (dgv.Items.Count > iRowKey)
|
||||||
{
|
{
|
||||||
#if TODO
|
Menu.ListViewItemData itemData = (Menu.ListViewItemData)dgv.Items[iRowKey];
|
||||||
RowData rowData = (RowData)dgv.
|
RowData rowData = itemData.data;
|
||||||
Items[iRowKey].Cells[2].Value;
|
|
||||||
if (rowData.IsSelected)
|
if (rowData.IsSelected)
|
||||||
{
|
{
|
||||||
isStillSelected = true;
|
isStillSelected = true;
|
||||||
menuFromSelected = rowData.SubMenu;
|
menuFromSelected = rowData.SubMenu;
|
||||||
textselected = dgv.Rows[iRowKey].
|
textselected = itemData.ColumnText;
|
||||||
Cells[1].Value.ToString();
|
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -554,31 +554,22 @@ namespace SystemTrayMenu.Handler
|
||||||
i != iRowKey &&
|
i != iRowKey &&
|
||||||
dgv.Items.Count > i)
|
dgv.Items.Count > i)
|
||||||
{
|
{
|
||||||
#if TODO
|
Menu.ListViewItemData itemData = (Menu.ListViewItemData)dgv.Items[i];
|
||||||
DataGridViewRow row = dgv.Items[i];
|
RowData rowData = itemData.data;
|
||||||
RowData rowData = (RowData)row.Cells[2].Value;
|
if (itemData.ColumnText.StartsWith(keyInput, true, CultureInfo.InvariantCulture))
|
||||||
string text = row.Cells[1].Value.ToString();
|
|
||||||
if (text.StartsWith(keyInput, true, CultureInfo.InvariantCulture))
|
|
||||||
{
|
{
|
||||||
iRowKey = rowData.RowIndex;
|
iRowKey = rowData.RowIndex;
|
||||||
rowData.IsSelected = true;
|
rowData.IsSelected = true;
|
||||||
row.Selected = false;
|
if (dgv.SelectedItems.Contains(itemData))
|
||||||
row.Selected = true;
|
|
||||||
if (row.Index < dgv.FirstDisplayedScrollingRowIndex)
|
|
||||||
{
|
{
|
||||||
dgv.FirstDisplayedScrollingRowIndex = row.Index;
|
dgv.SelectedItems.Remove(itemData);
|
||||||
}
|
|
||||||
else if (row.Index >=
|
|
||||||
dgv.FirstDisplayedScrollingRowIndex +
|
|
||||||
dgv.DisplayedRowCount(false))
|
|
||||||
{
|
|
||||||
dgv.FirstDisplayedScrollingRowIndex = row.Index -
|
|
||||||
dgv.DisplayedRowCount(false) + 1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
dgv.SelectedItems.Add(itemData);
|
||||||
|
dgv.ScrollIntoView(itemData);
|
||||||
|
|
||||||
found = true;
|
found = true;
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return found;
|
return found;
|
||||||
|
@ -592,16 +583,18 @@ namespace SystemTrayMenu.Handler
|
||||||
ListView dgv = menu.GetDataGridView();
|
ListView dgv = menu.GetDataGridView();
|
||||||
if (dgv.Items.Count > rowIndex)
|
if (dgv.Items.Count > rowIndex)
|
||||||
{
|
{
|
||||||
#if TODO
|
Menu.ListViewItemData itemData = (Menu.ListViewItemData)dgv.Items[rowIndex];
|
||||||
DataGridViewRow row = dgv.Rows[rowIndex];
|
RowData rowData = itemData.data;
|
||||||
row.Selected = false;
|
if (dgv.SelectedItems.Contains(itemData))
|
||||||
RowData rowData = (RowData)row.Cells[2].Value;
|
{
|
||||||
|
dgv.SelectedItems.Remove(itemData);
|
||||||
|
}
|
||||||
|
|
||||||
if (rowData != null)
|
if (rowData != null)
|
||||||
{
|
{
|
||||||
rowData.IsSelected = false;
|
rowData.IsSelected = false;
|
||||||
rowData.IsClicking = false;
|
rowData.IsClicking = false;
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,6 +14,7 @@ namespace SystemTrayMenu.Business
|
||||||
using System.Windows.Controls;
|
using System.Windows.Controls;
|
||||||
using System.Windows.Input;
|
using System.Windows.Input;
|
||||||
using System.Windows.Threading;
|
using System.Windows.Threading;
|
||||||
|
using Microsoft.Win32;
|
||||||
using SystemTrayMenu.DataClasses;
|
using SystemTrayMenu.DataClasses;
|
||||||
using SystemTrayMenu.DllImports;
|
using SystemTrayMenu.DllImports;
|
||||||
using SystemTrayMenu.Handler;
|
using SystemTrayMenu.Handler;
|
||||||
|
@ -319,6 +320,8 @@ namespace SystemTrayMenu.Business
|
||||||
Log.Warn($"Failed to {nameof(CreateWatcher)}: {path}", ex);
|
Log.Warn($"Failed to {nameof(CreateWatcher)}: {path}", ex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SystemEvents.DisplaySettingsChanged += SystemEvents_DisplaySettingsChanged;
|
||||||
}
|
}
|
||||||
|
|
||||||
internal event Action LoadStarted;
|
internal event Action LoadStarted;
|
||||||
|
@ -338,6 +341,7 @@ namespace SystemTrayMenu.Business
|
||||||
|
|
||||||
public void Dispose()
|
public void Dispose()
|
||||||
{
|
{
|
||||||
|
SystemEvents.DisplaySettingsChanged -= SystemEvents_DisplaySettingsChanged;
|
||||||
workerMainMenu.Dispose();
|
workerMainMenu.Dispose();
|
||||||
foreach (BackgroundWorker worker in workersSubMenu)
|
foreach (BackgroundWorker worker in workersSubMenu)
|
||||||
{
|
{
|
||||||
|
@ -351,7 +355,7 @@ namespace SystemTrayMenu.Business
|
||||||
timerStillActiveCheck.Stop();
|
timerStillActiveCheck.Stop();
|
||||||
waitLeave.Dispose();
|
waitLeave.Dispose();
|
||||||
IconReader.Dispose();
|
IconReader.Dispose();
|
||||||
DisposeMenu(menus[0]);
|
menus[0]?.Close();
|
||||||
dgvMouseRow.Dispose();
|
dgvMouseRow.Dispose();
|
||||||
|
|
||||||
foreach (FileSystemWatcher watcher in watchers)
|
foreach (FileSystemWatcher watcher in watchers)
|
||||||
|
@ -447,54 +451,6 @@ namespace SystemTrayMenu.Business
|
||||||
deactivatedTime = DateTime.MinValue;
|
deactivatedTime = DateTime.MinValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
internal void DisposeMenu(Menu menuToDispose)
|
|
||||||
{
|
|
||||||
if (menuToDispose != null)
|
|
||||||
{
|
|
||||||
menuToDispose.CellMouseEnter -= dgvMouseRow.CellMouseEnter;
|
|
||||||
menuToDispose.CellMouseLeave -= dgvMouseRow.CellMouseLeave;
|
|
||||||
menuToDispose.CellMouseDown -= Dgv_MouseDown;
|
|
||||||
menuToDispose.CellMouseUp -= Dgv_MouseUp;
|
|
||||||
menuToDispose.CellMouseClick -= Dgv_MouseClick;
|
|
||||||
menuToDispose.CellMouseDoubleClick -= Dgv_MouseDoubleClick;
|
|
||||||
#if TODO
|
|
||||||
menuToDispose.MouseWheel -= AdjustMenusSizeAndLocation;
|
|
||||||
menuToDispose.MouseLeave -= waitLeave.Start;
|
|
||||||
menuToDispose.MouseEnter -= waitLeave.Stop;
|
|
||||||
menuToDispose.CmdKeyProcessed -= keyboardInput.CmdKeyProcessed;
|
|
||||||
menuToDispose.SearchTextChanging -= keyboardInput.SearchTextChanging;
|
|
||||||
menuToDispose.KeyPressCheck -= Menu_KeyPressCheck;
|
|
||||||
menuToDispose.SearchTextChanged -= Menu_SearchTextChanged;
|
|
||||||
ListView dgv = menuToDispose.GetDataGridView();
|
|
||||||
if (dgv != null)
|
|
||||||
{
|
|
||||||
dgv.MouseLeave -= dgvMouseRow.MouseLeave;
|
|
||||||
dgv.MouseLeave -= Dgv_MouseLeave;
|
|
||||||
dgv.MouseMove -= waitToOpenMenu.MouseMove;
|
|
||||||
dgv.MouseMove -= Dgv_MouseMove;
|
|
||||||
dgv.SelectionChanged -= Dgv_SelectionChanged;
|
|
||||||
dgv.RowPostPaint -= Dgv_RowPostPaint;
|
|
||||||
dgv.ClearSelection();
|
|
||||||
|
|
||||||
foreach (DataGridViewRow row in dgv.Rows)
|
|
||||||
{
|
|
||||||
RowData rowData = (RowData)row.Cells[2].Value;
|
|
||||||
DisposeMenu(rowData.SubMenu);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
menuToDispose.Dispose();
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
internal void ReAdjustSizeAndLocation()
|
|
||||||
{
|
|
||||||
if (menus[0].IsUsable)
|
|
||||||
{
|
|
||||||
menus[0].Tag = null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
internal void MainPreload()
|
internal void MainPreload()
|
||||||
{
|
{
|
||||||
IconReader.MainPreload = true;
|
IconReader.MainPreload = true;
|
||||||
|
@ -748,7 +704,7 @@ namespace SystemTrayMenu.Business
|
||||||
|
|
||||||
if (menu.Visibility != Visibility.Visible && menu.Level != 0)
|
if (menu.Visibility != Visibility.Visible && menu.Level != 0)
|
||||||
{
|
{
|
||||||
DisposeMenu(menu);
|
menu.Close();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!AsEnumerable.Any(m => m.Visibility == Visibility.Visible))
|
if (!AsEnumerable.Any(m => m.Visibility == Visibility.Visible))
|
||||||
|
@ -817,7 +773,7 @@ namespace SystemTrayMenu.Business
|
||||||
|
|
||||||
MouseEnterOk(dgv, index, true);
|
MouseEnterOk(dgv, index, true);
|
||||||
|
|
||||||
// TODO WPF: Move directly into ListViewItem_MouseDown ?
|
// TODO WPF: Move directly into ListViewItem_PreviewMouseDown ?
|
||||||
((Menu.ListViewItemData)dgv.Items[index]).data.MouseDown(dgv, e);
|
((Menu.ListViewItemData)dgv.Items[index]).data.MouseDown(dgv, e);
|
||||||
|
|
||||||
if (e.LeftButton == MouseButtonState.Pressed)
|
if (e.LeftButton == MouseButtonState.Pressed)
|
||||||
|
@ -991,9 +947,7 @@ namespace SystemTrayMenu.Business
|
||||||
|
|
||||||
if (!searchTextChanging)
|
if (!searchTextChanging)
|
||||||
{
|
{
|
||||||
#if TODO
|
dgv.InvalidateVisual();
|
||||||
dgv.Invalidate();
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1049,6 +1003,14 @@ namespace SystemTrayMenu.Business
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
private void SystemEvents_DisplaySettingsChanged(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
if (menus[0].IsUsable)
|
||||||
|
{
|
||||||
|
menus[0].Tag = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void ShowSubMenu(Menu menuToShow)
|
private void ShowSubMenu(Menu menuToShow)
|
||||||
{
|
{
|
||||||
HideOldMenu(menuToShow, true);
|
HideOldMenu(menuToShow, true);
|
||||||
|
@ -1201,7 +1163,7 @@ namespace SystemTrayMenu.Business
|
||||||
menu = list[i];
|
menu = list[i];
|
||||||
|
|
||||||
menu.AdjustSizeAndLocation(screenBounds, menuPredecessor, startLocation, isCustomLocationOutsideOfScreen);
|
menu.AdjustSizeAndLocation(screenBounds, menuPredecessor, startLocation, isCustomLocationOutsideOfScreen);
|
||||||
#if TODO // What is this, doesn't seem to have any effect ?
|
|
||||||
if (!Properties.Settings.Default.AppearAtTheBottomLeft &&
|
if (!Properties.Settings.Default.AppearAtTheBottomLeft &&
|
||||||
!Properties.Settings.Default.AppearAtMouseLocation &&
|
!Properties.Settings.Default.AppearAtMouseLocation &&
|
||||||
!Properties.Settings.Default.UseCustomLocation &&
|
!Properties.Settings.Default.UseCustomLocation &&
|
||||||
|
@ -1217,7 +1179,7 @@ namespace SystemTrayMenu.Business
|
||||||
|
|
||||||
screenBounds.Width -= (int)menu.Width - overlapTolerance;
|
screenBounds.Width -= (int)menu.Width - overlapTolerance;
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
menuPredecessor = menu;
|
menuPredecessor = menu;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -158,7 +158,7 @@
|
||||||
<Setter Property="Padding" Value="0"/>
|
<Setter Property="Padding" Value="0"/>
|
||||||
<EventSetter Event="MouseEnter" Handler="ListViewItem_MouseEnter" />
|
<EventSetter Event="MouseEnter" Handler="ListViewItem_MouseEnter" />
|
||||||
<EventSetter Event="MouseLeave" Handler="ListViewItem_MouseLeave" />
|
<EventSetter Event="MouseLeave" Handler="ListViewItem_MouseLeave" />
|
||||||
<EventSetter Event="PreviewMouseDown" Handler="ListViewItem_MouseDown" />
|
<EventSetter Event="PreviewMouseDown" Handler="ListViewItem_PreviewMouseDown" />
|
||||||
<EventSetter Event="MouseUp" Handler="ListViewItem_MouseUp" />
|
<EventSetter Event="MouseUp" Handler="ListViewItem_MouseUp" />
|
||||||
<EventSetter Event="PreviewMouseLeftButtonDown" Handler="ListViewxItem_PreviewMouseLeftButtonDown" />
|
<EventSetter Event="PreviewMouseLeftButtonDown" Handler="ListViewxItem_PreviewMouseLeftButtonDown" />
|
||||||
<EventSetter Event="MouseDoubleClick" Handler="ListViewItem_MouseDoubleClick" />
|
<EventSetter Event="MouseDoubleClick" Handler="ListViewItem_MouseDoubleClick" />
|
||||||
|
|
|
@ -212,6 +212,14 @@ namespace SystemTrayMenu.UserInterface
|
||||||
IsHandleCreated = true;
|
IsHandleCreated = true;
|
||||||
HandleCreated?.Invoke(sender, e);
|
HandleCreated?.Invoke(sender, e);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Closed += (sender, e) =>
|
||||||
|
{
|
||||||
|
foreach (ListViewItemData item in dgv.Items)
|
||||||
|
{
|
||||||
|
item.data.SubMenu?.Close();
|
||||||
|
}
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
#if TODO
|
#if TODO
|
||||||
|
@ -886,32 +894,7 @@ namespace SystemTrayMenu.UserInterface
|
||||||
(double)(Scaling.Factor * Scaling.FactorByDpi * 400f * (Properties.Settings.Default.WidthMaxInPercent / 100f)));
|
(double)(Scaling.Factor * Scaling.FactorByDpi * 400f * (Properties.Settings.Default.WidthMaxInPercent / 100f)));
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
#if TODO
|
((CollectionView)CollectionViewSource.GetDefaultView(dgv.ItemsSource)).Filter = null;
|
||||||
int widthIcon = dgv.Columns[0].Width;
|
|
||||||
int widthText = dgv.Columns[1].Width;
|
|
||||||
|
|
||||||
using Graphics gfx = labelTitle.CreateGraphics();
|
|
||||||
gfx.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAlias;
|
|
||||||
int withTitle = (int)(gfx.MeasureString(
|
|
||||||
txtTitle.Text + "___",
|
|
||||||
dgv.RowTemplate.DefaultCellStyle.Font).Width + 0.5);
|
|
||||||
|
|
||||||
if (withTitle > (widthIcon + widthText))
|
|
||||||
{
|
|
||||||
tableLayoutPanelDgvAndScrollbar.MinimumSize = new Size(withTitle, 0);
|
|
||||||
dgv.Width = withTitle;
|
|
||||||
dgv.Columns[1].Width = dgv.Width - widthIcon;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
tableLayoutPanelDgvAndScrollbar.MinimumSize = new Size(widthIcon + widthText, 0);
|
|
||||||
dgv.Width = widthIcon + widthText;
|
|
||||||
dgv.Columns[1].Width = dgv.Width - widthIcon;
|
|
||||||
}
|
|
||||||
|
|
||||||
DataTable dataTable = (DataTable)dgv.DataSource;
|
|
||||||
dataTable.DefaultView.RowFilter = RowFilterShowAll;
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#if TODO
|
#if TODO
|
||||||
|
@ -1280,9 +1263,11 @@ namespace SystemTrayMenu.UserInterface
|
||||||
CellMouseLeave?.Invoke(dgv, dgv.Items.IndexOf(((ListViewItem)sender).Content));
|
CellMouseLeave?.Invoke(dgv, dgv.Items.IndexOf(((ListViewItem)sender).Content));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void ListViewItem_MouseDown(object sender, MouseButtonEventArgs e)
|
private void ListViewItem_PreviewMouseDown(object sender, MouseButtonEventArgs e)
|
||||||
{
|
{
|
||||||
|
#if TODO // Why sender is a disconnected item, needed at all?
|
||||||
CellMouseDown?.Invoke(dgv, dgv.Items.IndexOf(((ListViewItem)sender).Content), e);
|
CellMouseDown?.Invoke(dgv, dgv.Items.IndexOf(((ListViewItem)sender).Content), e);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
private void ListViewItem_MouseUp(object sender, MouseButtonEventArgs e)
|
private void ListViewItem_MouseUp(object sender, MouseButtonEventArgs e)
|
||||||
|
|
Loading…
Reference in a new issue