@@ -515,9 +515,7 @@ navigationArguments.SelectItems is not null &&
515515 ItemManipulationModel . FocusFileList ( ) ;
516516 }
517517 }
518- catch ( Exception )
519- {
520- }
518+ catch ( Exception ) { }
521519 }
522520
523521 private CancellationTokenSource ? groupingCancellationToken ;
@@ -565,7 +563,8 @@ public async void ItemContextFlyout_Opening(object? sender, object e)
565563
566564 try
567565 {
568- if ( ! IsItemSelected && ( ( sender as CommandBarFlyout ) ? . Target as ListViewItem ) ? . Content is ListedItem li ) // Workaround for item sometimes not getting selected
566+ // Workaround for item sometimes not getting selected
567+ if ( ! IsItemSelected && ( sender as CommandBarFlyout ) ? . Target is ListViewItem { Content : ListedItem li } )
569568 ItemManipulationModel . SetSelectedItem ( li ) ;
570569
571570 if ( IsItemSelected )
@@ -654,10 +653,13 @@ private async Task LoadMenuItemsAsync()
654653 shellContextMenuItemCancellationToken ? . Cancel ( ) ;
655654 shellContextMenuItemCancellationToken = new CancellationTokenSource ( ) ;
656655 SelectedItemsPropertiesViewModel . CheckAllFileExtensions ( SelectedItems ! . Select ( selectedItem => selectedItem ? . FileExtension ) . ToList ( ) ! ) ;
656+
657657 var shiftPressed = Microsoft . UI . Input . InputKeyboardSource . GetKeyStateForCurrentThread ( VirtualKey . Shift ) . HasFlag ( Windows . UI . Core . CoreVirtualKeyStates . Down ) ;
658658 var items = ContextFlyoutItemHelper . GetItemContextCommandsWithoutShellItems ( currentInstanceViewModel : InstanceViewModel ! , selectedItems : SelectedItems ! , selectedItemsPropertiesViewModel : SelectedItemsPropertiesViewModel , commandsViewModel : CommandsViewModel ! , shiftPressed : shiftPressed , itemViewModel : null ) ;
659+
659660 ItemContextMenuFlyout . PrimaryCommands . Clear ( ) ;
660661 ItemContextMenuFlyout . SecondaryCommands . Clear ( ) ;
662+
661663 var ( primaryElements , secondaryElements ) = ItemModelListToContextFlyoutHelper . GetAppBarItemsFromModel ( items ) ;
662664 AddCloseHandler ( ItemContextMenuFlyout , primaryElements , secondaryElements ) ;
663665 primaryElements . ForEach ( ItemContextMenuFlyout . PrimaryCommands . Add ) ;
@@ -747,7 +749,7 @@ private async Task AddShellMenuItemsAsync(List<ContextMenuFlyoutItemViewModel> s
747749 var requiredHeight = contextMenuFlyout . SecondaryCommands . Concat ( mainItems ) . Where ( x => x is not AppBarSeparator ) . Count ( ) * Constants . UI . ContextMenuSecondaryItemsHeight ;
748750 var availableHeight = App . Window . Bounds . Height - cMenuPos . Y - Constants . UI . ContextMenuPrimaryItemsHeight ;
749751
750- // Set menu max height to current height (avoids menu repositioning)
752+ // Set menu max height to current height (Avoid menu repositioning)
751753 if ( requiredHeight > availableHeight )
752754 itemsControl . MaxHeight = Math . Min ( Constants . UI . ContextMenuMaxHeight , Math . Max ( itemsControl . ActualHeight , Math . Min ( availableHeight , requiredHeight ) ) ) ;
753755
@@ -854,34 +856,31 @@ private async Task AddShellMenuItemsAsync(List<ContextMenuFlyoutItemViewModel> s
854856 ShellContextmenuHelper . AddItemsToOverflowMenu ( overflowItem , x ) ;
855857 } ) ;
856858
857- if ( itemsControl is not null )
859+ itemsControl ? . Items . OfType < FrameworkElement > ( ) . ForEach ( item =>
858860 {
859- itemsControl . Items . OfType < FrameworkElement > ( ) . ForEach ( item =>
860- {
861- // Enable CharacterEllipsis text trimming for menu items
862- if ( item . FindDescendant ( "OverflowTextLabel" ) is TextBlock label )
863- label . TextTrimming = TextTrimming . CharacterEllipsis ;
861+ // Enable CharacterEllipsis text trimming for menu items
862+ if ( item . FindDescendant ( "OverflowTextLabel" ) is TextBlock label )
863+ label . TextTrimming = TextTrimming . CharacterEllipsis ;
864864
865- // Close main menu when clicking on subitems (#5508)
866- if ( ( item as AppBarButton ) ? . Flyout as MenuFlyout is MenuFlyout flyout )
865+ // Close main menu when clicking on subitems (#5508)
866+ if ( ( item as AppBarButton ) ? . Flyout as MenuFlyout is MenuFlyout flyout )
867+ {
868+ Action < IList < MenuFlyoutItemBase > > clickAction = null ! ;
869+ clickAction = ( items ) =>
867870 {
868- Action < IList < MenuFlyoutItemBase > > clickAction = null ! ;
869- clickAction = ( items ) =>
871+ items . OfType < MenuFlyoutItem > ( ) . ForEach ( i =>
870872 {
871- items . OfType < MenuFlyoutItem > ( ) . ForEach ( i =>
872- {
873- i . Click += new RoutedEventHandler ( ( s , e ) => contextMenuFlyout . Hide ( ) ) ;
874- } ) ;
875- items . OfType < MenuFlyoutSubItem > ( ) . ForEach ( i =>
876- {
877- clickAction ( i . Items ) ;
878- } ) ;
879- } ;
873+ i . Click += new RoutedEventHandler ( ( s , e ) => contextMenuFlyout . Hide ( ) ) ;
874+ } ) ;
875+ items . OfType < MenuFlyoutSubItem > ( ) . ForEach ( i =>
876+ {
877+ clickAction ( i . Items ) ;
878+ } ) ;
879+ } ;
880880
881- clickAction ( flyout . Items ) ;
882- }
883- } ) ;
884- }
881+ clickAction ( flyout . Items ) ;
882+ }
883+ } ) ;
885884 }
886885
887886 private void RemoveOverflow ( CommandBarFlyout contextMenuFlyout )
@@ -913,6 +912,7 @@ protected void FileList_DragItemsStarting(object sender, DragItemsStartingEventA
913912 {
914913 var iddo = shellItemList [ 0 ] . Parent . GetChildrenUIObjects < IDataObject > ( HWND . NULL , shellItemList ) ;
915914 shellItemList . ForEach ( x => x . Dispose ( ) ) ;
915+
916916 var format = System . Windows . Forms . DataFormats . GetFormat ( "Shell IDList Array" ) ;
917917 if ( iddo . TryGetData < byte [ ] > ( ( uint ) format . Id , out var data ) )
918918 {
@@ -951,6 +951,7 @@ protected async void Item_DragOver(object sender, DragEventArgs e)
951951 return ;
952952
953953 DragOperationDeferral ? deferral = null ;
954+
954955 try
955956 {
956957 deferral = e . GetDeferral ( ) ;
@@ -1048,6 +1049,7 @@ protected async void Item_Drop(object sender, DragEventArgs e)
10481049 var item = GetItemFromElement ( sender ) ;
10491050 if ( item is not null )
10501051 await ParentShellPageInstance ! . FilesystemHelpers . PerformOperationTypeAsync ( e . AcceptedOperation , e . DataView , ( item as ShortcutItem ) ? . TargetPath ?? item . ItemPath , false , true , item . IsExecutable ) ;
1052+
10511053 deferral . Complete ( ) ;
10521054 }
10531055
@@ -1139,13 +1141,13 @@ protected internal void FileListItem_PointerEntered(object sender, PointerRouted
11391141
11401142 hoverTimer . Stop ( ) ;
11411143
1142- // selection of multiple individual items with control
1144+ // Selection of multiple individual items with control
11431145 if ( e . KeyModifiers == VirtualKeyModifiers . Control &&
11441146 selectedItems is not null )
11451147 {
11461148 ItemManipulationModel . AddSelectedItem ( hoveredItem ) ;
11471149 }
1148- // selection of a range of items with shift
1150+ // Selection of a range of items with shift
11491151 else if ( e . KeyModifiers == VirtualKeyModifiers . Shift &&
11501152 selectedItems is not null &&
11511153 selectedItems . Any ( ) )
@@ -1161,9 +1163,8 @@ selectedItems is not null &&
11611163 ItemManipulationModel . AddSelectedItem ( ( ListedItem ) ItemsControl . Items [ i ] ) ;
11621164 }
11631165 }
1164- // avoid resetting the selection if multiple items are selected
1165- else if ( SelectedItems is null ||
1166- SelectedItems . Count <= 1 )
1166+ // Avoid resetting the selection if multiple items are selected
1167+ else if ( SelectedItems is null || SelectedItems . Count <= 1 )
11671168 {
11681169 ItemManipulationModel . SetSelectedItem ( hoveredItem ) ;
11691170 }
@@ -1211,7 +1212,7 @@ protected void UninitializeDrag(UIElement element)
12111212 element . Drop -= Item_Drop ;
12121213 }
12131214
1214- // VirtualKey doesn't support / accept plus and minus by default.
1215+ // VirtualKey doesn't support or accept plus and minus by default.
12151216 public readonly VirtualKey PlusKey = ( VirtualKey ) 187 ;
12161217
12171218 public readonly VirtualKey MinusKey = ( VirtualKey ) 189 ;
@@ -1239,15 +1240,15 @@ private void UpdateCollectionViewSource()
12391240
12401241 if ( ParentShellPageInstance . FilesystemViewModel . FilesAndFolders . IsGrouped )
12411242 {
1242- CollectionViewSource = new CollectionViewSource ( )
1243+ CollectionViewSource = new ( )
12431244 {
12441245 IsSourceGrouped = true ,
12451246 Source = ParentShellPageInstance . FilesystemViewModel . FilesAndFolders . GroupedCollection
12461247 } ;
12471248 }
12481249 else
12491250 {
1250- CollectionViewSource = new CollectionViewSource ( )
1251+ CollectionViewSource = new ( )
12511252 {
12521253 IsSourceGrouped = false ,
12531254 Source = ParentShellPageInstance . FilesystemViewModel . FilesAndFolders
0 commit comments