@@ -515,9 +515,7 @@ navigationArguments.SelectItems is not null &&
515
515
ItemManipulationModel . FocusFileList ( ) ;
516
516
}
517
517
}
518
- catch ( Exception )
519
- {
520
- }
518
+ catch ( Exception ) { }
521
519
}
522
520
523
521
private CancellationTokenSource ? groupingCancellationToken ;
@@ -565,7 +563,8 @@ public async void ItemContextFlyout_Opening(object? sender, object e)
565
563
566
564
try
567
565
{
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 } )
569
568
ItemManipulationModel . SetSelectedItem ( li ) ;
570
569
571
570
if ( IsItemSelected )
@@ -654,10 +653,13 @@ private async Task LoadMenuItemsAsync()
654
653
shellContextMenuItemCancellationToken ? . Cancel ( ) ;
655
654
shellContextMenuItemCancellationToken = new CancellationTokenSource ( ) ;
656
655
SelectedItemsPropertiesViewModel . CheckAllFileExtensions ( SelectedItems ! . Select ( selectedItem => selectedItem ? . FileExtension ) . ToList ( ) ! ) ;
656
+
657
657
var shiftPressed = Microsoft . UI . Input . InputKeyboardSource . GetKeyStateForCurrentThread ( VirtualKey . Shift ) . HasFlag ( Windows . UI . Core . CoreVirtualKeyStates . Down ) ;
658
658
var items = ContextFlyoutItemHelper . GetItemContextCommandsWithoutShellItems ( currentInstanceViewModel : InstanceViewModel ! , selectedItems : SelectedItems ! , selectedItemsPropertiesViewModel : SelectedItemsPropertiesViewModel , commandsViewModel : CommandsViewModel ! , shiftPressed : shiftPressed , itemViewModel : null ) ;
659
+
659
660
ItemContextMenuFlyout . PrimaryCommands . Clear ( ) ;
660
661
ItemContextMenuFlyout . SecondaryCommands . Clear ( ) ;
662
+
661
663
var ( primaryElements , secondaryElements ) = ItemModelListToContextFlyoutHelper . GetAppBarItemsFromModel ( items ) ;
662
664
AddCloseHandler ( ItemContextMenuFlyout , primaryElements , secondaryElements ) ;
663
665
primaryElements . ForEach ( ItemContextMenuFlyout . PrimaryCommands . Add ) ;
@@ -747,7 +749,7 @@ private async Task AddShellMenuItemsAsync(List<ContextMenuFlyoutItemViewModel> s
747
749
var requiredHeight = contextMenuFlyout . SecondaryCommands . Concat ( mainItems ) . Where ( x => x is not AppBarSeparator ) . Count ( ) * Constants . UI . ContextMenuSecondaryItemsHeight ;
748
750
var availableHeight = App . Window . Bounds . Height - cMenuPos . Y - Constants . UI . ContextMenuPrimaryItemsHeight ;
749
751
750
- // Set menu max height to current height (avoids menu repositioning)
752
+ // Set menu max height to current height (Avoid menu repositioning)
751
753
if ( requiredHeight > availableHeight )
752
754
itemsControl . MaxHeight = Math . Min ( Constants . UI . ContextMenuMaxHeight , Math . Max ( itemsControl . ActualHeight , Math . Min ( availableHeight , requiredHeight ) ) ) ;
753
755
@@ -854,34 +856,31 @@ private async Task AddShellMenuItemsAsync(List<ContextMenuFlyoutItemViewModel> s
854
856
ShellContextmenuHelper . AddItemsToOverflowMenu ( overflowItem , x ) ;
855
857
} ) ;
856
858
857
- if ( itemsControl is not null )
859
+ itemsControl ? . Items . OfType < FrameworkElement > ( ) . ForEach ( item =>
858
860
{
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 ;
864
864
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 ) =>
867
870
{
868
- Action < IList < MenuFlyoutItemBase > > clickAction = null ! ;
869
- clickAction = ( items ) =>
871
+ items . OfType < MenuFlyoutItem > ( ) . ForEach ( i =>
870
872
{
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
+ } ;
880
880
881
- clickAction ( flyout . Items ) ;
882
- }
883
- } ) ;
884
- }
881
+ clickAction ( flyout . Items ) ;
882
+ }
883
+ } ) ;
885
884
}
886
885
887
886
private void RemoveOverflow ( CommandBarFlyout contextMenuFlyout )
@@ -913,6 +912,7 @@ protected void FileList_DragItemsStarting(object sender, DragItemsStartingEventA
913
912
{
914
913
var iddo = shellItemList [ 0 ] . Parent . GetChildrenUIObjects < IDataObject > ( HWND . NULL , shellItemList ) ;
915
914
shellItemList . ForEach ( x => x . Dispose ( ) ) ;
915
+
916
916
var format = System . Windows . Forms . DataFormats . GetFormat ( "Shell IDList Array" ) ;
917
917
if ( iddo . TryGetData < byte [ ] > ( ( uint ) format . Id , out var data ) )
918
918
{
@@ -951,6 +951,7 @@ protected async void Item_DragOver(object sender, DragEventArgs e)
951
951
return ;
952
952
953
953
DragOperationDeferral ? deferral = null ;
954
+
954
955
try
955
956
{
956
957
deferral = e . GetDeferral ( ) ;
@@ -1048,6 +1049,7 @@ protected async void Item_Drop(object sender, DragEventArgs e)
1048
1049
var item = GetItemFromElement ( sender ) ;
1049
1050
if ( item is not null )
1050
1051
await ParentShellPageInstance ! . FilesystemHelpers . PerformOperationTypeAsync ( e . AcceptedOperation , e . DataView , ( item as ShortcutItem ) ? . TargetPath ?? item . ItemPath , false , true , item . IsExecutable ) ;
1052
+
1051
1053
deferral . Complete ( ) ;
1052
1054
}
1053
1055
@@ -1139,13 +1141,13 @@ protected internal void FileListItem_PointerEntered(object sender, PointerRouted
1139
1141
1140
1142
hoverTimer . Stop ( ) ;
1141
1143
1142
- // selection of multiple individual items with control
1144
+ // Selection of multiple individual items with control
1143
1145
if ( e . KeyModifiers == VirtualKeyModifiers . Control &&
1144
1146
selectedItems is not null )
1145
1147
{
1146
1148
ItemManipulationModel . AddSelectedItem ( hoveredItem ) ;
1147
1149
}
1148
- // selection of a range of items with shift
1150
+ // Selection of a range of items with shift
1149
1151
else if ( e . KeyModifiers == VirtualKeyModifiers . Shift &&
1150
1152
selectedItems is not null &&
1151
1153
selectedItems . Any ( ) )
@@ -1161,9 +1163,8 @@ selectedItems is not null &&
1161
1163
ItemManipulationModel . AddSelectedItem ( ( ListedItem ) ItemsControl . Items [ i ] ) ;
1162
1164
}
1163
1165
}
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 )
1167
1168
{
1168
1169
ItemManipulationModel . SetSelectedItem ( hoveredItem ) ;
1169
1170
}
@@ -1211,7 +1212,7 @@ protected void UninitializeDrag(UIElement element)
1211
1212
element . Drop -= Item_Drop ;
1212
1213
}
1213
1214
1214
- // VirtualKey doesn't support / accept plus and minus by default.
1215
+ // VirtualKey doesn't support or accept plus and minus by default.
1215
1216
public readonly VirtualKey PlusKey = ( VirtualKey ) 187 ;
1216
1217
1217
1218
public readonly VirtualKey MinusKey = ( VirtualKey ) 189 ;
@@ -1239,15 +1240,15 @@ private void UpdateCollectionViewSource()
1239
1240
1240
1241
if ( ParentShellPageInstance . FilesystemViewModel . FilesAndFolders . IsGrouped )
1241
1242
{
1242
- CollectionViewSource = new CollectionViewSource ( )
1243
+ CollectionViewSource = new ( )
1243
1244
{
1244
1245
IsSourceGrouped = true ,
1245
1246
Source = ParentShellPageInstance . FilesystemViewModel . FilesAndFolders . GroupedCollection
1246
1247
} ;
1247
1248
}
1248
1249
else
1249
1250
{
1250
- CollectionViewSource = new CollectionViewSource ( )
1251
+ CollectionViewSource = new ( )
1251
1252
{
1252
1253
IsSourceGrouped = false ,
1253
1254
Source = ParentShellPageInstance . FilesystemViewModel . FilesAndFolders
0 commit comments