Skip to content

Commit 515d8f8

Browse files
committed
work around menu close sometimes not firing
1 parent bc781e9 commit 515d8f8

File tree

2 files changed

+5
-18
lines changed

2 files changed

+5
-18
lines changed

src/DiffEngineTray/MenuBuilder.cs

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6,23 +6,20 @@
66

77
static class MenuBuilder
88
{
9-
static List<ToolStripItem>? itemsToCleanup;
10-
119
public static ContextMenuStrip Build(Action exit, Action launchOptions, Tracker tracker)
1210
{
1311
var menu = new ContextMenuStrip();
1412
var items = menu.Items;
1513
menu.Opening += delegate
1614
{
17-
DisposePreviousItems();
15+
DisposePreviousItems(items);
1816

1917
foreach (var item in BuildTrackingMenuItems(tracker))
2018
{
2119
items.Add(item);
2220
}
2321
};
2422
menu.Font = new Font(menu.Font.FontFamily, 10);
25-
menu.Closed += delegate { CleanTransientMenus(items); };
2623
items.Add(new MenuButton("Exit", exit, Images.Exit));
2724
items.Add(new MenuButton("Options", launchOptions, Images.Options));
2825
items.Add(new MenuButton("Open logs", Logging.OpenDirectory, Images.Folder));
@@ -40,25 +37,15 @@ static List<ToolStripItem> NonDefaultMenus(ToolStripItemCollection items)
4037
.ToList();
4138
}
4239

43-
static void DisposePreviousItems()
40+
static void DisposePreviousItems(ToolStripItemCollection items)
4441
{
45-
if (itemsToCleanup == null)
46-
{
47-
return;
48-
}
49-
50-
foreach (var item in itemsToCleanup)
42+
foreach (var item in NonDefaultMenus(items))
5143
{
44+
items.Remove(item);
5245
item.Dispose();
5346
}
5447
}
5548

56-
static void CleanTransientMenus(ToolStripItemCollection items)
57-
{
58-
itemsToCleanup = NonDefaultMenus(items);
59-
items.RemoveRange(itemsToCleanup);
60-
}
61-
6249
static IEnumerable<ToolStripItem> BuildTrackingMenuItems(Tracker tracker)
6350
{
6451
if (!tracker.TrackingAny)

src/Directory.Build.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<Project>
33
<PropertyGroup>
44
<NoWarn>CS1591;CS0649</NoWarn>
5-
<Version>6.1.1</Version>
5+
<Version>6.1.2</Version>
66
<AssemblyVersion>1.0.0</AssemblyVersion>
77
<PackageTags>Testing, Snapshot, Diff, Compare</PackageTags>
88
<Description>Launches diff tools based on file extensions. Designed to be consumed by snapshot testing libraries.</Description>

0 commit comments

Comments
 (0)