Skip to content

Commit 972651c

Browse files
committed
Code Quality: Replaced Files.App.Data.Items.MenuItemType with Windows.Win32.UI.WindowsAndMessaging.MENU_ITEM_TYPE
1 parent baba941 commit 972651c

File tree

4 files changed

+16
-25
lines changed

4 files changed

+16
-25
lines changed

src/Files.App.CsWin32/NativeMethods.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,3 +159,4 @@ ApplicationDestinations
159159
IApplicationDocumentLists
160160
ApplicationDocumentLists
161161
IApplicationActivationManager
162+
MENU_ITEM_TYPE

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

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
using Windows.System;
1313
using Windows.UI.Core;
1414
using Windows.Win32;
15+
using Windows.Win32.UI.WindowsAndMessaging;
1516

1617
namespace Files.App.Helpers
1718
{
@@ -77,10 +78,10 @@ private static void LoadMenuFlyoutItem(
7778
return;
7879

7980
var itemsCount = 0; // Separators do not count for reaching the overflow threshold
80-
var menuItems = menuFlyoutItems.TakeWhile(x => x.Type == MenuItemType.MFT_SEPARATOR || ++itemsCount <= itemsBeforeOverflow).ToList();
81+
var menuItems = menuFlyoutItems.TakeWhile(x => x.Type == MENU_ITEM_TYPE.MFT_SEPARATOR || ++itemsCount <= itemsBeforeOverflow).ToList();
8182
var overflowItems = menuFlyoutItems.Except(menuItems).ToList();
8283

83-
if (overflowItems.Any(x => x.Type != MenuItemType.MFT_SEPARATOR))
84+
if (overflowItems.Any(x => x.Type != MENU_ITEM_TYPE.MFT_SEPARATOR))
8485
{
8586
var moreItem = menuItemsListLocal.FirstOrDefault(x => x.ID == "ItemOverflow");
8687
if (moreItem is null)
@@ -100,15 +101,15 @@ private static void LoadMenuFlyoutItem(
100101
}
101102

102103
foreach (var menuFlyoutItem in menuItems
103-
.SkipWhile(x => x.Type == MenuItemType.MFT_SEPARATOR) // Remove leading separators
104+
.SkipWhile(x => x.Type == MENU_ITEM_TYPE.MFT_SEPARATOR) // Remove leading separators
104105
.Reverse()
105-
.SkipWhile(x => x.Type == MenuItemType.MFT_SEPARATOR)) // Remove trailing separators
106+
.SkipWhile(x => x.Type == MENU_ITEM_TYPE.MFT_SEPARATOR)) // Remove trailing separators
106107
{
107108
if (cancellationToken.IsCancellationRequested)
108109
break;
109110

110111
// Avoid duplicate separators
111-
if ((menuFlyoutItem.Type == MenuItemType.MFT_SEPARATOR) && (menuItemsListLocal.FirstOrDefault()?.ItemType == ContextMenuFlyoutItemType.Separator))
112+
if ((menuFlyoutItem.Type == MENU_ITEM_TYPE.MFT_SEPARATOR) && (menuItemsListLocal.FirstOrDefault()?.ItemType == ContextMenuFlyoutItemType.Separator))
112113
continue;
113114

114115
BitmapImage? image = null;
@@ -119,7 +120,7 @@ private static void LoadMenuFlyoutItem(
119120
image.SetSourceAsync(ms.AsRandomAccessStream()).AsTask().Wait(10);
120121
}
121122

122-
if (menuFlyoutItem.Type is MenuItemType.MFT_SEPARATOR)
123+
if (menuFlyoutItem.Type is MENU_ITEM_TYPE.MFT_SEPARATOR)
123124
{
124125
var menuLayoutItem = new ContextMenuFlyoutItemViewModel()
125126
{

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

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,10 @@
11
// Copyright (c) 2024 Files Community
22
// Licensed under the MIT License. See the LICENSE.
33

4+
using Windows.Win32.UI.WindowsAndMessaging;
5+
46
namespace Files.App.Data.Items
57
{
6-
// Same definition of Vanara.PInvoke.User32.MenuItemType
7-
public enum MenuItemType : uint
8-
{
9-
MFT_STRING = 0,
10-
MFT_BITMAP = 4,
11-
MFT_MENUBARBREAK = 32,
12-
MFT_MENUBREAK = 64,
13-
MFT_OWNERDRAW = 256,
14-
MFT_RADIOCHECK = 512,
15-
MFT_SEPARATOR = 2048,
16-
MFT_RIGHTORDER = 8192,
17-
MFT_RIGHTJUSTIFY = 16384
18-
}
19-
208
public enum HBITMAP_HMENU : long
219
{
2210
HBMMENU_CALLBACK = -1,
@@ -43,7 +31,7 @@ public class Win32ContextMenuItem
4331
public int ID { get; set; } // Valid only in current menu to invoke item
4432
public string Label { get; set; }
4533
public string CommandString { get; set; }
46-
public MenuItemType Type { get; set; }
34+
public MENU_ITEM_TYPE Type { get; set; }
4735
public List<Win32ContextMenuItem> SubItems { get; set; }
4836
}
4937
}

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

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
using Vanara.PInvoke;
88
using Vanara.Windows.Shell;
99
using Windows.Win32;
10+
using Windows.Win32.UI.WindowsAndMessaging;
1011

1112
namespace Files.App.Utils.Shell
1213
{
@@ -178,7 +179,7 @@ public static async Task WarmUpQueryContextMenuAsync()
178179
using var cMenu = await GetContextMenuForFiles(new string[] { $@"{Constants.UserEnvironmentPaths.SystemDrivePath}\" }, PInvoke.CMF_NORMAL);
179180
}
180181

181-
private void EnumMenuItems(HMENU hMenu, List<Win32ContextMenuItem> menuItemsResult, bool loadSubenus = false)
182+
private void EnumMenuItems(Vanara.PInvoke.HMENU hMenu, List<Win32ContextMenuItem> menuItemsResult, bool loadSubenus = false)
182183
{
183184
var itemCount = User32.GetMenuItemCount(hMenu);
184185

@@ -212,12 +213,12 @@ private void EnumMenuItems(HMENU hMenu, List<Win32ContextMenuItem> menuItemsResu
212213
continue;
213214
}
214215

215-
menuItem.Type = (MenuItemType)menuItemInfo.fType;
216+
menuItem.Type = (MENU_ITEM_TYPE)menuItemInfo.fType;
216217

217218
// wID - idCmdFirst
218219
menuItem.ID = (int)(menuItemInfo.wID - 1);
219220

220-
if (menuItem.Type == MenuItemType.MFT_STRING)
221+
if (menuItem.Type == MENU_ITEM_TYPE.MFT_STRING)
221222
{
222223
Debug.WriteLine("Item {0} ({1}): {2}", index, menuItemInfo.wID, menuItemInfo.dwTypeData);
223224

@@ -245,7 +246,7 @@ private void EnumMenuItems(HMENU hMenu, List<Win32ContextMenuItem> menuItemsResu
245246
}
246247
}
247248

248-
if (menuItemInfo.hSubMenu != HMENU.NULL)
249+
if (menuItemInfo.hSubMenu != Vanara.PInvoke.HMENU.NULL)
249250
{
250251
Debug.WriteLine("Item {0}: has submenu", index);
251252
var subItems = new List<Win32ContextMenuItem>();

0 commit comments

Comments
 (0)