Skip to content

Commit

Permalink
[BUG] Fix issue when empty main menu and right click into it (#338, #361
Browse files Browse the repository at this point in the history
), version 1.2.8.9
Hofknecht committed Feb 21, 2022
1 parent a9f3308 commit 3c0ed17
Showing 5 changed files with 18 additions and 72 deletions.
30 changes: 6 additions & 24 deletions Business/KeyboardInput.cs
Original file line number Diff line number Diff line change
@@ -168,27 +168,6 @@ int GetMenuIndex(in Menu currentMenu)
}
}

/// <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 @@ private void ClearIsSelectedByKey(int menuIndex, int rowIndex)
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;
}
}
}
}
2 changes: 0 additions & 2 deletions Business/Menus.cs
Original file line number Diff line number Diff line change
@@ -630,7 +630,6 @@ internal void DisposeMenu(Menu menuToDispose)
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 @@ private Menu Create(MenuData menuData, string title = null)
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;
4 changes: 2 additions & 2 deletions Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -39,5 +39,5 @@
// 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")]
35 changes: 3 additions & 32 deletions UserInterface/AppNotifyIcon.cs
Original file line number Diff line number Diff line change
@@ -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 @@ public void Dispose()
{
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 @@ private void VerifyClick(MouseEventArgs e)
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();
}
}
}
}
19 changes: 7 additions & 12 deletions UserInterface/Menu.cs
Original file line number Diff line number Diff line change
@@ -569,20 +569,15 @@ internal void AdjustSizeAndLocation(
}
}

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)

0 comments on commit 3c0ed17

Please sign in to comment.