Skip to content

Commit f611e4d

Browse files
committed
Change default drop action on Ctrl/Shift
1 parent 083309a commit f611e4d

File tree

3 files changed

+74
-25
lines changed

3 files changed

+74
-25
lines changed

Files/BaseLayout.cs

Lines changed: 27 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
using System.Threading.Tasks;
2323
using Windows.ApplicationModel.Core;
2424
using Windows.ApplicationModel.DataTransfer;
25+
using Windows.ApplicationModel.DataTransfer.DragDrop;
2526
using Windows.Storage;
2627
using Windows.System;
2728
using Windows.UI.Core;
@@ -625,26 +626,38 @@ protected async void Item_DragOver(object sender, DragEventArgs e)
625626
}
626627

627628
e.Handled = true;
628-
e.DragUIOverride.IsCaptionVisible = true;
629-
630629
if (InstanceViewModel.IsPageTypeSearchResults || draggedItems.Any(draggedItem => draggedItem.Path == item.ItemPath))
631630
{
632631
e.AcceptedOperation = DataPackageOperation.None;
633632
}
634-
else if (item.IsExecutable)
635-
{
636-
e.DragUIOverride.Caption = $"{"OpenItemsWithCaptionText".GetLocalized()} {item.ItemName}";
637-
e.AcceptedOperation = DataPackageOperation.Link;
638-
} // Items from the same drive as this folder are dragged into this folder, so we move the items instead of copy
639-
else if (draggedItems.AreItemsInSameDrive(item.ItemPath))
640-
{
641-
e.DragUIOverride.Caption = string.Format("MoveToFolderCaptionText".GetLocalized(), item.ItemName);
642-
e.AcceptedOperation = DataPackageOperation.Move;
643-
}
644633
else
645634
{
646-
e.DragUIOverride.Caption = string.Format("CopyToFolderCaptionText".GetLocalized(), item.ItemName);
647-
e.AcceptedOperation = DataPackageOperation.Copy;
635+
e.DragUIOverride.IsCaptionVisible = true;
636+
if (item.IsExecutable)
637+
{
638+
e.DragUIOverride.Caption = $"{"OpenItemsWithCaptionText".GetLocalized()} {item.ItemName}";
639+
e.AcceptedOperation = DataPackageOperation.Link;
640+
} // Items from the same drive as this folder are dragged into this folder, so we move the items instead of copy
641+
else if (e.Modifiers.HasFlag(DragDropModifiers.Control))
642+
{
643+
e.DragUIOverride.Caption = string.Format("CopyToFolderCaptionText".GetLocalized(), item.ItemName);
644+
e.AcceptedOperation = DataPackageOperation.Copy;
645+
}
646+
else if (e.Modifiers.HasFlag(DragDropModifiers.Shift))
647+
{
648+
e.DragUIOverride.Caption = string.Format("MoveToFolderCaptionText".GetLocalized(), item.ItemName);
649+
e.AcceptedOperation = DataPackageOperation.Move;
650+
}
651+
else if (draggedItems.AreItemsInSameDrive(item.ItemPath))
652+
{
653+
e.DragUIOverride.Caption = string.Format("MoveToFolderCaptionText".GetLocalized(), item.ItemName);
654+
e.AcceptedOperation = DataPackageOperation.Move;
655+
}
656+
else
657+
{
658+
e.DragUIOverride.Caption = string.Format("CopyToFolderCaptionText".GetLocalized(), item.ItemName);
659+
e.AcceptedOperation = DataPackageOperation.Copy;
660+
}
648661
}
649662
}
650663

Files/Interacts/BaseLayoutCommandImplementationModel.cs

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
using System.IO;
1313
using System.Linq;
1414
using Windows.ApplicationModel.DataTransfer;
15+
using Windows.ApplicationModel.DataTransfer.DragDrop;
1516
using Windows.Foundation;
1617
using Windows.Foundation.Collections;
1718
using Windows.Storage;
@@ -500,7 +501,6 @@ public virtual async void DragOver(DragEventArgs e)
500501
if (e.DataView.Contains(StandardDataFormats.StorageItems))
501502
{
502503
e.Handled = true;
503-
e.DragUIOverride.IsCaptionVisible = true;
504504
IEnumerable<IStorageItem> draggedItems = new List<IStorageItem>();
505505
try
506506
{
@@ -521,21 +521,36 @@ public virtual async void DragOver(DragEventArgs e)
521521
return;
522522
}
523523

524-
var folderName = Path.GetFileName(associatedInstance.FilesystemViewModel.WorkingDirectory.TrimPath());
524+
var pwd = associatedInstance.FilesystemViewModel.WorkingDirectory.TrimPath();
525+
var folderName = (Path.IsPathRooted(pwd) && Path.GetPathRoot(pwd) == pwd) ? Path.GetPathRoot(pwd) : Path.GetFileName(pwd);
525526
// As long as one file doesn't already belong to this folder
526527
if (associatedInstance.InstanceViewModel.IsPageTypeSearchResults || draggedItems.AreItemsAlreadyInFolder(associatedInstance.FilesystemViewModel.WorkingDirectory))
527528
{
528529
e.AcceptedOperation = DataPackageOperation.None;
529530
}
530-
else if (draggedItems.AreItemsInSameDrive(associatedInstance.FilesystemViewModel.WorkingDirectory))
531-
{
532-
e.DragUIOverride.Caption = string.Format("MoveToFolderCaptionText".GetLocalized(), folderName);
533-
e.AcceptedOperation = DataPackageOperation.Move;
534-
}
535531
else
536532
{
537-
e.DragUIOverride.Caption = string.Format("CopyToFolderCaptionText".GetLocalized(), folderName);
538-
e.AcceptedOperation = DataPackageOperation.Copy;
533+
e.DragUIOverride.IsCaptionVisible = true;
534+
if (e.Modifiers.HasFlag(DragDropModifiers.Control))
535+
{
536+
e.DragUIOverride.Caption = string.Format("CopyToFolderCaptionText".GetLocalized(), folderName);
537+
e.AcceptedOperation = DataPackageOperation.Copy;
538+
}
539+
else if (e.Modifiers.HasFlag(DragDropModifiers.Shift))
540+
{
541+
e.DragUIOverride.Caption = string.Format("MoveToFolderCaptionText".GetLocalized(), folderName);
542+
e.AcceptedOperation = DataPackageOperation.Move;
543+
}
544+
else if (draggedItems.AreItemsInSameDrive(associatedInstance.FilesystemViewModel.WorkingDirectory))
545+
{
546+
e.DragUIOverride.Caption = string.Format("MoveToFolderCaptionText".GetLocalized(), folderName);
547+
e.AcceptedOperation = DataPackageOperation.Move;
548+
}
549+
else
550+
{
551+
e.DragUIOverride.Caption = string.Format("CopyToFolderCaptionText".GetLocalized(), folderName);
552+
e.AcceptedOperation = DataPackageOperation.Copy;
553+
}
539554
}
540555
}
541556

Files/UserControls/SidebarControl.xaml.cs

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
using System.Threading;
1616
using System.Windows.Input;
1717
using Windows.ApplicationModel.DataTransfer;
18+
using Windows.ApplicationModel.DataTransfer.DragDrop;
1819
using Windows.Storage;
1920
using Windows.System;
2021
using Windows.UI.Core;
@@ -502,7 +503,17 @@ private async void NavigationViewLocationItem_DragOver(object sender, DragEventA
502503
else
503504
{
504505
e.DragUIOverride.IsCaptionVisible = true;
505-
if (storageItems.AreItemsInSameDrive(locationItem.Path) || locationItem.IsDefaultLocation)
506+
if (e.Modifiers.HasFlag(DragDropModifiers.Control))
507+
{
508+
e.DragUIOverride.Caption = string.Format("CopyToFolderCaptionText".GetLocalized(), locationItem.Text);
509+
e.AcceptedOperation = DataPackageOperation.Copy;
510+
}
511+
else if (e.Modifiers.HasFlag(DragDropModifiers.Shift))
512+
{
513+
e.DragUIOverride.Caption = string.Format("MoveToFolderCaptionText".GetLocalized(), locationItem.Text);
514+
e.AcceptedOperation = DataPackageOperation.Move;
515+
}
516+
else if (storageItems.AreItemsInSameDrive(locationItem.Path) || locationItem.IsDefaultLocation)
506517
{
507518
e.AcceptedOperation = DataPackageOperation.Move;
508519
e.DragUIOverride.Caption = string.Format("MoveToFolderCaptionText".GetLocalized(), locationItem.Text);
@@ -617,7 +628,17 @@ private async void NavigationViewDriveItem_DragOver(object sender, DragEventArgs
617628
else
618629
{
619630
e.DragUIOverride.IsCaptionVisible = true;
620-
if (storageItems.AreItemsInSameDrive(driveItem.Path))
631+
if (e.Modifiers.HasFlag(DragDropModifiers.Control))
632+
{
633+
e.DragUIOverride.Caption = string.Format("CopyToFolderCaptionText".GetLocalized(), driveItem.Text);
634+
e.AcceptedOperation = DataPackageOperation.Copy;
635+
}
636+
else if (e.Modifiers.HasFlag(DragDropModifiers.Shift))
637+
{
638+
e.DragUIOverride.Caption = string.Format("MoveToFolderCaptionText".GetLocalized(), driveItem.Text);
639+
e.AcceptedOperation = DataPackageOperation.Move;
640+
}
641+
else if (storageItems.AreItemsInSameDrive(driveItem.Path))
621642
{
622643
e.AcceptedOperation = DataPackageOperation.Move;
623644
e.DragUIOverride.Caption = string.Format("MoveToFolderCaptionText".GetLocalized(), driveItem.Text);

0 commit comments

Comments
 (0)