Skip to content

Commit d9cc70c

Browse files
authored
Feature: Show confirmation dialog when the undo operation is to delete items. (#11185)
1 parent 47e41dd commit d9cc70c

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-5
lines changed

src/Files.App/Filesystem/StorageHistory/Helpers/StorageHistoryHelpers.cs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,18 @@ public async Task<ReturnResult> TryUndo()
2222
{
2323
return ReturnResult.InProgress;
2424
}
25+
bool keepHistory = false;
2526
try
2627
{
27-
return await operations.Undo(App.HistoryWrapper.GetCurrentHistory());
28+
ReturnResult result = await operations.Undo(App.HistoryWrapper.GetCurrentHistory());
29+
keepHistory = result is ReturnResult.Cancelled;
30+
return result;
2831
}
2932
finally
3033
{
31-
App.HistoryWrapper.DecreaseIndex();
34+
if (!keepHistory)
35+
App.HistoryWrapper.DecreaseIndex();
36+
3237
semaphore.Release();
3338
}
3439
}

src/Files.App/Filesystem/StorageHistory/StorageHistoryOperations.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,13 @@ public async Task<ReturnResult> Undo(IStorageHistory history)
3838
case FileOperationType.CreateNew: // Opposite: Delete created items
3939
if (!IsHistoryNull(history.Source))
4040
{
41-
return await helpers.DeleteItemsAsync(history.Source, false, true, false);
41+
return await helpers.DeleteItemsAsync(history.Source, true, true, false); // Show a dialog to prevent unexpected deletion
4242
}
4343
break;
4444
case FileOperationType.CreateLink: // Opposite: Delete created items
4545
if (!IsHistoryNull(history.Destination))
4646
{
47-
return await helpers.DeleteItemsAsync(history.Destination, false, true, false);
47+
return await helpers.DeleteItemsAsync(history.Destination, true, true, false); // Show a dialog to prevent unexpected deletion
4848
}
4949
break;
5050
case FileOperationType.Rename: // Opposite: Restore original item names
@@ -61,7 +61,7 @@ public async Task<ReturnResult> Undo(IStorageHistory history)
6161
case FileOperationType.Copy: // Opposite: Delete copied items
6262
if (!IsHistoryNull(history.Destination))
6363
{
64-
return await helpers.DeleteItemsAsync(history.Destination, false, true, false);
64+
return await helpers.DeleteItemsAsync(history.Destination, true, true, false); // Show a dialog to prevent unexpected deletion
6565
}
6666
break;
6767
case FileOperationType.Move: // Opposite: Move the items to original directory

0 commit comments

Comments
 (0)