[BUG] Fix issue when empty main menu and right click into it (#338, #361), version 1.2.8.9

This commit is contained in:
Markus Hofknecht 2022-02-21 17:25:31 +01:00
parent a9f3308b27
commit 3c0ed17988
5 changed files with 18 additions and 72 deletions

View file

@ -168,27 +168,6 @@ namespace SystemTrayMenu.Handler
}
}
/// <summary>
/// While menu is open user presses a key to search for specific entries.
/// </summary>
/// <param name="sender">not used.</param>
/// <param name="e">Key data of the pressed key.</param>
internal void KeyPress(object sender, KeyPressEventArgs e)
{
if (char.IsLetterOrDigit(e.KeyChar) ||
char.IsPunctuation(e.KeyChar) ||
char.IsWhiteSpace(e.KeyChar) ||
char.IsSeparator(e.KeyChar))
{
string letter = e.KeyChar.ToString(CultureInfo.InvariantCulture);
Menu menu = menus[iMenuKey];
menu.KeyPressedSearch(letter);
e.Handled = true;
}
}
internal void SearchTextChanging()
{
ClearIsSelectedByKey();
@ -582,10 +561,13 @@ namespace SystemTrayMenu.Handler
if (dgv.Rows.Count > rowIndex)
{
DataGridViewRow row = dgv.Rows[rowIndex];
RowData rowData = (RowData)row.Cells[2].Value;
rowData.IsSelected = false;
row.Selected = false;
rowData.IsClicking = false;
RowData rowData = (RowData)row.Cells[2].Value;
if (rowData != null)
{
rowData.IsSelected = false;
rowData.IsClicking = false;
}
}
}
}

View file

@ -630,7 +630,6 @@ namespace SystemTrayMenu.Business
menuToDispose.MouseWheel -= AdjustMenusSizeAndLocation;
menuToDispose.MouseLeave -= waitLeave.Start;
menuToDispose.MouseEnter -= waitLeave.Stop;
menuToDispose.KeyPress -= keyboardInput.KeyPress;
menuToDispose.CmdKeyProcessed -= keyboardInput.CmdKeyProcessed;
menuToDispose.SearchTextChanging -= keyboardInput.SearchTextChanging;
menuToDispose.KeyPressCheck -= Menu_KeyPressCheck;
@ -896,7 +895,6 @@ namespace SystemTrayMenu.Business
menu.MouseWheel += AdjustMenusSizeAndLocation;
menu.MouseLeave += waitLeave.Start;
menu.MouseEnter += waitLeave.Stop;
menu.KeyPress += keyboardInput.KeyPress;
menu.CmdKeyProcessed += keyboardInput.CmdKeyProcessed;
menu.KeyPressCheck += Menu_KeyPressCheck;
menu.SearchTextChanging += Menu_SearchTextChanging;

View file

@ -39,5 +39,5 @@ using System.Runtime.InteropServices;
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.2.8.8")]
[assembly: AssemblyFileVersion("1.2.8.8")]
[assembly: AssemblyVersion("1.2.8.9")]
[assembly: AssemblyFileVersion("1.2.8.9")]

View file

@ -12,18 +12,13 @@ namespace SystemTrayMenu.UserInterface
internal class AppNotifyIcon : IDisposable
{
private readonly Timer load = new();
private readonly NotifyIcon notifyIcon = new();
private bool threadsLoading;
public AppNotifyIcon()
{
notifyIcon.Icon = Resources.StaticResources.LoadingIcon;
load.Tick += Load_Tick;
load.Interval = 15;
notifyIcon.Text = Translator.GetText("SystemTrayMenu");
notifyIcon.Visible = true;
notifyIcon.Icon = Config.GetAppIcon();
notifyIcon.Visible = true;
AppContextMenu contextMenus = new();
@ -55,19 +50,16 @@ namespace SystemTrayMenu.UserInterface
{
notifyIcon.Icon = null;
notifyIcon.Dispose();
load.Dispose();
}
public void LoadingStart()
{
threadsLoading = true;
load.Start();
notifyIcon.Icon = Resources.StaticResources.LoadingIcon;
}
public void LoadingStop()
{
Cursor.Current = Cursors.Default;
threadsLoading = false;
notifyIcon.Icon = Config.GetAppIcon();
}
private void VerifyClick(MouseEventArgs e)
@ -77,26 +69,5 @@ namespace SystemTrayMenu.UserInterface
Click?.Invoke();
}
}
private void Load_Tick(object sender, EventArgs e)
{
if (threadsLoading)
{
notifyIcon.Icon = Resources.StaticResources.LoadingIcon;
// see #361, rotating icon caused rare GDI+ exception at GetHicon
// rotationAngle += 5;
// using Bitmap bitmapLoading = Resources.StaticResources.LoadingIcon.ToBitmap();
// using Bitmap bitmapLoadingRotated = new(ImagingHelper.RotateImage(bitmapLoading, rotationAngle));
// IntPtr hIcon = bitmapLoadingRotated.GetHicon();
// notifyIcon.Icon = (Icon)Icon.FromHandle(hIcon).Clone();
// DllImports.NativeMethods.User32DestroyIcon(hIcon);
}
else
{
notifyIcon.Icon = Config.GetAppIcon();
load.Stop();
}
}
}
}

View file

@ -569,20 +569,15 @@ namespace SystemTrayMenu.UserInterface
}
}
internal void KeyPressedSearch(string letter)
{
textBoxSearch.Text += letter;
textBoxSearch.SelectionStart = textBoxSearch.Text.Length;
textBoxSearch.SelectionLength = 0;
textBoxSearch.Focus();
}
internal void AdjustScrollbar()
{
customScrollbar.Value = (int)Math.Round(
dgv.FirstDisplayedScrollingRowIndex * (decimal)customScrollbar.Maximum / dgv.Rows.Count,
0,
MidpointRounding.AwayFromZero);
if (dgv.Rows.Count > 0)
{
customScrollbar.Value = (int)Math.Round(
dgv.FirstDisplayedScrollingRowIndex * (decimal)customScrollbar.Maximum / dgv.Rows.Count,
0,
MidpointRounding.AwayFromZero);
}
}
internal void SetCounts(int foldersCount, int filesCount)