15
15
16
16
namespace Files . App . Helpers
17
17
{
18
- public static class ShellContextmenuHelper
18
+ public static class ShellContextFlyoutFactory
19
19
{
20
20
public static IUserSettingsService UserSettingsService { get ; } = Ioc . Default . GetRequiredService < IUserSettingsService > ( ) ;
21
+
21
22
public static async Task < List < ContextMenuFlyoutItemViewModel > > GetShellContextmenuAsync ( bool showOpenMenu , bool shiftPressed , string workingDirectory , List < ListedItem > ? selectedItems , CancellationToken cancellationToken )
22
23
{
23
24
bool IsItemSelected = selectedItems ? . Count > 0 ;
@@ -63,12 +64,13 @@ bool filterMenuItemsImpl(string menuItem) => !string.IsNullOrEmpty(menuItem)
63
64
return menuItemsList ;
64
65
}
65
66
66
- private static void LoadMenuFlyoutItem ( IList < ContextMenuFlyoutItemViewModel > menuItemsListLocal ,
67
- ContextMenu contextMenu ,
68
- IEnumerable < Win32ContextMenuItem > menuFlyoutItems ,
69
- CancellationToken cancellationToken ,
70
- bool showIcons = true ,
71
- int itemsBeforeOverflow = int . MaxValue )
67
+ private static void LoadMenuFlyoutItem (
68
+ IList < ContextMenuFlyoutItemViewModel > menuItemsListLocal ,
69
+ ContextMenu contextMenu ,
70
+ IEnumerable < Win32ContextMenuItem > menuFlyoutItems ,
71
+ CancellationToken cancellationToken ,
72
+ bool showIcons = true ,
73
+ int itemsBeforeOverflow = int . MaxValue )
72
74
{
73
75
if ( cancellationToken . IsCancellationRequested )
74
76
return ;
@@ -215,6 +217,7 @@ async Task InvokeShellMenuItemAsync(ContextMenu contextMenu, object? tag)
215
217
var item = flyout . FirstOrDefault ( x => x . Tag is Win32ContextMenuItem { CommandString : "openas" } ) ;
216
218
if ( item is not null )
217
219
flyout . Remove ( item ) ;
220
+
218
221
return item ? . Items ;
219
222
}
220
223
@@ -223,6 +226,7 @@ async Task InvokeShellMenuItemAsync(ContextMenu contextMenu, object? tag)
223
226
var item = flyout . FirstOrDefault ( x => x . Tag is Win32ContextMenuItem { CommandString : "sendto" } ) ;
224
227
if ( item is not null )
225
228
flyout . Remove ( item ) ;
229
+
226
230
return item ? . Items ;
227
231
}
228
232
@@ -239,7 +243,7 @@ public static async Task LoadShellMenuItemsAsync(
239
243
return ;
240
244
241
245
var shiftPressed = InputKeyboardSource . GetKeyStateForCurrentThread ( VirtualKey . Shift ) . HasFlag ( CoreVirtualKeyStates . Down ) ;
242
- var shellMenuItems = await ContextFlyoutItemHelper . GetItemContextShellCommandsAsync (
246
+ var shellMenuItems = await ContentPageContextFlyoutFactory . GetItemContextShellCommandsAsync (
243
247
workingDir : null ,
244
248
new List < ListedItem > ( ) { new ListedItem ( null ) { ItemPath = path } } ,
245
249
shiftPressed : shiftPressed ,
@@ -262,7 +266,7 @@ x.Tag is Win32ContextMenuItem menuItem &&
262
266
if ( turnOnBitLocker is not null )
263
267
shellMenuItems . Remove ( turnOnBitLocker ) ;
264
268
265
- ContextFlyoutItemHelper . SwapPlaceholderWithShellOption (
269
+ ContentPageContextFlyoutFactory . SwapPlaceholderWithShellOption (
266
270
itemContextMenuFlyout ,
267
271
"TurnOnBitLockerPlaceholder" ,
268
272
turnOnBitLocker ,
@@ -273,7 +277,7 @@ x.Tag is Win32ContextMenuItem menuItem &&
273
277
if ( manageBitLocker is not null )
274
278
shellMenuItems . Remove ( manageBitLocker ) ;
275
279
276
- ContextFlyoutItemHelper . SwapPlaceholderWithShellOption (
280
+ ContentPageContextFlyoutFactory . SwapPlaceholderWithShellOption (
277
281
itemContextMenuFlyout ,
278
282
"ManageBitLockerPlaceholder" ,
279
283
manageBitLocker ,
@@ -284,7 +288,7 @@ x.Tag is Win32ContextMenuItem menuItem &&
284
288
285
289
if ( ! UserSettingsService . GeneralSettingsService . MoveShellExtensionsToSubMenu )
286
290
{
287
- var ( _, secondaryElements ) = ItemModelListToContextFlyoutHelper . GetAppBarItemsFromModel ( shellMenuItems ) ;
291
+ var ( _, secondaryElements ) = ContextFlyoutModelToElementHelper . GetAppBarItemsFromModel ( shellMenuItems ) ;
288
292
if ( secondaryElements . Any ( ) )
289
293
{
290
294
var openedPopups = Microsoft . UI . Xaml . Media . VisualTreeHelper . GetOpenPopups ( MainWindow . Instance ) ;
@@ -310,7 +314,7 @@ x.Tag is Win32ContextMenuItem menuItem &&
310
314
}
311
315
else
312
316
{
313
- var overflowItems = ItemModelListToContextFlyoutHelper . GetMenuFlyoutItemsFromModel ( shellMenuItems ) ;
317
+ var overflowItems = ContextFlyoutModelToElementHelper . GetMenuFlyoutItemsFromModel ( shellMenuItems ) ;
314
318
if ( itemContextMenuFlyout . SecondaryCommands . FirstOrDefault ( x => x is AppBarButton appBarButton && ( appBarButton . Tag as string ) == "ItemOverflow" ) is not AppBarButton overflowItem
315
319
|| itemContextMenuFlyout . SecondaryCommands . FirstOrDefault ( x => x is AppBarSeparator appBarSeparator && ( appBarSeparator . Tag as string ) == "OverflowSeparator" ) is not AppBarSeparator overflowSeparator )
316
320
return ;
@@ -334,7 +338,7 @@ x.Tag is Win32ContextMenuItem menuItem &&
334
338
{
335
339
OpacityIconStyle = "ColorIconOpenWith" ,
336
340
} ;
337
- var ( _, openWithItems ) = ItemModelListToContextFlyoutHelper . GetAppBarItemsFromModel ( new List < ContextMenuFlyoutItemViewModel > ( ) { openWithItem } ) ;
341
+ var ( _, openWithItems ) = ContextFlyoutModelToElementHelper . GetAppBarItemsFromModel ( new List < ContextMenuFlyoutItemViewModel > ( ) { openWithItem } ) ;
338
342
var placeholder = itemContextMenuFlyout . SecondaryCommands . Where ( x => Equals ( ( x as AppBarButton ) ? . Tag , "OpenWithPlaceholder" ) ) . FirstOrDefault ( ) as AppBarButton ;
339
343
if ( placeholder is not null )
340
344
placeholder . Visibility = Visibility . Collapsed ;
@@ -346,7 +350,7 @@ x.Tag is Win32ContextMenuItem menuItem &&
346
350
{
347
351
await sendToItem . LoadSubMenuAction ( ) ;
348
352
349
- var ( _, sendToItems ) = ItemModelListToContextFlyoutHelper . GetAppBarItemsFromModel ( new List < ContextMenuFlyoutItemViewModel > ( ) { sendToItem } ) ;
353
+ var ( _, sendToItems ) = ContextFlyoutModelToElementHelper . GetAppBarItemsFromModel ( new List < ContextMenuFlyoutItemViewModel > ( ) { sendToItem } ) ;
350
354
var placeholder = itemContextMenuFlyout . SecondaryCommands . Where ( x => Equals ( ( x as AppBarButton ) ? . Tag , "SendToPlaceholder" ) ) . FirstOrDefault ( ) as AppBarButton ;
351
355
if ( placeholder is not null )
352
356
placeholder . Visibility = Visibility . Collapsed ;
@@ -378,7 +382,7 @@ public static void AddItemsToMainMenu(IEnumerable<ICommandBarElement> mainMenu,
378
382
if ( appBarButton is not null )
379
383
{
380
384
var ctxFlyout = new MenuFlyout ( ) ;
381
- ItemModelListToContextFlyoutHelper . GetMenuFlyoutItemsFromModel ( viewModel . Items ) ? . ForEach ( i => ctxFlyout . Items . Add ( i ) ) ;
385
+ ContextFlyoutModelToElementHelper . GetMenuFlyoutItemsFromModel ( viewModel . Items ) ? . ForEach ( i => ctxFlyout . Items . Add ( i ) ) ;
382
386
appBarButton . Flyout = ctxFlyout ;
383
387
appBarButton . Visibility = Visibility . Collapsed ;
384
388
appBarButton . Visibility = Visibility . Visible ;
@@ -392,7 +396,7 @@ public static void AddItemsToOverflowMenu(AppBarButton? overflowItem, ContextMen
392
396
var flyoutSubItem = flyout . Items . FirstOrDefault ( x => x . Tag == viewModel . Tag ) as MenuFlyoutSubItem ;
393
397
if ( flyoutSubItem is not null )
394
398
{
395
- viewModel . Items . ForEach ( i => flyoutSubItem . Items . Add ( ItemModelListToContextFlyoutHelper . GetMenuItem ( i ) ) ) ;
399
+ viewModel . Items . ForEach ( i => flyoutSubItem . Items . Add ( ContextFlyoutModelToElementHelper . GetMenuItem ( i ) ) ) ;
396
400
flyout . Items [ flyout . Items . IndexOf ( flyoutSubItem ) + 1 ] . Visibility = Visibility . Collapsed ;
397
401
flyoutSubItem . Visibility = Visibility . Visible ;
398
402
}
0 commit comments