Skip to content

Commit

Permalink
Add support for dropping to recycle bin
Browse files Browse the repository at this point in the history
  • Loading branch information
gave92 committed Jun 19, 2021
1 parent 94cf7d8 commit a20bbce
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 16 deletions.
4 changes: 2 additions & 2 deletions Files/Filesystem/FilesystemOperations/FilesystemOperations.cs
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ public async Task<IStorageHistory> CopyAsync(IStorageItemWithPath source,
IProgress<FileSystemStatusCode> errorCode,
CancellationToken cancellationToken)
{
if (associatedInstance.FilesystemViewModel.WorkingDirectory.StartsWith(App.AppSettings.RecycleBinPath))
if (destination.StartsWith(App.AppSettings.RecycleBinPath))
{
errorCode?.Report(FileSystemStatusCode.Unauthorized);
progress?.Report(100.0f);
Expand Down Expand Up @@ -331,7 +331,7 @@ public async Task<IStorageHistory> MoveAsync(IStorageItemWithPath source,
return await CopyAsync(source, destination, collision, progress, errorCode, cancellationToken);
}

if (associatedInstance.FilesystemViewModel.WorkingDirectory.StartsWith(App.AppSettings.RecycleBinPath))
if (destination.StartsWith(App.AppSettings.RecycleBinPath))
{
errorCode?.Report(FileSystemStatusCode.Unauthorized);
progress?.Report(100.0f);
Expand Down
46 changes: 35 additions & 11 deletions Files/Filesystem/FilesystemOperations/Helpers/FilesystemHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -473,6 +473,10 @@ public async Task<ReturnResult> PerformOperationTypeAsync(DataPackageOperation o
{
return default;
}
if (destination.StartsWith(App.AppSettings.RecycleBinPath))
{
return await RecycleItemsFromClipboard(packageView, destination, showDialog, registerHistory);
}
else if (operation.HasFlag(DataPackageOperation.Copy))
{
return await CopyItemsFromClipboard(packageView, destination, showDialog, registerHistory);
Expand Down Expand Up @@ -676,6 +680,36 @@ public async Task<ReturnResult> CopyItemAsync(IStorageItemWithPath source, strin
return returnStatus;
}

public async Task<ReturnResult> RecycleItemsFromClipboard(DataPackageView packageView, string destination, bool showDialog, bool registerHistory)
{
if (!packageView.Contains(StandardDataFormats.StorageItems))
{
// Happens if you copy some text and then you Ctrl+V in Files
return ReturnResult.BadArgumentException;
}

IReadOnlyList<IStorageItem> source;
try
{
source = await packageView.GetStorageItemsAsync();
}
catch (Exception ex) when ((uint)ex.HResult == 0x80040064 || (uint)ex.HResult == 0x8004006A)
{
// Not supported
return ReturnResult.Failed;
}
catch (Exception ex)
{
App.Logger.Warn(ex, ex.Message);
return ReturnResult.UnknownException;
}
ReturnResult returnStatus = ReturnResult.InProgress;

returnStatus = await DeleteItemsAsync(source, showDialog, false, registerHistory);

return returnStatus;
}

public async Task<ReturnResult> CopyItemsFromClipboard(DataPackageView packageView, string destination, bool showDialog, bool registerHistory)
{
if (packageView.Contains(StandardDataFormats.StorageItems))
Expand Down Expand Up @@ -744,7 +778,6 @@ public async Task<ReturnResult> CopyItemsFromClipboard(DataPackageView packageVi
}

// Happens if you copy some text and then you Ctrl+V in Files
// Should this be done in ModernShellPage?
return ReturnResult.BadArgumentException;
}

Expand Down Expand Up @@ -929,7 +962,6 @@ public async Task<ReturnResult> MoveItemsFromClipboard(DataPackageView packageVi
if (!packageView.Contains(StandardDataFormats.StorageItems))
{
// Happens if you copy some text and then you Ctrl+V in Files
// Should this be done in ModernShellPage?
return ReturnResult.BadArgumentException;
}

Expand All @@ -940,15 +972,7 @@ public async Task<ReturnResult> MoveItemsFromClipboard(DataPackageView packageVi
}
catch (Exception ex) when ((uint)ex.HResult == 0x80040064 || (uint)ex.HResult == 0x8004006A)
{
if (associatedInstance.ServiceConnection != null)
{
var (status, response) = await associatedInstance.ServiceConnection.SendMessageForResponseAsync(new ValueSet() {
{ "Arguments", "FileOperation" },
{ "fileop", "DragDrop" },
{ "droptext", "DragDropWindowText".GetLocalized() },
{ "droppath", associatedInstance.FilesystemViewModel.WorkingDirectory } });
return (status == AppServiceResponseStatus.Success && response.Get("Success", false)) ? ReturnResult.Success : ReturnResult.Failed;
}
// Not supported
return ReturnResult.Failed;
}
catch (Exception ex)
Expand Down
7 changes: 6 additions & 1 deletion Files/Interacts/BaseLayoutCommandImplementationModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -535,7 +535,12 @@ public virtual async void DragOver(DragEventArgs e)
else
{
e.DragUIOverride.IsCaptionVisible = true;
if (e.Modifiers.HasFlag(DragDropModifiers.Control))
if (pwd.StartsWith(App.AppSettings.RecycleBinPath))
{
e.DragUIOverride.Caption = string.Format("MoveToFolderCaptionText".GetLocalized(), folderName);
e.AcceptedOperation = DataPackageOperation.Move;
}
else if (e.Modifiers.HasFlag(DragDropModifiers.Control))
{
e.DragUIOverride.Caption = string.Format("CopyToFolderCaptionText".GetLocalized(), folderName);
e.AcceptedOperation = DataPackageOperation.Copy;
Expand Down
8 changes: 6 additions & 2 deletions Files/UserControls/SidebarControl.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -493,7 +493,6 @@ private async void NavigationViewLocationItem_DragOver(object sender, DragEventA
}

if (string.IsNullOrEmpty(locationItem.Path) ||
locationItem.Path.Equals(App.AppSettings.RecycleBinPath, StringComparison.OrdinalIgnoreCase) ||
(storageItems.Any() && storageItems.AreItemsAlreadyInFolder(locationItem.Path)))
{
e.AcceptedOperation = DataPackageOperation.None;
Expand All @@ -507,7 +506,12 @@ private async void NavigationViewLocationItem_DragOver(object sender, DragEventA
else
{
e.DragUIOverride.IsCaptionVisible = true;
if (e.Modifiers.HasFlag(DragDropModifiers.Control))
if (locationItem.Path.StartsWith(App.AppSettings.RecycleBinPath))
{
e.DragUIOverride.Caption = string.Format("MoveToFolderCaptionText".GetLocalized(), locationItem.Text);
e.AcceptedOperation = DataPackageOperation.Move;
}
else if (e.Modifiers.HasFlag(DragDropModifiers.Control))
{
e.DragUIOverride.Caption = string.Format("CopyToFolderCaptionText".GetLocalized(), locationItem.Text);
e.AcceptedOperation = DataPackageOperation.Copy;
Expand Down

0 comments on commit a20bbce

Please sign in to comment.