Skip to content

Commit 594827e

Browse files
committed
Code Quality: Replaced Files.App.Data.Items.CMF with CsWin32
1 parent 41b6b19 commit 594827e

File tree

4 files changed

+11
-29
lines changed

4 files changed

+11
-29
lines changed

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
using System.IO;
1212
using Windows.System;
1313
using Windows.UI.Core;
14+
using Windows.Win32;
1415

1516
namespace Files.App.Helpers
1617
{
@@ -53,7 +54,7 @@ bool filterMenuItemsImpl(string menuItem) => !string.IsNullOrEmpty(menuItem)
5354
}
5455

5556
var contextMenu = await ContextMenu.GetContextMenuForFiles(filePaths,
56-
shiftPressed ? CMF.CMF_EXTENDEDVERBS : CMF.CMF_NORMAL, FilterMenuItems(showOpenMenu));
57+
shiftPressed ? PInvoke.CMF_EXTENDEDVERBS : PInvoke.CMF_NORMAL, FilterMenuItems(showOpenMenu));
5758

5859
if (contextMenu is not null)
5960
LoadMenuFlyoutItem(menuItemsList, contextMenu, contextMenu.Items, cancellationToken, true);

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

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -32,27 +32,6 @@ 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-
5635
public class Win32ContextMenu
5736
{
5837
public List<Win32ContextMenuItem> Items { get; set; }

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

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
using Vanara.InteropServices;
77
using Vanara.PInvoke;
88
using Vanara.Windows.Shell;
9+
using Windows.Win32;
910

1011
namespace Files.App.Utils.Shell
1112
{
@@ -43,7 +44,7 @@ private ContextMenu(Shell32.IContextMenu cMenu, User32.SafeHMENU hMenu, IEnumera
4344

4445
public async static Task<bool> InvokeVerb(string verb, params string[] filePaths)
4546
{
46-
using var cMenu = await GetContextMenuForFiles(filePaths, CMF.CMF_DEFAULTONLY);
47+
using var cMenu = await GetContextMenuForFiles(filePaths, PInvoke.CMF_DEFAULTONLY);
4748

4849
return cMenu is not null && await cMenu.InvokeVerb(verb);
4950
}
@@ -112,7 +113,7 @@ public async Task<bool> InvokeItem(int itemID)
112113
return false;
113114
}
114115

115-
public async static Task<ContextMenu?> GetContextMenuForFiles(string[] filePathList, CMF flags, Func<string, bool>? itemFilter = null)
116+
public async static Task<ContextMenu?> GetContextMenuForFiles(string[] filePathList, uint flags, Func<string, bool>? itemFilter = null)
116117
{
117118
var owningThread = new ThreadWithMessageQueue();
118119

@@ -140,14 +141,14 @@ public async Task<bool> InvokeItem(int itemID)
140141
});
141142
}
142143

143-
public async static Task<ContextMenu?> GetContextMenuForFiles(ShellItem[] shellItems, CMF flags, Func<string, bool>? itemFilter = null)
144+
public async static Task<ContextMenu?> GetContextMenuForFiles(ShellItem[] shellItems, uint flags, Func<string, bool>? itemFilter = null)
144145
{
145146
var owningThread = new ThreadWithMessageQueue();
146147

147148
return await owningThread.PostMethod<ContextMenu>(() => GetContextMenuForFiles(shellItems, flags, owningThread, itemFilter));
148149
}
149150

150-
private static ContextMenu? GetContextMenuForFiles(ShellItem[] shellItems, CMF flags, ThreadWithMessageQueue owningThread, Func<string, bool>? itemFilter = null)
151+
private static ContextMenu? GetContextMenuForFiles(ShellItem[] shellItems, uint flags, ThreadWithMessageQueue owningThread, Func<string, bool>? itemFilter = null)
151152
{
152153
if (!shellItems.Any())
153154
return null;
@@ -174,7 +175,7 @@ public async Task<bool> InvokeItem(int itemID)
174175

175176
public static async Task WarmUpQueryContextMenuAsync()
176177
{
177-
using var cMenu = await GetContextMenuForFiles(new string[] { $@"{Constants.UserEnvironmentPaths.SystemDrivePath}\" }, CMF.CMF_NORMAL);
178+
using var cMenu = await GetContextMenuForFiles(new string[] { $@"{Constants.UserEnvironmentPaths.SystemDrivePath}\" }, PInvoke.CMF_NORMAL);
178179
}
179180

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

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
using System.IO;
77
using Vanara.PInvoke;
88
using Vanara.Windows.Shell;
9+
using Windows.Win32;
910
using Windows.Win32.UI.Shell;
1011

1112
namespace Files.App.Utils.Shell
@@ -161,7 +162,7 @@ private static async Task<bool> HandleApplicationLaunch(string application, stri
161162
if (!group.Any())
162163
continue;
163164

164-
using var cMenu = await ContextMenu.GetContextMenuForFiles(group.ToArray(), CMF.CMF_DEFAULTONLY);
165+
using var cMenu = await ContextMenu.GetContextMenuForFiles(group.ToArray(), PInvoke.CMF_DEFAULTONLY);
165166

166167
if (cMenu is not null)
167168
await cMenu.InvokeVerb(Shell32.CMDSTR_OPEN);
@@ -177,7 +178,7 @@ private static async Task<bool> HandleApplicationLaunch(string application, stri
177178
{
178179
opened = await Win32Helper.StartSTATask(async () =>
179180
{
180-
using var cMenu = await ContextMenu.GetContextMenuForFiles(new[] { application }, CMF.CMF_DEFAULTONLY);
181+
using var cMenu = await ContextMenu.GetContextMenuForFiles(new[] { application }, PInvoke.CMF_DEFAULTONLY);
181182

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

0 commit comments

Comments
 (0)