Skip to content

Commit e5e6f21

Browse files
committed
Code Quality: Removed Vanara.PInvoke.Shell32.CMF import
1 parent 08ab494 commit e5e6f21

File tree

4 files changed

+30
-11
lines changed

4 files changed

+30
-11
lines changed

src/Files.App/Data/Factories/ShellContextFlyoutHelper.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,8 @@
99
using Microsoft.UI.Xaml.Controls;
1010
using Microsoft.UI.Xaml.Media.Imaging;
1111
using System.IO;
12-
using Vanara.PInvoke;
1312
using Windows.System;
1413
using Windows.UI.Core;
15-
using static Vanara.PInvoke.Kernel32;
1614

1715
namespace Files.App.Helpers
1816
{
@@ -55,7 +53,7 @@ bool filterMenuItemsImpl(string menuItem) => !string.IsNullOrEmpty(menuItem)
5553
}
5654

5755
var contextMenu = await ContextMenu.GetContextMenuForFiles(filePaths,
58-
shiftPressed ? Shell32.CMF.CMF_EXTENDEDVERBS : Shell32.CMF.CMF_NORMAL, FilterMenuItems(showOpenMenu));
56+
shiftPressed ? CMF.CMF_EXTENDEDVERBS : CMF.CMF_NORMAL, FilterMenuItems(showOpenMenu));
5957

6058
if (contextMenu is not null)
6159
LoadMenuFlyoutItem(menuItemsList, contextMenu, contextMenu.Items, cancellationToken, true);

src/Files.App/Data/Items/ContextMenu.cs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,27 @@ public enum HBITMAP_HMENU : long
3232
HBMMENU_SYSTEM = 1
3333
}
3434

35+
// Same definition of Vanara.PInvoke.Shell32.CMF
36+
public enum CMF : uint
37+
{
38+
CMF_NORMAL = 0x00000000,
39+
CMF_DEFAULTONLY = 0x00000001,
40+
CMF_VERBSONLY = 0x00000002,
41+
CMF_EXPLORE = 0x00000004,
42+
CMF_NOVERBS = 0x00000008,
43+
CMF_CANRENAME = 0x00000010,
44+
CMF_NODEFAULT = 0x00000020,
45+
CMF_EXTENDEDVERBS = 0x00000100,
46+
CMF_INCLUDESTATIC = 0x00000040,
47+
CMF_ITEMMENU = 0x00000080,
48+
CMF_DISABLEDVERBS = 0x00000200,
49+
CMF_ASYNCVERBSTATE = 0x00000400,
50+
CMF_OPTIMIZEFORINVOKE = 0x00000800,
51+
CMF_SYNCCASCADEMENU = 0x00001000,
52+
CMF_DONOTPICKDEFAULT = 0x00002000,
53+
CMF_RESERVED = 0xffff0000,
54+
}
55+
3556
public class Win32ContextMenu
3657
{
3758
public List<Win32ContextMenuItem> Items { get; set; }

src/Files.App/Utils/Shell/ContextMenu.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ private ContextMenu(Shell32.IContextMenu cMenu, User32.SafeHMENU hMenu, IEnumera
4343

4444
public async static Task<bool> InvokeVerb(string verb, params string[] filePaths)
4545
{
46-
using var cMenu = await GetContextMenuForFiles(filePaths, Shell32.CMF.CMF_DEFAULTONLY);
46+
using var cMenu = await GetContextMenuForFiles(filePaths, CMF.CMF_DEFAULTONLY);
4747

4848
return cMenu is not null && await cMenu.InvokeVerb(verb);
4949
}
@@ -112,7 +112,7 @@ public async Task<bool> InvokeItem(int itemID)
112112
return false;
113113
}
114114

115-
public async static Task<ContextMenu?> GetContextMenuForFiles(string[] filePathList, Shell32.CMF flags, Func<string, bool>? itemFilter = null)
115+
public async static Task<ContextMenu?> GetContextMenuForFiles(string[] filePathList, CMF flags, Func<string, bool>? itemFilter = null)
116116
{
117117
var owningThread = new ThreadWithMessageQueue();
118118

@@ -140,14 +140,14 @@ public async Task<bool> InvokeItem(int itemID)
140140
});
141141
}
142142

143-
public async static Task<ContextMenu?> GetContextMenuForFiles(ShellItem[] shellItems, Shell32.CMF flags, Func<string, bool>? itemFilter = null)
143+
public async static Task<ContextMenu?> GetContextMenuForFiles(ShellItem[] shellItems, CMF flags, Func<string, bool>? itemFilter = null)
144144
{
145145
var owningThread = new ThreadWithMessageQueue();
146146

147147
return await owningThread.PostMethod<ContextMenu>(() => GetContextMenuForFiles(shellItems, flags, owningThread, itemFilter));
148148
}
149149

150-
private static ContextMenu? GetContextMenuForFiles(ShellItem[] shellItems, Shell32.CMF flags, ThreadWithMessageQueue owningThread, Func<string, bool>? itemFilter = null)
150+
private static ContextMenu? GetContextMenuForFiles(ShellItem[] shellItems, CMF flags, ThreadWithMessageQueue owningThread, Func<string, bool>? itemFilter = null)
151151
{
152152
if (!shellItems.Any())
153153
return null;
@@ -159,7 +159,7 @@ public async Task<bool> InvokeItem(int itemID)
159159

160160
Shell32.IContextMenu menu = sf.GetChildrenUIObjects<Shell32.IContextMenu>(default, shellItems);
161161
var hMenu = User32.CreatePopupMenu();
162-
menu.QueryContextMenu(hMenu, 0, 1, 0x7FFF, flags);
162+
menu.QueryContextMenu(hMenu, 0, 1, 0x7FFF, (Shell32.CMF)flags);
163163
var contextMenu = new ContextMenu(menu, hMenu, shellItems.Select(x => x.ParsingName), owningThread, itemFilter);
164164
contextMenu.EnumMenuItems(hMenu, contextMenu.Items);
165165

@@ -174,7 +174,7 @@ public async Task<bool> InvokeItem(int itemID)
174174

175175
public static async Task WarmUpQueryContextMenuAsync()
176176
{
177-
using var cMenu = await GetContextMenuForFiles(new string[] { $@"{Constants.UserEnvironmentPaths.SystemDrivePath}\" }, Shell32.CMF.CMF_NORMAL);
177+
using var cMenu = await GetContextMenuForFiles(new string[] { $@"{Constants.UserEnvironmentPaths.SystemDrivePath}\" }, CMF.CMF_NORMAL);
178178
}
179179

180180
private void EnumMenuItems(HMENU hMenu, List<Win32ContextMenuItem> menuItemsResult, bool loadSubenus = false)

src/Files.App/Utils/Shell/LaunchHelper.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ private static async Task<bool> HandleApplicationLaunch(string application, stri
160160
if (!group.Any())
161161
continue;
162162

163-
using var cMenu = await ContextMenu.GetContextMenuForFiles(group.ToArray(), Shell32.CMF.CMF_DEFAULTONLY);
163+
using var cMenu = await ContextMenu.GetContextMenuForFiles(group.ToArray(), CMF.CMF_DEFAULTONLY);
164164

165165
if (cMenu is not null)
166166
await cMenu.InvokeVerb(Shell32.CMDSTR_OPEN);
@@ -176,7 +176,7 @@ private static async Task<bool> HandleApplicationLaunch(string application, stri
176176
{
177177
opened = await Win32Helper.StartSTATask(async () =>
178178
{
179-
using var cMenu = await ContextMenu.GetContextMenuForFiles(new[] { application }, Shell32.CMF.CMF_DEFAULTONLY);
179+
using var cMenu = await ContextMenu.GetContextMenuForFiles(new[] { application }, CMF.CMF_DEFAULTONLY);
180180

181181
if (cMenu is not null)
182182
await cMenu.InvokeItem(cMenu.Items.FirstOrDefault()?.ID ?? -1);

0 commit comments

Comments
 (0)