Fix and extended use of mouse events

Add comments (tags) for all TODO markers
This commit is contained in:
Peter Kirmeier 2022-11-29 22:48:45 +01:00
parent 059b4cc73a
commit 1f985c53aa
9 changed files with 113 additions and 107 deletions

View file

@ -158,7 +158,7 @@ namespace SystemTrayMenu.Handler
if (iRowKey > -1 &&
dgv.Items.Count > iRowKey)
{
#if TODO
#if TODO // WPF: Better way to open context menu (as it looks like this is the code's intention)
Point point = dgv.GetCellDisplayRectangle(2, iRowKey, false).Location;
RowData trigger = (RowData)dgv.Rows[iRowKey].Cells[2].Value;
MouseEventArgs mouseEventArgs = new(MouseButtons.Right, 1, point.X, point.Y, 0);
@ -313,7 +313,7 @@ namespace SystemTrayMenu.Handler
if (trigger.IsMenuOpen || !trigger.ContainsMenu)
{
trigger.MouseClick(null, out bool toCloseByMouseClick);
#if TODO
#if TODO // Misc MouseEvents
trigger.DoubleClick(
new MouseButtonEventArgs(MouseButtons.Left, 0, 0, 0, 0),
out bool toCloseByDoubleClick);
@ -324,7 +324,7 @@ namespace SystemTrayMenu.Handler
{
ClosePressed?.Invoke();
}
#if TODO
#if TODO // WPF: Can be removed as we do not paint ourselfs?
if (iRowKey > -1 && dgv.Rows.Count > iRowKey)
{
// Raise Dgv_RowPostPaint to show ProcessStarted
@ -486,15 +486,14 @@ namespace SystemTrayMenu.Handler
iRowKey = -1;
menu = menus[iMenuKey];
dgv = menu.GetDataGridView();
#if TODO
if (SelectMatched(dgv, dgv.SelectedRows[0].Index) ||
if (SelectMatched(dgv, dgv.Items.IndexOf(dgv.SelectedItems.Count > 0 ? dgv.SelectedItems[0] : null)) ||
SelectMatched(dgv, 0))
{
RowDeselected(iRowBefore, dgvBefore);
SelectRow(dgv, iRowKey);
toClear = true;
}
#endif
}
}
else

View file

@ -45,7 +45,7 @@ namespace SystemTrayMenu.Business
private bool waitingForReactivate;
private int lastMouseDownRowIndex = -1;
private bool showMenuAfterMainPreload;
#if TODO
#if TODO // TOUCH
private int dragSwipeScrollingStartRowIndex = -1;
#endif
private bool isDraggingSwipeScrolling;
@ -258,7 +258,7 @@ namespace SystemTrayMenu.Business
waitToOpenMenu.MouseEnterOk += MouseEnterOk;
dgvMouseRow.RowMouseEnter += waitToOpenMenu.MouseEnter;
dgvMouseRow.RowMouseLeave += waitToOpenMenu.MouseLeave;
#if TODO
#if TODO // Misc MouseEvents
dgvMouseRow.RowMouseLeave += Dgv_RowMouseLeave;
#endif
@ -522,7 +522,7 @@ namespace SystemTrayMenu.Business
private static int GetRowUnderCursor(ListView dgv, Point location)
{
#if TODO
#if TODO // TOUCH
ListView.HitTestInfo myHitTest = dgv.HitTest(location.X, location.Y);
return myHitTest.RowIndex;
#else
@ -614,13 +614,13 @@ namespace SystemTrayMenu.Business
menu.AdjustControls(title, menuData.Validity);
menu.UserClickedOpenFolder += () => OpenFolder(path);
menu.Level = menuData.Level;
#if TODO
#if TODO // MouseWeel and Misc MouseEvents
menu.MouseWheel += AdjustMenusSizeAndLocation;
menu.MouseLeave += waitLeave.Start;
menu.MouseEnter += waitLeave.Stop;
#endif
menu.CmdKeyProcessed += keyboardInput.CmdKeyProcessed;
#if TODO
#if TODO // SEARCH
menu.KeyPressCheck += Menu_KeyPressCheck;
menu.SearchTextChanging += Menu_SearchTextChanging;
menu.SearchTextChanged += Menu_SearchTextChanged;
@ -672,15 +672,18 @@ namespace SystemTrayMenu.Business
menu.CellMouseDown += Dgv_MouseDown;
menu.CellMouseUp += Dgv_MouseUp;
menu.CellMouseClick += Dgv_MouseClick;
menu.CellMouseDoubleClick += Dgv_MouseDoubleClick;
#if TODO
ListView dgv = menu.GetDataGridView();
#if TODO // Misc MouseEvents
dgv.MouseLeave += dgvMouseRow.MouseLeave;
dgv.MouseLeave += Dgv_MouseLeave;
dgv.MouseMove += waitToOpenMenu.MouseMove;
#endif
#if TODO // TOUCH
dgv.MouseMove += Dgv_MouseMove;
dgv.MouseDoubleClick += Dgv_MouseDoubleClick;
#endif
dgv.SelectionChanged += Dgv_SelectionChanged;
#if TODO // BorderColors and PaintEvent
dgv.RowPostPaint += Dgv_RowPostPaint;
#endif
menu.SetCounts(foldersCount, filesCount);
@ -720,11 +723,11 @@ namespace SystemTrayMenu.Business
}
}
#if TODO // TOUCH
private void Dgv_MouseMove(object sender, MouseEventArgs e)
{
if (isDraggingSwipeScrolling)
{
#if TODO
ListView dgv = (ListView)sender;
int newRow = GetRowUnderCursor(dgv, e.Location);
if (newRow > -1)
@ -735,7 +738,6 @@ namespace SystemTrayMenu.Business
dragSwipeScrollingStartRowIndex += delta;
}
}
#endif
}
}
@ -744,7 +746,6 @@ namespace SystemTrayMenu.Business
bool scrolled = false;
if (delta != 0)
{
#if TODO
if (delta < 0 && dgv.FirstDisplayedScrollingRowIndex == 0)
{
delta = 0;
@ -763,11 +764,11 @@ namespace SystemTrayMenu.Business
dgv.FirstDisplayedScrollingRowIndex = newFirstDisplayedScrollingRowIndex;
scrolled = dgv.FirstDisplayedScrollingRowIndex == newFirstDisplayedScrollingRowIndex;
}
#endif
}
return scrolled;
}
#endif
private void Dgv_MouseDown(object sender, int index, MouseButtonEventArgs e)
{
@ -782,7 +783,7 @@ namespace SystemTrayMenu.Business
{
lastMouseDownRowIndex = index;
}
#if TODO
#if TODO // TOUCH
Menu menu = (Menu)((ListView)sender).GetParentWindow();
if (menu != null && menu.ScrollbarVisible)
{
@ -829,7 +830,7 @@ namespace SystemTrayMenu.Business
keyboardInput.Select(dgv, rowIndex, refreshView);
}
}
#if TODO
#if TODO // Misc MouseEvents
private void Dgv_RowMouseLeave(object sender, DataGridViewCellEventArgs e)
{
ListView dgv = (ListView)sender;
@ -840,7 +841,7 @@ namespace SystemTrayMenu.Business
e.RowIndex < dgv.Items.Count)
{
lastMouseDownRowIndex = -1;
#if TODO
RowData rowData = (RowData)dgv.Items[e.RowIndex].Cells[2].Value;
string[] files = new string[] { rowData.Path };
@ -848,41 +849,33 @@ namespace SystemTrayMenu.Business
Cursor.Position = new Point(Cursor.Position.X, Cursor.Position.Y);
dgv.DoDragDrop(new DataObject(DataFormats.FileDrop, files), DragDropEffects.Copy);
#endif
}
}
#endif
private void Dgv_MouseClick(object sender, int index, MouseButtonEventArgs e)
private void Dgv_MouseClick(ListView sender, int index, MouseButtonEventArgs e)
{
if (!isDragSwipeScrolled)
bool doClose = false;
if (e.ClickCount == 1)
{
ListView dgv = (ListView)sender;
lastMouseDownRowIndex = -1;
// TODO WPF: Move directly into ListViewxItem_PreviewMouseLeftButtonDown ?
((Menu.ListViewItemData)dgv.Items[index]).data.MouseClick(e, out bool toCloseByClick);
waitToOpenMenu.ClickOpensInstantly(dgv, index);
if (toCloseByClick)
if (!isDragSwipeScrolled)
{
MenusFadeOut();
lastMouseDownRowIndex = -1;
((Menu.ListViewItemData)sender.Items[index]).data.MouseClick(e, out doClose);
waitToOpenMenu.ClickOpensInstantly(sender, index);
}
}
else if (e.ClickCount == 2)
{
lastMouseDownRowIndex = -1;
lastMouseDownRowIndex = -1;
}
((Menu.ListViewItemData)sender.Items[index]).data.DoubleClick(e, out doClose);
}
private void Dgv_MouseDoubleClick(object sender, int index, MouseButtonEventArgs e)
{
ListView dgv = (ListView)sender;
lastMouseDownRowIndex = -1;
// TODO WPF: Move directly into ListViewItem_MouseDoubleClick ?
((Menu.ListViewItemData)dgv.Items[index]).data.DoubleClick(e, out bool toCloseByDoubleClick);
if (toCloseByDoubleClick)
if (doClose)
{
MenusFadeOut();
}
@ -909,14 +902,14 @@ namespace SystemTrayMenu.Business
}
else if (!menus[0].IsUsable)
{
#if TODO
#if TODO // Colors
row.DefaultCellStyle.SelectionBackColor = Color.White;
#endif
dgv.SelectedItems.Remove(row);
}
else if (rowData.IsClicking)
{
#if TODO
#if TODO // Colors
row.DefaultCellStyle.SelectionBackColor = MenuDefines.ColorIcons;
#endif
dgv.SelectedItems.Add(row);
@ -931,14 +924,14 @@ namespace SystemTrayMenu.Business
}
else if (rowData.IsSelected)
{
#if TODO
#if TODO // Colors
row.DefaultCellStyle.SelectionBackColor = MenuDefines.ColorSelectedItem;
#endif
dgv.SelectedItems.Add(row);
}
else
{
#if TODO
#if TODO // Colors
row.DefaultCellStyle.SelectionBackColor = Color.White;
#endif
dgv.SelectedItems.Remove(row);
@ -953,7 +946,7 @@ namespace SystemTrayMenu.Business
}
}
#if TODO
#if TODO // BorderColors and PaintEvent
private void Dgv_RowPostPaint(object sender, DataGridViewRowPostPaintEventArgs e)
{
ListView dgv = (ListView)sender;
@ -1186,7 +1179,7 @@ namespace SystemTrayMenu.Business
}
}
#if TODO
#if TODO // Misc MouseEvents and TOUCH
private void Menu_KeyPressCheck(object sender, KeyPressEventArgs e)
{
if (isDraggingSwipeScrolling)

View file

@ -5,12 +5,9 @@
namespace SystemTrayMenu.Handler
{
using System;
using System.Data;
using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Threading;
using SystemTrayMenu.DataClasses;
using SystemTrayMenu.UserInterface;
using SystemTrayMenu.Utilities;
using static SystemTrayMenu.UserInterface.Menu;
using ListView = System.Windows.Controls.ListView;
@ -47,7 +44,7 @@ namespace SystemTrayMenu.Handler
public void Dispose()
{
timerStartLoad.Stop();
#if TODO
#if TODO // WPF: Can be optimized away?
dgv?.Dispose();
dgvTmp?.Dispose();
#endif
@ -139,7 +136,7 @@ namespace SystemTrayMenu.Handler
{
MouseActive = true;
if (dgvTmp != null
#if TODO
#if TODO // WPF: Can be optimized away?
&& !dgvTmp.IsDisposed
#endif
)

View file

@ -77,7 +77,7 @@ namespace SystemTrayMenu.Helper
if (disposing)
{
timerRaiseRowMouseLeave.Stop();
#if TODO
#if TODO // WPF: Can be optimized away?
senderObject?.Dispose();
#endif
}

View file

@ -69,7 +69,7 @@ namespace SystemTrayMenu.UserInterface
ColorChanged?.Invoke(this);
}
#if TODO
#if TODO // ColorPicker
private void PictureBoxClick(object sender, EventArgs e)
{
PictureBox pictureBox = (PictureBox)sender;

View file

@ -95,7 +95,7 @@
<sys:Double x:Key="ColumnTextWidth">60</sys:Double>
</Window.Resources>
<Border x:Name="windowFrame" BorderBrush="#FF000000" BorderThickness="1" CornerRadius="0" Background="White" HorizontalAlignment="Center" VerticalAlignment="Center">
<Border x:Name="windowFrame" BorderBrush="#FF000000" BorderThickness="1" CornerRadius="0" Background="White">
<DockPanel x:Name="tableLayoutPanelMenu">
<Label x:Name="labelTitle" DockPanel.Dock="Top" HorizontalContentAlignment="Center" Padding="1" Margin="6,0" FontWeight="Bold" HorizontalAlignment="Center" VerticalAlignment="Center">
<TextBlock x:Name="txtTitle" TextTrimming="CharacterEllipsis" Margin="14,0"><Run Text="title"/></TextBlock>
@ -162,7 +162,6 @@
<EventSetter Event="PreviewMouseDown" Handler="ListViewItem_PreviewMouseDown" />
<EventSetter Event="MouseUp" Handler="ListViewItem_MouseUp" />
<EventSetter Event="PreviewMouseLeftButtonDown" Handler="ListViewxItem_PreviewMouseLeftButtonDown" />
<EventSetter Event="MouseDoubleClick" Handler="ListViewItem_MouseDoubleClick" />
</Style>
</ListView.ItemContainerStyle>
</ListView>

View file

@ -27,7 +27,7 @@ namespace SystemTrayMenu.UserInterface
/// </summary>
public partial class Menu : Window
{
#if TODO
#if TODO // SEARCH
public const string RowFilterShowAll = "[SortIndex] LIKE '%0%'";
#endif
private const int CornerRadius = 10;
@ -37,7 +37,7 @@ namespace SystemTrayMenu.UserInterface
private bool directionToRight;
private bool mouseDown;
private Point lastLocation;
#if TODO
#if TODO // SEARCH
private bool isSetSearchText;
private bool dgvHeightSet;
#endif
@ -133,7 +133,7 @@ namespace SystemTrayMenu.UserInterface
MouseDown += Menu_MouseDown;
MouseUp += Menu_MouseUp;
MouseMove += Menu_MouseMove;
#if TODO
#if TODO // MouseWeel
labelTitle.MouseWheel += new MouseEventHandler(DgvMouseWheel);
#endif
SolidColorBrush foreColor = new(Colors.Black);
@ -160,7 +160,7 @@ namespace SystemTrayMenu.UserInterface
panelLine.Background = AppColors.Icons.ToSolidColorBrush();
dgv.GotFocus += (_, _) => FocusTextBox();
#if TODO
#if TODO // Misc MouseEvents
dgv.MouseEnter += ControlsMouseEnter;
labelTitle.MouseEnter += ControlsMouseEnter;
textBoxSearch.MouseEnter += ControlsMouseEnter;
@ -194,7 +194,8 @@ namespace SystemTrayMenu.UserInterface
{
MouseLeave?.Invoke();
}
#endif
#if TODO // TOUCH
bool isTouchEnabled = NativeMethods.IsTouchEnabled();
if ((isTouchEnabled && Properties.Settings.Default.DragDropItemsEnabledTouch) ||
(!isTouchEnabled && Properties.Settings.Default.DragDropItemsEnabled))
@ -223,7 +224,7 @@ namespace SystemTrayMenu.UserInterface
};
}
#if TODO
#if TODO // MouseWeel and Misc MouseEvents
internal new event Action MouseWheel;
internal new event Action MouseEnter;
@ -234,7 +235,7 @@ namespace SystemTrayMenu.UserInterface
internal event Action? UserClickedOpenFolder;
internal event Action<Menu, Key, ModifierKeys> CmdKeyProcessed;
#if TODO
#if TODO // SEARCH
internal event EventHandler<KeyPressEventArgs> KeyPressCheck;
@ -257,8 +258,6 @@ namespace SystemTrayMenu.UserInterface
internal event Action<ListView, int, MouseButtonEventArgs>? CellMouseClick;
internal event Action<ListView, int, MouseButtonEventArgs>? CellMouseDoubleClick;
internal enum MenuType
{
/// <summary>
@ -314,7 +313,7 @@ namespace SystemTrayMenu.UserInterface
internal bool IsUsable => Visibility == Visibility.Visible && !fading.IsHiding && !IsDisposed && !Disposing;
#if TODO
#if TODO // TOUCH
internal bool ScrollbarVisible { get; private set; }
private ListView tableLayoutPanelDgvAndScrollbar => dgv; // TODO WPF Remove and replace with dgv
@ -339,7 +338,7 @@ namespace SystemTrayMenu.UserInterface
internal void FocusTextBox()
{
#if TODO
#if TODO // SEARCH
if (isSetSearchText)
{
isSetSearchText = false;
@ -429,7 +428,7 @@ namespace SystemTrayMenu.UserInterface
if (!string.IsNullOrEmpty(userSearchText))
{
textBoxSearch.Text = userSearchText + "*";
#if TODO
#if TODO // SEARCH
isSetSearchText = true;
#endif
}
@ -746,12 +745,15 @@ namespace SystemTrayMenu.UserInterface
{
windowFrame.CornerRadius = new CornerRadius(CornerRadius);
}
// Keep its size when once created.
SizeToContent = SizeToContent.Manual;
};
}
internal void ResetHeight()
{
#if TODO
#if TODO // SEARCH
dgvHeightSet = false;
#endif
}
@ -841,18 +843,18 @@ namespace SystemTrayMenu.UserInterface
dgv.Tag = true;
}
#if TODO
#if TODO // SEARCH
if (!dgvHeightSet && dgvHeightByItems > 0 && dgvHeightMax > 0)
{
#endif
double heightMaxByOptions = Scaling.Factor * Scaling.FactorByDpi *
450f * (Properties.Settings.Default.HeightMaxInPercent / 100f);
MaxHeight = Math.Min(screenHeightMax, heightMaxByOptions);
#if TODO
#if TODO // SEARCH
dgvHeightSet = true;
}
#endif
#if TODO
#if TODO // SEARCH and TOUCH
if (dgvHeightByItems > dgvHeightMax)
{
ScrollbarVisible = true;
@ -920,13 +922,14 @@ namespace SystemTrayMenu.UserInterface
((CollectionView)CollectionViewSource.GetDefaultView(dgv.ItemsSource)).Filter = null;
}
#if TODO
#if TODO // MouseWheel
private void DgvMouseWheel(object sender, MouseEventArgs e)
{
((HandledMouseEventArgs)e).Handled = true;
MouseWheel?.Invoke();
}
#endif
#if TODO // SEARCH
private void TextBoxSearch_KeyPress(object sender, KeyPressEventArgs e)
{
KeyPressCheck?.Invoke(sender, e);
@ -934,11 +937,11 @@ namespace SystemTrayMenu.UserInterface
#endif
private void TextBoxSearch_TextChanged()
{
#if TODO
#if TODO // SEARCH
DataTable data = (DataTable)dgv.DataSource;
#endif
string filterField = nameof(ListViewItemData.ColumnText);
#if TODO
#if TODO // SEARCH
SearchTextChanging?.Invoke();
// Expression reference: https://docs.microsoft.com/en-us/dotnet/api/system.data.datacolumn.expression?view=net-6.0
@ -996,7 +999,7 @@ namespace SystemTrayMenu.UserInterface
return row.ColumnText.Contains(textBoxSearch.Text.Trim()); // TODO: THIS IS JUST TEMPORARY DUMMY FILTER (see below)
}
}
#if TODO
#if TODO // SEARCH
try
{
if (Properties.Settings.Default.ShowOnlyAsSearchResult &&
@ -1104,7 +1107,7 @@ namespace SystemTrayMenu.UserInterface
}
#endif
}
#if TODO
#if TODO // Misc MouseEvents and BorderColors
private void PictureBox_MouseEnter(object sender, EventArgs e)
{
@ -1145,7 +1148,7 @@ namespace SystemTrayMenu.UserInterface
UserClickedOpenFolder?.Invoke();
}
#if TODO
#if TODO // BorderColors
private void PictureBoxMenuAlwaysOpen_Paint(object sender, PaintEventArgs e)
{
PictureBox pictureBox = (PictureBox)sender;
@ -1169,7 +1172,7 @@ namespace SystemTrayMenu.UserInterface
}
}
#if TODO
#if TODO // BorderColors
private void PictureBoxSettings_Paint(object sender, PaintEventArgs e)
{
PictureBox pictureBox = (PictureBox)sender;
@ -1188,7 +1191,7 @@ namespace SystemTrayMenu.UserInterface
SettingsWindow.ShowSingleInstance();
}
#if TODO
#if TODO // BorderColors
private void PictureBoxRestart_Paint(object sender, PaintEventArgs e)
{
PictureBox pictureBox = (PictureBox)sender;
@ -1207,7 +1210,7 @@ namespace SystemTrayMenu.UserInterface
AppRestart.ByMenuButton();
}
#if TODO
#if TODO // BorderColors
private void PictureBoxSearch_Paint(object sender, PaintEventArgs e)
{
PictureBox pictureBox = (PictureBox)sender;
@ -1278,35 +1281,27 @@ namespace SystemTrayMenu.UserInterface
private void ListViewItem_MouseEnter(object sender, MouseEventArgs e)
{
CellMouseEnter?.Invoke(dgv, dgv.Items.IndexOf(((ListViewItem)sender).Content));
CellMouseEnter?.Invoke(dgv, dgv.IndexOfSenderItem((ListViewItem)sender));
}
private void ListViewItem_MouseLeave(object sender, MouseEventArgs e)
{
CellMouseLeave?.Invoke(dgv, dgv.Items.IndexOf(((ListViewItem)sender).Content));
CellMouseLeave?.Invoke(dgv, dgv.IndexOfSenderItem((ListViewItem)sender));
}
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
CellMouseDown?.Invoke(dgv, dgv.IndexOfSenderItem((ListViewItem)sender), e);
}
private void ListViewItem_MouseUp(object sender, MouseButtonEventArgs e)
{
CellMouseUp?.Invoke(dgv, dgv.Items.IndexOf(((ListViewItem)sender).Content), e);
CellMouseUp?.Invoke(dgv, dgv.IndexOfSenderItem((ListViewItem)sender), e);
}
private void ListViewxItem_PreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
// Simulate missing MouseClick event
CellMouseClick?.Invoke(dgv, dgv.Items.IndexOf(((ListViewItem)sender).Content), e);
}
private void ListViewItem_MouseDoubleClick(object sender, MouseButtonEventArgs e)
{
CellMouseDoubleClick?.Invoke(dgv, dgv.Items.IndexOf(((ListViewItem)sender).Content), e);
CellMouseClick?.Invoke(dgv, dgv.IndexOfSenderItem((ListViewItem)sender), e);
}
/// <summary>

View file

@ -29,7 +29,7 @@ namespace SystemTrayMenu.UserInterface
private const string Command = @"Software\Classes\directory\shell\SystemTrayMenu_SetAsRootFolder\command";
private static SettingsWindow? settingsForm;
#if TODO
#if TODO // HOTKEY
private bool inHotkey;
#endif
public SettingsWindow()
@ -51,7 +51,7 @@ namespace SystemTrayMenu.UserInterface
Icon = imageSource;
}
}
#if TODO
#if TODO // HOTKEY
// Initialize and replace here here, because designer always removes it
InitializeTextBoxHotkeyAndReplacetextBoxHotkeyPlaceholder();
void InitializeTextBoxHotkeyAndReplacetextBoxHotkeyPlaceholder()
@ -105,7 +105,7 @@ namespace SystemTrayMenu.UserInterface
}
checkBoxCheckForUpdates.IsChecked = Settings.Default.CheckForUpdates;
#if TODO
#if TODO // HOTKEY
textBoxHotkey.SetHotkey(Settings.Default.HotKey);
#endif
@ -376,7 +376,7 @@ namespace SystemTrayMenu.UserInterface
Closed += (_, _) => settingsForm = null;
}
#if TODO
#if TODO // HOTKEY
/// <summary>
/// Gets NewHotKey.
/// </summary>
@ -416,7 +416,7 @@ namespace SystemTrayMenu.UserInterface
return settingsForm != null;
}
#if TODO
#if TODO // HOTKEY
protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
{
switch (keyData)
@ -671,7 +671,7 @@ namespace SystemTrayMenu.UserInterface
Settings.Default.CheckForUpdates = checkBoxCheckForUpdates.IsChecked ?? false;
#if TODO
#if TODO // HOTKEY
Settings.Default.HotKey = new KeysConverter().ConvertToInvariantString(textBoxHotkey.Hotkey | textBoxHotkey.HotkeyModifiers);
Settings.Default.CurrentCultureInfoName = comboBoxLanguage.SelectedValue.ToString();
#endif
@ -903,7 +903,7 @@ namespace SystemTrayMenu.UserInterface
}
}
#if TODO
#if TODO // HOTKEY
private void TextBoxHotkeyEnter(object sender, EventArgs e)
{
UnregisterHotkeys();
@ -921,7 +921,7 @@ namespace SystemTrayMenu.UserInterface
#endif
private void ButtonHotkeyDefault_Click(object sender, RoutedEventArgs e)
{
#if TODO
#if TODO // HOTKEY
textBoxHotkey.SetHotkey("Ctrl+LWin");
#endif
}

View file

@ -8,6 +8,7 @@
namespace SystemTrayMenu.Utilities
{
using System;
using System.Drawing;
using System.Globalization;
using System.Windows;
@ -29,6 +30,28 @@ namespace SystemTrayMenu.Utilities
return (Window)parent;
}
internal static int IndexOfSenderItem(this ListView listView, ListViewItem sender)
{
int index = listView.Items.IndexOf(sender.Content);
if (index < 0)
{
// Most likely the sender object is a "DiconnectedItem"
// Needs to be confirmed:
// May happen when focus gets lost while event is handled
// As this has not occurred on files but on folders
// that spawns a new menu window which will get focus
// it may be caused by the loss of focus.
// Workaround:
// If possible take index from selection
// we simply assume it is the first one.
// Otherwise fall back to index 0 which shall always work
// because there must be anything that has sent something.
index = Math.Min(listView.SelectedIndex, 0);
}
return index;
}
internal static T? FindVisualChildOfType<T>(this DependencyObject depObj, int index = 0)
where T : DependencyObject
{