Skip to content

Commit 2034ee6

Browse files
authored
Added drop to pin folder/s to Favorites (#6129)
1 parent d1af645 commit 2034ee6

File tree

1 file changed

+54
-7
lines changed

1 file changed

+54
-7
lines changed

Files/UserControls/SidebarControl.xaml.cs

Lines changed: 54 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
using System.Windows.Input;
2020
using Windows.ApplicationModel.DataTransfer;
2121
using Windows.ApplicationModel.DataTransfer.DragDrop;
22+
using Windows.Storage;
2223
using Windows.System;
2324
using Windows.UI.Core;
2425
using Windows.UI.Xaml;
@@ -498,6 +499,8 @@ private void NavigationViewItem_DragStarting(UIElement sender, DragStartingEvent
498499

499500
private object dragOverSection, dragOverItem = null;
500501

502+
private bool isDropOnProcess = false;
503+
501504
private void NavigationViewItem_DragEnter(object sender, DragEventArgs e)
502505
{
503506
VisualStateManager.GoToState(sender as Microsoft.UI.Xaml.Controls.NavigationViewItem, "DragEnter", false);
@@ -542,6 +545,8 @@ private void NavigationViewItem_DragLeave(object sender, DragEventArgs e)
542545
{
543546
VisualStateManager.GoToState(sender as Microsoft.UI.Xaml.Controls.NavigationViewItem, "DragLeave", false);
544547

548+
isDropOnProcess = false;
549+
545550
if ((sender as Microsoft.UI.Xaml.Controls.NavigationViewItem).DataContext is INavigationControlItem)
546551
{
547552
if (sender == dragOverItem)
@@ -569,11 +574,36 @@ private async void NavigationViewLocationItem_DragOver(object sender, DragEventA
569574
if (Filesystem.FilesystemHelpers.HasDraggedStorageItems(e.DataView))
570575
{
571576
e.Handled = true;
577+
isDropOnProcess = true;
572578

573579
var (handledByFtp, storageItems) = await Filesystem.FilesystemHelpers.GetDraggedStorageItems(e.DataView);
574580
storageItems ??= new List<IStorageItemWithPath>();
575581

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) ||
577607
(storageItems.Any() && storageItems.AreItemsAlreadyInFolder(locationItem.Path))
578608
|| locationItem.Path.StartsWith("Home".GetLocalized(), StringComparison.OrdinalIgnoreCase))
579609
{
@@ -668,7 +698,7 @@ private void NavigationViewLocationItem_DragOver_SetCaptions(LocationItem sender
668698
}
669699
}
670700

671-
private void NavigationViewLocationItem_Drop(object sender, DragEventArgs e)
701+
private async void NavigationViewLocationItem_Drop(object sender, DragEventArgs e)
672702
{
673703
dragOverItem = null; // Reset dragged over item
674704
dragOverSection = null; // Reset dragged over section
@@ -684,12 +714,29 @@ private void NavigationViewLocationItem_Drop(object sender, DragEventArgs e)
684714
VisualStateManager.GoToState(sender as Microsoft.UI.Xaml.Controls.NavigationViewItem, "Drop", false);
685715

686716
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
688730
{
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;
693740
deferral.Complete();
694741
}
695742
else if ((e.DataView.Properties["sourceLocationItem"] as Microsoft.UI.Xaml.Controls.NavigationViewItem).DataContext is LocationItem sourceLocationItem)

0 commit comments

Comments
 (0)