19
19
using System . Windows . Input ;
20
20
using Windows . ApplicationModel . DataTransfer ;
21
21
using Windows . ApplicationModel . DataTransfer . DragDrop ;
22
+ using Windows . Storage ;
22
23
using Windows . System ;
23
24
using Windows . UI . Core ;
24
25
using Windows . UI . Xaml ;
@@ -498,6 +499,8 @@ private void NavigationViewItem_DragStarting(UIElement sender, DragStartingEvent
498
499
499
500
private object dragOverSection , dragOverItem = null ;
500
501
502
+ private bool isDropOnProcess = false ;
503
+
501
504
private void NavigationViewItem_DragEnter ( object sender , DragEventArgs e )
502
505
{
503
506
VisualStateManager . GoToState ( sender as Microsoft . UI . Xaml . Controls . NavigationViewItem , "DragEnter" , false ) ;
@@ -542,6 +545,8 @@ private void NavigationViewItem_DragLeave(object sender, DragEventArgs e)
542
545
{
543
546
VisualStateManager . GoToState ( sender as Microsoft . UI . Xaml . Controls . NavigationViewItem , "DragLeave" , false ) ;
544
547
548
+ isDropOnProcess = false ;
549
+
545
550
if ( ( sender as Microsoft . UI . Xaml . Controls . NavigationViewItem ) . DataContext is INavigationControlItem )
546
551
{
547
552
if ( sender == dragOverItem )
@@ -569,11 +574,36 @@ private async void NavigationViewLocationItem_DragOver(object sender, DragEventA
569
574
if ( Filesystem . FilesystemHelpers . HasDraggedStorageItems ( e . DataView ) )
570
575
{
571
576
e . Handled = true ;
577
+ isDropOnProcess = true ;
572
578
573
579
var ( handledByFtp , storageItems ) = await Filesystem . FilesystemHelpers . GetDraggedStorageItems ( e . DataView ) ;
574
580
storageItems ??= new List < IStorageItemWithPath > ( ) ;
575
581
576
- if ( string . IsNullOrEmpty ( locationItem . Path ) ||
582
+ if ( string . IsNullOrEmpty ( locationItem . Path ) && SectionType . Favorites . Equals ( locationItem . Section ) && storageItems . Any ( ) )
583
+ {
584
+ bool haveFoldersToPin = false ;
585
+
586
+ foreach ( var item in storageItems )
587
+ {
588
+ if ( item . ItemType == FilesystemItemType . Directory && ! SidebarPinnedModel . FavoriteItems . Contains ( item . Path ) )
589
+ {
590
+ haveFoldersToPin = true ;
591
+ break ;
592
+ }
593
+ }
594
+
595
+ if ( ! haveFoldersToPin )
596
+ {
597
+ e . AcceptedOperation = DataPackageOperation . None ;
598
+ }
599
+ else
600
+ {
601
+ e . DragUIOverride . IsCaptionVisible = true ;
602
+ e . DragUIOverride . Caption = "BaseLayoutItemContextFlyoutPinToFavorites/Text" . GetLocalized ( ) ;
603
+ e . AcceptedOperation = DataPackageOperation . Move ;
604
+ }
605
+ }
606
+ else if ( string . IsNullOrEmpty ( locationItem . Path ) ||
577
607
( storageItems . Any ( ) && storageItems . AreItemsAlreadyInFolder ( locationItem . Path ) )
578
608
|| locationItem . Path . StartsWith ( "Home" . GetLocalized ( ) , StringComparison . OrdinalIgnoreCase ) )
579
609
{
@@ -668,7 +698,7 @@ private void NavigationViewLocationItem_DragOver_SetCaptions(LocationItem sender
668
698
}
669
699
}
670
700
671
- private void NavigationViewLocationItem_Drop ( object sender , DragEventArgs e )
701
+ private async void NavigationViewLocationItem_Drop ( object sender , DragEventArgs e )
672
702
{
673
703
dragOverItem = null ; // Reset dragged over item
674
704
dragOverSection = null ; // Reset dragged over section
@@ -684,12 +714,29 @@ private void NavigationViewLocationItem_Drop(object sender, DragEventArgs e)
684
714
VisualStateManager . GoToState ( sender as Microsoft . UI . Xaml . Controls . NavigationViewItem , "Drop" , false ) ;
685
715
686
716
var deferral = e . GetDeferral ( ) ;
687
- SidebarItemDropped ? . Invoke ( this , new SidebarItemDroppedEventArgs ( )
717
+
718
+ if ( string . IsNullOrEmpty ( locationItem . Path ) && SectionType . Favorites . Equals ( locationItem . Section ) && isDropOnProcess ) // Pin to Favorites section
719
+ {
720
+ var storageItems = await e . DataView . GetStorageItemsAsync ( ) ;
721
+ foreach ( var item in storageItems )
722
+ {
723
+ if ( item . IsOfType ( StorageItemTypes . Folder ) && ! SidebarPinnedModel . FavoriteItems . Contains ( item . Path ) )
724
+ {
725
+ SidebarPinnedModel . AddItem ( item . Path ) ;
726
+ }
727
+ }
728
+ }
729
+ else
688
730
{
689
- Package = e . DataView ,
690
- ItemPath = locationItem . Path ,
691
- AcceptedOperation = e . AcceptedOperation
692
- } ) ;
731
+ SidebarItemDropped ? . Invoke ( this , new SidebarItemDroppedEventArgs ( )
732
+ {
733
+ Package = e . DataView ,
734
+ ItemPath = locationItem . Path ,
735
+ AcceptedOperation = e . AcceptedOperation
736
+ } ) ;
737
+ }
738
+
739
+ isDropOnProcess = false ;
693
740
deferral . Complete ( ) ;
694
741
}
695
742
else if ( ( e . DataView . Properties [ "sourceLocationItem" ] as Microsoft . UI . Xaml . Controls . NavigationViewItem ) . DataContext is LocationItem sourceLocationItem )
0 commit comments