Skip to content

Commit 3344148

Browse files
authored
Enabled the "Open linux shell here" context menu item (#2004)
1 parent 6e3103c commit 3344148

File tree

2 files changed

+10
-7
lines changed

2 files changed

+10
-7
lines changed

Files.Launcher/Program.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -341,7 +341,7 @@ private static Func<string, bool> FilterMenuItems(bool showOpenMenu)
341341
"opennew", "openas", "opencontaining", "opennewprocess",
342342
"runas", "runasuser", "pintohome", "PinToStartScreen",
343343
"cut", "copy", "paste", "delete", "properties", "link",
344-
"WSL", "Windows.ModernShare", "Windows.Share", "setdesktopwallpaper",
344+
"Windows.ModernShare", "Windows.Share", "setdesktopwallpaper",
345345
Win32API.ExtractStringFromDLL("shell32.dll", 30312), // SendTo menu
346346
Win32API.ExtractStringFromDLL("shell32.dll", 34593), // Add to collection
347347
};

Files.Launcher/Win32API_ContextMenu.cs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -129,10 +129,12 @@ public void Dispose()
129129
public class ContextMenu : Win32ContextMenu, IDisposable
130130
{
131131
private Shell32.IContextMenu cMenu;
132+
private User32.SafeHMENU hMenu;
132133

133-
public ContextMenu(Shell32.IContextMenu cMenu)
134+
public ContextMenu(Shell32.IContextMenu cMenu, User32.SafeHMENU hMenu)
134135
{
135136
this.cMenu = cMenu;
137+
this.hMenu = hMenu;
136138
this.Items = new List<Win32ContextMenuItem>();
137139
}
138140

@@ -203,11 +205,10 @@ public static ContextMenu GetContextMenuForFiles(ShellItem[] shellItems, Shell32
203205
return null;
204206
using var sf = shellItems.First().Parent; // HP: the items are all in the same folder
205207
Shell32.IContextMenu menu = sf.GetChildrenUIObjects<Shell32.IContextMenu>(null, shellItems);
206-
var contextMenu = new ContextMenu(menu);
207208
var hMenu = User32.CreatePopupMenu();
208209
menu.QueryContextMenu(hMenu, 0, 1, 0x7FFF, flags);
210+
var contextMenu = new ContextMenu(menu, hMenu);
209211
ContextMenu.EnumMenuItems(menu, hMenu, contextMenu.Items, itemFilter);
210-
User32.DestroyMenu(hMenu);
211212
return contextMenu;
212213
}
213214

@@ -264,9 +265,6 @@ private static void EnumMenuItems(
264265
try
265266
{
266267
(cMenu as Shell32.IContextMenu2)?.HandleMenuMsg((uint)User32.WindowMessage.WM_INITMENUPOPUP, (IntPtr)mii.hSubMenu, new IntPtr(ii));
267-
// Skip this items, clicking on them probably won't work
268-
container.Dispose();
269-
continue;
270268
}
271269
catch (NotImplementedException)
272270
{
@@ -366,6 +364,11 @@ protected virtual void Dispose(bool disposing)
366364
}
367365

368366
// TODO: free unmanaged resources (unmanaged objects) and override a finalizer below.
367+
if (hMenu != null)
368+
{
369+
User32.DestroyMenu(hMenu);
370+
hMenu = null;
371+
}
369372
if (cMenu != null)
370373
{
371374
Marshal.ReleaseComObject(cMenu);

0 commit comments

Comments
 (0)