Skip to content

Fix: Additional fix to show a confirmation dialog when undoing #11197

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ await DialogDisplayHelper.ShowDialogAsync(

#region Delete

public async Task<ReturnResult> DeleteItemsAsync(IEnumerable<IStorageItemWithPath> source, bool showDialog, bool permanently, bool registerHistory)
public async Task<ReturnResult> DeleteItemsAsync(IEnumerable<IStorageItemWithPath> source, ShowDeleteDialog showDialog, bool permanently, bool registerHistory)
{
source = await source.ToListAsync();

Expand All @@ -125,7 +125,7 @@ public async Task<ReturnResult> DeleteItemsAsync(IEnumerable<IStorageItemWithPat
var deleteFromRecycleBin = source.Select(item => item.Path).Any(path => RecycleBinHelpers.IsPathUnderRecycleBin(path));
var canBeSentToBin = !deleteFromRecycleBin && await RecycleBinHelpers.HasRecycleBin(source.FirstOrDefault()?.Path);

if (showDialog && UserSettingsService.FoldersSettingsService.ShowConfirmDeleteDialog) // Check if the setting to show a confirmation dialog is on
if (showDialog is ShowDeleteDialog.Always || showDialog is ShowDeleteDialog.DependsOnSettings && UserSettingsService.FoldersSettingsService.ShowConfirmDeleteDialog)
{
var incomingItems = new List<BaseFileSystemDialogItemViewModel>();
List<ShellFileItem>? binItems = null;
Expand Down Expand Up @@ -193,13 +193,13 @@ public async Task<ReturnResult> DeleteItemsAsync(IEnumerable<IStorageItemWithPat
return returnStatus;
}

public Task<ReturnResult> DeleteItemAsync(IStorageItemWithPath source, bool showDialog, bool permanently, bool registerHistory)
public Task<ReturnResult> DeleteItemAsync(IStorageItemWithPath source, ShowDeleteDialog showDialog, bool permanently, bool registerHistory)
=> DeleteItemsAsync(source.CreateEnumerable(), showDialog, permanently, registerHistory);

public Task<ReturnResult> DeleteItemsAsync(IEnumerable<IStorageItem> source, bool showDialog, bool permanently, bool registerHistory)
public Task<ReturnResult> DeleteItemsAsync(IEnumerable<IStorageItem> source, ShowDeleteDialog showDialog, bool permanently, bool registerHistory)
=> DeleteItemsAsync(source.Select((item) => item.FromStorageItem()), showDialog, permanently, registerHistory);

public Task<ReturnResult> DeleteItemAsync(IStorageItem source, bool showDialog, bool permanently, bool registerHistory)
public Task<ReturnResult> DeleteItemAsync(IStorageItem source, ShowDeleteDialog showDialog, bool permanently, bool registerHistory)
=> DeleteItemAsync(source.FromStorageItem(), showDialog, permanently, registerHistory);

#endregion Delete
Expand Down Expand Up @@ -259,7 +259,7 @@ public async Task<ReturnResult> PerformOperationTypeAsync(DataPackageOperation o
if (destination.StartsWith(CommonPaths.RecycleBinPath, StringComparison.Ordinal))
{
showDialog |= UserSettingsService.FoldersSettingsService.ShowConfirmDeleteDialog;
return await RecycleItemsFromClipboard(packageView, destination, showDialog, registerHistory);
return await RecycleItemsFromClipboard(packageView, destination, showDialog ? ShowDeleteDialog.DependsOnSettings : ShowDeleteDialog.Never, registerHistory);
}
else if (operation.HasFlag(DataPackageOperation.Copy))
{
Expand Down Expand Up @@ -626,7 +626,7 @@ public async Task<ReturnResult> CreateShortcutFromClipboard(DataPackageView pack
return returnStatus;
}

public async Task<ReturnResult> RecycleItemsFromClipboard(DataPackageView packageView, string destination, bool showDialog, bool registerHistory)
public async Task<ReturnResult> RecycleItemsFromClipboard(DataPackageView packageView, string destination, ShowDeleteDialog showDialog, bool registerHistory)
{
if (!HasDraggedStorageItems(packageView))
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public interface IFilesystemHelpers : IDisposable
/// <param name="permanently">Determines whether <paramref name="source"/> is be deleted permanently</param>
/// <param name="registerHistory">Determines whether <see cref="IStorageHistory"/> is saved</param>
/// <returns><see cref="ReturnResult"/> of performed operation</returns>
Task<ReturnResult> DeleteItemsAsync(IEnumerable<IStorageItem> source, bool showDialog, bool permanently, bool registerHistory);
Task<ReturnResult> DeleteItemsAsync(IEnumerable<IStorageItem> source, ShowDeleteDialog showDialog, bool permanently, bool registerHistory);

/// <summary>
/// Deletes provided <paramref name="source"/>
Expand All @@ -38,7 +38,7 @@ public interface IFilesystemHelpers : IDisposable
/// <param name="permanently">Determines whether <paramref name="source"/> is be deleted permanently</param>
/// <param name="registerHistory">Determines whether <see cref="IStorageHistory"/> is saved</param>
/// <returns><see cref="ReturnResult"/> of performed operation</returns>
Task<ReturnResult> DeleteItemAsync(IStorageItem source, bool showDialog, bool permanently, bool registerHistory);
Task<ReturnResult> DeleteItemAsync(IStorageItem source, ShowDeleteDialog showDialog, bool permanently, bool registerHistory);

/// <summary>
/// Deletes provided <paramref name="source"/>
Expand All @@ -48,7 +48,7 @@ public interface IFilesystemHelpers : IDisposable
/// <param name="permanently">Determines whether <paramref name="source"/> is be deleted permanently</param>
/// <param name="registerHistory">Determines whether <see cref="IStorageHistory"/> is saved</param>
/// <returns><see cref="ReturnResult"/> of performed operation</returns>
Task<ReturnResult> DeleteItemsAsync(IEnumerable<IStorageItemWithPath> source, bool showDialog, bool permanently, bool registerHistory);
Task<ReturnResult> DeleteItemsAsync(IEnumerable<IStorageItemWithPath> source, ShowDeleteDialog showDialog, bool permanently, bool registerHistory);

/// <summary>
/// Deletes provided <paramref name="source"/>
Expand All @@ -58,7 +58,7 @@ public interface IFilesystemHelpers : IDisposable
/// <param name="permanently">Determines whether <paramref name="source"/> is be deleted permanently</param>
/// <param name="registerHistory">Determines whether <see cref="IStorageHistory"/> is saved</param>
/// <returns><see cref="ReturnResult"/> of performed operation</returns>
Task<ReturnResult> DeleteItemAsync(IStorageItemWithPath source, bool showDialog, bool permanently, bool registerHistory);
Task<ReturnResult> DeleteItemAsync(IStorageItemWithPath source, ShowDeleteDialog showDialog, bool permanently, bool registerHistory);

#endregion Delete

Expand Down Expand Up @@ -175,7 +175,7 @@ public interface IFilesystemHelpers : IDisposable
/// <returns><see cref="ReturnResult"/> of performed operation</returns>
Task<ReturnResult> CopyItemsFromClipboard(DataPackageView packageView, string destination, bool showDialog, bool registerHistory);

Task<ReturnResult> RecycleItemsFromClipboard(DataPackageView packageView, string destination, bool showDialog, bool registerHistory);
Task<ReturnResult> RecycleItemsFromClipboard(DataPackageView packageView, string destination, ShowDeleteDialog showDialog, bool registerHistory);

Task<ReturnResult> CreateShortcutFromClipboard(DataPackageView packageView, string destination, bool showDialog, bool registerHistory);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,13 @@ public async Task<ReturnResult> Undo(IStorageHistory history)
case FileOperationType.CreateNew: // Opposite: Delete created items
if (!IsHistoryNull(history.Source))
{
return await helpers.DeleteItemsAsync(history.Source, true, true, false); // Show a dialog to prevent unexpected deletion
return await helpers.DeleteItemsAsync(history.Source, ShowDeleteDialog.Always, true, false); // Show a dialog to prevent unexpected deletion
}
break;
case FileOperationType.CreateLink: // Opposite: Delete created items
if (!IsHistoryNull(history.Destination))
{
return await helpers.DeleteItemsAsync(history.Destination, true, true, false); // Show a dialog to prevent unexpected deletion
return await helpers.DeleteItemsAsync(history.Destination, ShowDeleteDialog.Always, true, false); // Show a dialog to prevent unexpected deletion
}
break;
case FileOperationType.Rename: // Opposite: Restore original item names
Expand All @@ -61,7 +61,7 @@ public async Task<ReturnResult> Undo(IStorageHistory history)
case FileOperationType.Copy: // Opposite: Delete copied items
if (!IsHistoryNull(history.Destination))
{
return await helpers.DeleteItemsAsync(history.Destination, true, true, false); // Show a dialog to prevent unexpected deletion
return await helpers.DeleteItemsAsync(history.Destination, ShowDeleteDialog.Always, true, false); // Show a dialog to prevent unexpected deletion
}
break;
case FileOperationType.Move: // Opposite: Move the items to original directory
Expand Down
2 changes: 1 addition & 1 deletion src/Files.App/Helpers/NavigationHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ public static async Task<bool> OpenPath(string path, IShellPage associatedInstan

// Delete shortcut
var shortcutItem = StorageHelpers.FromPathAndType(path, FilesystemItemType.File);
await associatedInstance.FilesystemHelpers.DeleteItemAsync(shortcutItem, false, false, true);
await associatedInstance.FilesystemHelpers.DeleteItemAsync(shortcutItem, ShowDeleteDialog.Never, false, true);
}
}
else if (isReparsePoint)
Expand Down
2 changes: 1 addition & 1 deletion src/Files.App/Helpers/RecycleBinHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ public static async Task DeleteItem(IShellPage associatedInstance)
var items = associatedInstance.SlimContentPage.SelectedItems.ToList().Select((item) => StorageHelpers.FromPathAndType(
item.ItemPath,
item.PrimaryItemAttribute == StorageItemTypes.File ? FilesystemItemType.File : FilesystemItemType.Directory));
await associatedInstance.FilesystemHelpers.DeleteItemsAsync(items, true, false, true);
await associatedInstance.FilesystemHelpers.DeleteItemsAsync(items, ShowDeleteDialog.DependsOnSettings, false, true);
}
}
}
4 changes: 2 additions & 2 deletions src/Files.App/Views/ColumnShellPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -714,7 +714,7 @@ private async void KeyboardAccelerator_Invoked(KeyboardAccelerator sender, Keybo
var items = SlimContentPage.SelectedItems.ToList().Select((item) => StorageHelpers.FromPathAndType(
item.ItemPath,
item.PrimaryItemAttribute == StorageItemTypes.File ? FilesystemItemType.File : FilesystemItemType.Directory));
await FilesystemHelpers.DeleteItemsAsync(items, true, true, true);
await FilesystemHelpers.DeleteItemsAsync(items, ShowDeleteDialog.DependsOnSettings, true, true);
}

break;
Expand Down Expand Up @@ -758,7 +758,7 @@ private async void KeyboardAccelerator_Invoked(KeyboardAccelerator sender, Keybo
var items = SlimContentPage.SelectedItems.ToList().Select((item) => StorageHelpers.FromPathAndType(
item.ItemPath,
item.PrimaryItemAttribute == StorageItemTypes.File ? FilesystemItemType.File : FilesystemItemType.Directory));
await FilesystemHelpers.DeleteItemsAsync(items, true, false, true);
await FilesystemHelpers.DeleteItemsAsync(items, ShowDeleteDialog.DependsOnSettings, false, true);
}

break;
Expand Down
4 changes: 2 additions & 2 deletions src/Files.App/Views/ModernShellPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -725,7 +725,7 @@ private async void KeyboardAccelerator_Invoked(KeyboardAccelerator sender, Keybo
var items = SlimContentPage.SelectedItems.ToList().Select((item) => StorageHelpers.FromPathAndType(
item.ItemPath,
item.PrimaryItemAttribute == StorageItemTypes.File ? FilesystemItemType.File : FilesystemItemType.Directory));
await FilesystemHelpers.DeleteItemsAsync(items, true, true, true);
await FilesystemHelpers.DeleteItemsAsync(items, ShowDeleteDialog.DependsOnSettings, true, true);
}

break;
Expand Down Expand Up @@ -761,7 +761,7 @@ private async void KeyboardAccelerator_Invoked(KeyboardAccelerator sender, Keybo
var items = SlimContentPage.SelectedItems.ToList().Select((item) => StorageHelpers.FromPathAndType(
item.ItemPath,
item.PrimaryItemAttribute == StorageItemTypes.File ? FilesystemItemType.File : FilesystemItemType.Directory));
await FilesystemHelpers.DeleteItemsAsync(items, true, false, true);
await FilesystemHelpers.DeleteItemsAsync(items, ShowDeleteDialog.DependsOnSettings, false, true);
}

break;
Expand Down
9 changes: 9 additions & 0 deletions src/Files.Shared/Enums/ShowDeleteDialog.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
namespace Files.Shared.Enums
{
public enum ShowDeleteDialog : byte
{
Never,
DependsOnSettings,
Always,
}
}