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()
|
||||
{
|
||||
AppRestart.BeforeRestarting += Dispose;
|
||||
SystemEvents.DisplaySettingsChanged += SystemEvents_DisplaySettingsChanged;
|
||||
menus.LoadStarted += menuNotifyIcon.LoadingStart;
|
||||
menus.LoadStopped += menuNotifyIcon.LoadingStop;
|
||||
menuNotifyIcon.Click += () => menus.SwitchOpenClose(true);
|
||||
|
@ -65,17 +64,11 @@ namespace SystemTrayMenu
|
|||
TaskbarLogo?.Close();
|
||||
TaskbarLogo = null;
|
||||
|
||||
SystemEvents.DisplaySettingsChanged -= SystemEvents_DisplaySettingsChanged;
|
||||
menus.Dispose();
|
||||
menuNotifyIcon.Dispose();
|
||||
|
||||
isDisposed = true;
|
||||
}
|
||||
}
|
||||
|
||||
private void SystemEvents_DisplaySettingsChanged(object? sender, EventArgs e)
|
||||
{
|
||||
menus.ReAdjustSizeAndLocation();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -14,6 +14,7 @@ namespace SystemTrayMenu.Handler
|
|||
using SystemTrayMenu.DataClasses;
|
||||
using SystemTrayMenu.Helper;
|
||||
using SystemTrayMenu.Utilities;
|
||||
using static System.Net.Mime.MediaTypeNames;
|
||||
using ListView = System.Windows.Controls.ListView;
|
||||
using Menu = SystemTrayMenu.UserInterface.Menu;
|
||||
|
||||
|
@ -214,9 +215,8 @@ namespace SystemTrayMenu.Handler
|
|||
|
||||
if (dgv.Items.Count > index)
|
||||
{
|
||||
#if TODO
|
||||
DataGridViewRow row = dgv.Items[i];
|
||||
RowData rowData = (RowData)row.Cells[2].Value;
|
||||
Menu.ListViewItemData itemData = (Menu.ListViewItemData)dgv.Items[index];
|
||||
RowData rowData = itemData.data;
|
||||
if (rowData != null)
|
||||
{
|
||||
rowData.IsSelected = true;
|
||||
|
@ -224,10 +224,13 @@ namespace SystemTrayMenu.Handler
|
|||
|
||||
if (refreshview)
|
||||
{
|
||||
row.Selected = false;
|
||||
row.Selected = true;
|
||||
if (dgv.SelectedItems.Contains(itemData))
|
||||
{
|
||||
dgv.SelectedItems.Remove(itemData);
|
||||
}
|
||||
|
||||
dgv.SelectedItems.Add(itemData);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -244,17 +247,14 @@ namespace SystemTrayMenu.Handler
|
|||
dgv = menu.GetDataGridView();
|
||||
if (dgv.Items.Count > iRowKey)
|
||||
{
|
||||
#if TODO
|
||||
RowData rowData = (RowData)dgv.
|
||||
Items[iRowKey].Cells[2].Value;
|
||||
Menu.ListViewItemData itemData = (Menu.ListViewItemData)dgv.Items[iRowKey];
|
||||
RowData rowData = itemData.data;
|
||||
if (rowData.IsSelected)
|
||||
{
|
||||
isStillSelected = true;
|
||||
menuFromSelected = rowData.SubMenu;
|
||||
textselected = dgv.Rows[iRowKey].
|
||||
Cells[1].Value.ToString();
|
||||
textselected = itemData.ColumnText;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -554,31 +554,22 @@ namespace SystemTrayMenu.Handler
|
|||
i != iRowKey &&
|
||||
dgv.Items.Count > i)
|
||||
{
|
||||
#if TODO
|
||||
DataGridViewRow row = dgv.Items[i];
|
||||
RowData rowData = (RowData)row.Cells[2].Value;
|
||||
string text = row.Cells[1].Value.ToString();
|
||||
if (text.StartsWith(keyInput, true, CultureInfo.InvariantCulture))
|
||||
Menu.ListViewItemData itemData = (Menu.ListViewItemData)dgv.Items[i];
|
||||
RowData rowData = itemData.data;
|
||||
if (itemData.ColumnText.StartsWith(keyInput, true, CultureInfo.InvariantCulture))
|
||||
{
|
||||
iRowKey = rowData.RowIndex;
|
||||
rowData.IsSelected = true;
|
||||
row.Selected = false;
|
||||
row.Selected = true;
|
||||
if (row.Index < dgv.FirstDisplayedScrollingRowIndex)
|
||||
if (dgv.SelectedItems.Contains(itemData))
|
||||
{
|
||||
dgv.FirstDisplayedScrollingRowIndex = row.Index;
|
||||
}
|
||||
else if (row.Index >=
|
||||
dgv.FirstDisplayedScrollingRowIndex +
|
||||
dgv.DisplayedRowCount(false))
|
||||
{
|
||||
dgv.FirstDisplayedScrollingRowIndex = row.Index -
|
||||
dgv.DisplayedRowCount(false) + 1;
|
||||
dgv.SelectedItems.Remove(itemData);
|
||||
}
|
||||
|
||||
dgv.SelectedItems.Add(itemData);
|
||||
dgv.ScrollIntoView(itemData);
|
||||
|
||||
found = true;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
return found;
|
||||
|
@ -592,16 +583,18 @@ namespace SystemTrayMenu.Handler
|
|||
ListView dgv = menu.GetDataGridView();
|
||||
if (dgv.Items.Count > rowIndex)
|
||||
{
|
||||
#if TODO
|
||||
DataGridViewRow row = dgv.Rows[rowIndex];
|
||||
row.Selected = false;
|
||||
RowData rowData = (RowData)row.Cells[2].Value;
|
||||
Menu.ListViewItemData itemData = (Menu.ListViewItemData)dgv.Items[rowIndex];
|
||||
RowData rowData = itemData.data;
|
||||
if (dgv.SelectedItems.Contains(itemData))
|
||||
{
|
||||
dgv.SelectedItems.Remove(itemData);
|
||||
}
|
||||
|
||||
if (rowData != null)
|
||||
{
|
||||
rowData.IsSelected = false;
|
||||
rowData.IsClicking = false;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -14,6 +14,7 @@ namespace SystemTrayMenu.Business
|
|||
using System.Windows.Controls;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Threading;
|
||||
using Microsoft.Win32;
|
||||
using SystemTrayMenu.DataClasses;
|
||||
using SystemTrayMenu.DllImports;
|
||||
using SystemTrayMenu.Handler;
|
||||
|
@ -319,6 +320,8 @@ namespace SystemTrayMenu.Business
|
|||
Log.Warn($"Failed to {nameof(CreateWatcher)}: {path}", ex);
|
||||
}
|
||||
}
|
||||
|
||||
SystemEvents.DisplaySettingsChanged += SystemEvents_DisplaySettingsChanged;
|
||||
}
|
||||
|
||||
internal event Action LoadStarted;
|
||||
|
@ -338,6 +341,7 @@ namespace SystemTrayMenu.Business
|
|||
|
||||
public void Dispose()
|
||||
{
|
||||
SystemEvents.DisplaySettingsChanged -= SystemEvents_DisplaySettingsChanged;
|
||||
workerMainMenu.Dispose();
|
||||
foreach (BackgroundWorker worker in workersSubMenu)
|
||||
{
|
||||
|
@ -351,7 +355,7 @@ namespace SystemTrayMenu.Business
|
|||
timerStillActiveCheck.Stop();
|
||||
waitLeave.Dispose();
|
||||
IconReader.Dispose();
|
||||
DisposeMenu(menus[0]);
|
||||
menus[0]?.Close();
|
||||
dgvMouseRow.Dispose();
|
||||
|
||||
foreach (FileSystemWatcher watcher in watchers)
|
||||
|
@ -447,54 +451,6 @@ namespace SystemTrayMenu.Business
|
|||
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()
|
||||
{
|
||||
IconReader.MainPreload = true;
|
||||
|
@ -748,7 +704,7 @@ namespace SystemTrayMenu.Business
|
|||
|
||||
if (menu.Visibility != Visibility.Visible && menu.Level != 0)
|
||||
{
|
||||
DisposeMenu(menu);
|
||||
menu.Close();
|
||||
}
|
||||
|
||||
if (!AsEnumerable.Any(m => m.Visibility == Visibility.Visible))
|
||||
|
@ -817,7 +773,7 @@ namespace SystemTrayMenu.Business
|
|||
|
||||
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);
|
||||
|
||||
if (e.LeftButton == MouseButtonState.Pressed)
|
||||
|
@ -991,9 +947,7 @@ namespace SystemTrayMenu.Business
|
|||
|
||||
if (!searchTextChanging)
|
||||
{
|
||||
#if TODO
|
||||
dgv.Invalidate();
|
||||
#endif
|
||||
dgv.InvalidateVisual();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1049,6 +1003,14 @@ namespace SystemTrayMenu.Business
|
|||
}
|
||||
#endif
|
||||
|
||||
private void SystemEvents_DisplaySettingsChanged(object sender, EventArgs e)
|
||||
{
|
||||
if (menus[0].IsUsable)
|
||||
{
|
||||
menus[0].Tag = null;
|
||||
}
|
||||
}
|
||||
|
||||
private void ShowSubMenu(Menu menuToShow)
|
||||
{
|
||||
HideOldMenu(menuToShow, true);
|
||||
|
@ -1201,7 +1163,7 @@ namespace SystemTrayMenu.Business
|
|||
menu = list[i];
|
||||
|
||||
menu.AdjustSizeAndLocation(screenBounds, menuPredecessor, startLocation, isCustomLocationOutsideOfScreen);
|
||||
#if TODO // What is this, doesn't seem to have any effect ?
|
||||
|
||||
if (!Properties.Settings.Default.AppearAtTheBottomLeft &&
|
||||
!Properties.Settings.Default.AppearAtMouseLocation &&
|
||||
!Properties.Settings.Default.UseCustomLocation &&
|
||||
|
@ -1217,7 +1179,7 @@ namespace SystemTrayMenu.Business
|
|||
|
||||
screenBounds.Width -= (int)menu.Width - overlapTolerance;
|
||||
}
|
||||
#endif
|
||||
|
||||
menuPredecessor = menu;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -158,7 +158,7 @@
|
|||
<Setter Property="Padding" Value="0"/>
|
||||
<EventSetter Event="MouseEnter" Handler="ListViewItem_MouseEnter" />
|
||||
<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="PreviewMouseLeftButtonDown" Handler="ListViewxItem_PreviewMouseLeftButtonDown" />
|
||||
<EventSetter Event="MouseDoubleClick" Handler="ListViewItem_MouseDoubleClick" />
|
||||
|
|
|
@ -212,6 +212,14 @@ namespace SystemTrayMenu.UserInterface
|
|||
IsHandleCreated = true;
|
||||
HandleCreated?.Invoke(sender, e);
|
||||
};
|
||||
|
||||
Closed += (sender, e) =>
|
||||
{
|
||||
foreach (ListViewItemData item in dgv.Items)
|
||||
{
|
||||
item.data.SubMenu?.Close();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
#if TODO
|
||||
|
@ -886,32 +894,7 @@ namespace SystemTrayMenu.UserInterface
|
|||
(double)(Scaling.Factor * Scaling.FactorByDpi * 400f * (Properties.Settings.Default.WidthMaxInPercent / 100f)));
|
||||
|
||||
#endif
|
||||
#if TODO
|
||||
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
|
||||
((CollectionView)CollectionViewSource.GetDefaultView(dgv.ItemsSource)).Filter = null;
|
||||
}
|
||||
|
||||
#if TODO
|
||||
|
@ -1280,9 +1263,11 @@ namespace SystemTrayMenu.UserInterface
|
|||
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);
|
||||
#endif
|
||||
}
|
||||
|
||||
private void ListViewItem_MouseUp(object sender, MouseButtonEventArgs e)
|
||||
|
|
Loading…
Reference in a new issue