@@ -98,7 +98,7 @@ public bool IsMiddleClickToScrollEnabled
98
98
99
99
protected AddressToolbar ? NavToolbar => ( App . Window . Content as Frame ) ? . FindDescendant < AddressToolbar > ( ) ;
100
100
101
- private CollectionViewSource collectionViewSource = new CollectionViewSource ( )
101
+ private CollectionViewSource collectionViewSource = new ( )
102
102
{
103
103
IsSourceGrouped = true ,
104
104
} ;
@@ -150,10 +150,7 @@ public string JumpString
150
150
if ( value != string . Empty )
151
151
{
152
152
ListedItem ? jumpedToItem = null ;
153
- ListedItem ? previouslySelectedItem = null ;
154
-
155
- if ( IsItemSelected )
156
- previouslySelectedItem = SelectedItem ;
153
+ ListedItem ? previouslySelectedItem = IsItemSelected ? SelectedItem : null ;
157
154
158
155
// Select first matching item after currently selected item
159
156
if ( previouslySelectedItem is not null )
@@ -207,7 +204,7 @@ internal set
207
204
// check if the preview pane is open before updating the model
208
205
if ( PreviewPaneViewModel . IsEnabled )
209
206
{
210
- bool isPaneEnabled = ( ( App . Window . Content as Frame ) ? . Content as MainPage ) ? . ShouldPreviewPaneBeActive ?? false ;
207
+ var isPaneEnabled = ( ( App . Window . Content as Frame ) ? . Content as MainPage ) ? . ShouldPreviewPaneBeActive ?? false ;
211
208
if ( isPaneEnabled )
212
209
App . PreviewPaneViewModel . UpdateSelectedItemPreview ( ) ;
213
210
}
@@ -222,7 +219,7 @@ internal set
222
219
ResetRenameDoubleClick ( ) ;
223
220
UpdateSelectionSize ( ) ;
224
221
}
225
- else if ( selectedItems != null )
222
+ else if ( selectedItems is not null )
226
223
{
227
224
IsItemSelected = true ;
228
225
SelectedItem = selectedItems . First ( ) ;
@@ -307,15 +304,18 @@ private void JumpTimer_Tick(object sender, object e)
307
304
308
305
protected IEnumerable < ListedItem > ? GetAllItems ( )
309
306
{
310
- var items = CollectionViewSource . IsSourceGrouped ? // add all items from each group to the new list
311
- ( CollectionViewSource . Source as BulkConcurrentObservableCollection < GroupedCollection < ListedItem > > ) ? . SelectMany ( g => g ) :
312
- CollectionViewSource . Source as IEnumerable < ListedItem > ;
307
+ var items = CollectionViewSource . IsSourceGrouped
308
+ ? ( CollectionViewSource . Source as BulkConcurrentObservableCollection < GroupedCollection < ListedItem > > ) ? . SelectMany ( g => g ) // add all items from each group to the new list
309
+ : CollectionViewSource . Source as IEnumerable < ListedItem > ;
313
310
return items ?? new List < ListedItem > ( ) ;
314
311
}
315
312
316
313
public virtual void ResetItemOpacity ( )
317
314
{
318
- foreach ( var item in GetAllItems ( ) )
315
+ var items = GetAllItems ( ) ;
316
+ if ( items is null )
317
+ return ;
318
+ foreach ( var item in items )
319
319
{
320
320
if ( item is not null )
321
321
item . Opacity = item . IsHiddenItem ? Constants . UI . DimItemOpacity : 1.0d ;
@@ -324,8 +324,7 @@ public virtual void ResetItemOpacity()
324
324
325
325
protected ListedItem ? GetItemFromElement ( object element )
326
326
{
327
- var item = element as ContentControl ;
328
- if ( item is null || ! CanGetItemFromElement ( element ) )
327
+ if ( element is not ContentControl item || ! CanGetItemFromElement ( element ) )
329
328
return null ;
330
329
331
330
return ( item . DataContext as ListedItem ) ?? ( item . Content as ListedItem ) ?? ( ItemsControl . ItemFromContainer ( item ) as ListedItem ) ;
@@ -384,14 +383,14 @@ protected override async void OnNavigatedTo(NavigationEventArgs eventArgs)
384
383
385
384
if ( ! navigationArguments . IsSearchResultPage )
386
385
{
387
- string previousDir = ParentShellPageInstance . FilesystemViewModel . WorkingDirectory ;
386
+ var previousDir = ParentShellPageInstance . FilesystemViewModel . WorkingDirectory ;
388
387
await ParentShellPageInstance . FilesystemViewModel . SetWorkingDirectoryAsync ( navigationArguments . NavPathParam ) ;
389
388
390
389
// pathRoot will be empty on recycle bin path
391
390
var workingDir = ParentShellPageInstance . FilesystemViewModel . WorkingDirectory ?? string . Empty ;
392
- string pathRoot = GetPathRoot ( workingDir ) ;
391
+ var pathRoot = GetPathRoot ( workingDir ) ;
393
392
394
- bool isRecycleBin = workingDir . StartsWith ( CommonPaths . RecycleBinPath , StringComparison . Ordinal ) ;
393
+ var isRecycleBin = workingDir . StartsWith ( CommonPaths . RecycleBinPath , StringComparison . Ordinal ) ;
395
394
ParentShellPageInstance . InstanceViewModel . IsPageTypeRecycleBin = isRecycleBin ;
396
395
397
396
// Can't go up from recycle bin
@@ -506,9 +505,7 @@ public async void ItemContextFlyout_Opening(object? sender, object e)
506
505
try
507
506
{
508
507
if ( ! IsItemSelected && ( ( sender as CommandBarFlyout ) ? . Target as ListViewItem ) ? . Content is ListedItem li ) // Workaround for item sometimes not getting selected
509
- {
510
508
ItemManipulationModel . SetSelectedItem ( li ) ;
511
- }
512
509
if ( IsItemSelected )
513
510
await LoadMenuItemsAsync ( ) ;
514
511
}
@@ -529,7 +526,7 @@ public async void BaseContextFlyout_Opening(object? sender, object e)
529
526
shellContextMenuItemCancellationToken ? . Cancel ( ) ;
530
527
shellContextMenuItemCancellationToken = new CancellationTokenSource ( ) ;
531
528
var shiftPressed = Microsoft . UI . Input . InputKeyboardSource . GetKeyStateForCurrentThread ( VirtualKey . Shift ) . HasFlag ( Windows . UI . Core . CoreVirtualKeyStates . Down ) ;
532
- var items = ContextFlyoutItemHelper . GetBaseContextCommandsWithoutShellItems ( currentInstanceViewModel : InstanceViewModel ! , itemViewModel : ParentShellPageInstance ! . FilesystemViewModel , commandsViewModel : CommandsViewModel ! , shiftPressed : shiftPressed , false ) ;
529
+ var items = ContextFlyoutItemHelper . GetBaseContextCommandsWithoutShellItems ( currentInstanceViewModel : InstanceViewModel ! , itemViewModel : ParentShellPageInstance ! . FilesystemViewModel , commandsViewModel : CommandsViewModel ! , shiftPressed : shiftPressed ) ;
533
530
BaseContextMenuFlyout . PrimaryCommands . Clear ( ) ;
534
531
BaseContextMenuFlyout . SecondaryCommands . Clear ( ) ;
535
532
var ( primaryElements , secondaryElements ) = ItemModelListToContextFlyoutHelper . GetAppBarItemsFromModel ( items ) ;
@@ -540,7 +537,7 @@ public async void BaseContextFlyout_Opening(object? sender, object e)
540
537
541
538
if ( ! InstanceViewModel ! . IsPageTypeSearchResults && ! InstanceViewModel . IsPageTypeZipFolder )
542
539
{
543
- var shellMenuItems = await ContextFlyoutItemHelper . GetBaseContextShellCommandsAsync ( currentInstanceViewModel : InstanceViewModel , workingDir : ParentShellPageInstance . FilesystemViewModel . WorkingDirectory , shiftPressed : shiftPressed , showOpenMenu : false , shellContextMenuItemCancellationToken . Token ) ;
540
+ var shellMenuItems = await ContextFlyoutItemHelper . GetBaseContextShellCommandsAsync ( workingDir : ParentShellPageInstance . FilesystemViewModel . WorkingDirectory , shiftPressed : shiftPressed , showOpenMenu : false , shellContextMenuItemCancellationToken . Token ) ;
544
541
if ( shellMenuItems . Any ( ) )
545
542
AddShellItemsToMenu ( shellMenuItems , BaseContextMenuFlyout , shiftPressed ) ;
546
543
}
@@ -556,7 +553,7 @@ public void UpdateSelectionSize()
556
553
var items = ( selectedItems ? . Any ( ) ?? false ) ? selectedItems : GetAllItems ( ) ;
557
554
if ( items is null )
558
555
return ;
559
- bool isSizeKnown = ! items . Any ( item => string . IsNullOrEmpty ( item . FileSize ) ) ;
556
+ var isSizeKnown = ! items . Any ( item => string . IsNullOrEmpty ( item . FileSize ) ) ;
560
557
if ( isSizeKnown )
561
558
{
562
559
long size = items . Sum ( item => item . FileSizeBytes ) ;
@@ -579,7 +576,7 @@ private async Task LoadMenuItemsAsync()
579
576
shellContextMenuItemCancellationToken = new CancellationTokenSource ( ) ;
580
577
SelectedItemsPropertiesViewModel . CheckAllFileExtensions ( SelectedItems ! . Select ( selectedItem => selectedItem ? . FileExtension ) . ToList ( ) ! ) ;
581
578
var shiftPressed = Microsoft . UI . Input . InputKeyboardSource . GetKeyStateForCurrentThread ( VirtualKey . Shift ) . HasFlag ( Windows . UI . Core . CoreVirtualKeyStates . Down ) ;
582
- var items = ContextFlyoutItemHelper . GetItemContextCommandsWithoutShellItems ( currentInstanceViewModel : InstanceViewModel ! , workingDir : ParentShellPageInstance ! . FilesystemViewModel . WorkingDirectory , selectedItems : SelectedItems ! , selectedItemsPropertiesViewModel : SelectedItemsPropertiesViewModel , commandsViewModel : CommandsViewModel ! , shiftPressed : shiftPressed , showOpenMenu : false ) ;
579
+ var items = ContextFlyoutItemHelper . GetItemContextCommandsWithoutShellItems ( currentInstanceViewModel : InstanceViewModel ! , selectedItems : SelectedItems ! , selectedItemsPropertiesViewModel : SelectedItemsPropertiesViewModel , commandsViewModel : CommandsViewModel ! , shiftPressed : shiftPressed ) ;
583
580
ItemContextMenuFlyout . PrimaryCommands . Clear ( ) ;
584
581
ItemContextMenuFlyout . SecondaryCommands . Clear ( ) ;
585
582
var ( primaryElements , secondaryElements ) = ItemModelListToContextFlyoutHelper . GetAppBarItemsFromModel ( items ) ;
@@ -593,7 +590,7 @@ private async Task LoadMenuItemsAsync()
593
590
594
591
if ( ! InstanceViewModel . IsPageTypeZipFolder )
595
592
{
596
- var shellMenuItems = await ContextFlyoutItemHelper . GetItemContextShellCommandsAsync ( currentInstanceViewModel : InstanceViewModel , workingDir : ParentShellPageInstance . FilesystemViewModel . WorkingDirectory , selectedItems : SelectedItems ! , shiftPressed : shiftPressed , showOpenMenu : false , shellContextMenuItemCancellationToken . Token ) ;
593
+ var shellMenuItems = await ContextFlyoutItemHelper . GetItemContextShellCommandsAsync ( workingDir : ParentShellPageInstance . FilesystemViewModel . WorkingDirectory , selectedItems : SelectedItems ! , shiftPressed : shiftPressed , showOpenMenu : false , shellContextMenuItemCancellationToken . Token ) ;
597
594
if ( shellMenuItems . Any ( ) )
598
595
AddShellItemsToMenu ( shellMenuItems , ItemContextMenuFlyout , shiftPressed ) ;
599
596
}
@@ -708,9 +705,7 @@ private void AddShellItemsToMenu(List<ContextMenuFlyoutItemViewModel> shellMenuI
708
705
flyout . Items . Clear ( ) ;
709
706
710
707
foreach ( var item in openWithSubItems )
711
- {
712
708
flyout . Items . Add ( item ) ;
713
- }
714
709
715
710
openWithOverflow . Flyout = flyout ;
716
711
openWith . Visibility = Visibility . Collapsed ;
@@ -1079,12 +1074,11 @@ private void UpdateCollectionViewSource()
1079
1074
1080
1075
protected void SemanticZoom_ViewChangeStarted ( object sender , SemanticZoomViewChangedEventArgs e )
1081
1076
{
1082
- if ( ! e . IsSourceZoomedInView )
1083
- {
1084
- // According to the docs this isn't necessary, but it would crash otherwise
1085
- var destination = e . DestinationItem . Item as GroupedCollection < ListedItem > ;
1086
- e . DestinationItem . Item = destination ? . FirstOrDefault ( ) ;
1087
- }
1077
+ if ( e . IsSourceZoomedInView )
1078
+ return ;
1079
+ // According to the docs this isn't necessary, but it would crash otherwise
1080
+ var destination = e . DestinationItem . Item as GroupedCollection < ListedItem > ;
1081
+ e . DestinationItem . Item = destination ? . FirstOrDefault ( ) ;
1088
1082
}
1089
1083
1090
1084
protected void StackPanel_PointerEntered ( object sender , PointerRoutedEventArgs e )
@@ -1110,7 +1104,10 @@ protected void RootPanel_PointerPressed(object sender, PointerRoutedEventArgs e)
1110
1104
1111
1105
private void ItemManipulationModel_RefreshItemsOpacityInvoked ( object ? sender , EventArgs e )
1112
1106
{
1113
- foreach ( ListedItem listedItem in GetAllItems ( ) )
1107
+ var items = GetAllItems ( ) ;
1108
+ if ( items is null )
1109
+ return ;
1110
+ foreach ( ListedItem listedItem in items )
1114
1111
{
1115
1112
if ( listedItem . IsHiddenItem )
1116
1113
listedItem . Opacity = Constants . UI . DimItemOpacity ;
0 commit comments