Fix delete delay. Do not regard user cancellations of permanent deletes as an error, but log them as info anyway. More descriptive name for delete confirmation dialog checkbox.
This commit is contained in:
Родитель
098d912e19
Коммит
e030084128
|
@ -226,24 +226,36 @@ namespace Peek.UI
|
|||
OnPropertyChanged(nameof(DisplayItemCount));
|
||||
|
||||
// Attempt the deletion then navigate to the next file.
|
||||
DispatcherQueue.GetForCurrentThread().TryEnqueue(() =>
|
||||
DispatcherQueue.GetForCurrentThread().TryEnqueue(async () =>
|
||||
{
|
||||
Task.Delay(DeleteDelayMs);
|
||||
await Task.Delay(DeleteDelayMs);
|
||||
int result = DeleteFile(item, hwnd);
|
||||
|
||||
if (result != 0)
|
||||
if (result == 0)
|
||||
{
|
||||
// On failure, log the error, show a message in the UI, and reinstate the
|
||||
// deleted file if it still exists.
|
||||
DeleteErrorMessageHelper.LogError(result);
|
||||
ShowDeleteError(item.Name, result);
|
||||
// Success.
|
||||
return;
|
||||
}
|
||||
|
||||
if (File.Exists(item.Path))
|
||||
if (result == ERROR_CANCELLED)
|
||||
{
|
||||
if (Path.GetPathRoot(item.Path) is string root)
|
||||
{
|
||||
_deletedItemIndexes.Remove(index);
|
||||
OnPropertyChanged(nameof(DisplayItemCount));
|
||||
var driveInfo = new DriveInfo(root);
|
||||
Logger.LogInfo($"User cancelled deletion of \"{item.Name}\" on " +
|
||||
$"{driveInfo.DriveType} drive.");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// For failures other than user cancellation, log the error and show a message
|
||||
// in the UI.
|
||||
DeleteErrorMessageHelper.LogError(result);
|
||||
ShowDeleteError(item.Name, result);
|
||||
}
|
||||
|
||||
// For all errors, reinstate the deleted file if it still exists.
|
||||
ReinstateDeletedFile(item, index);
|
||||
});
|
||||
|
||||
Navigate(_navigationDirection, isAfterDelete: true);
|
||||
|
@ -278,6 +290,15 @@ namespace Peek.UI
|
|||
return result;
|
||||
}
|
||||
|
||||
private void ReinstateDeletedFile(IFileSystemItem item, int index)
|
||||
{
|
||||
if (File.Exists(item.Path))
|
||||
{
|
||||
_deletedItemIndexes.Remove(index);
|
||||
OnPropertyChanged(nameof(DisplayItemCount));
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Informs shell listeners like Explorer windows that a delete operation has occurred.
|
||||
/// </summary>
|
||||
|
|
|
@ -94,6 +94,11 @@ namespace Peek.UI.Native
|
|||
/// <remarks>Declared in shellapi.h./remarks>
|
||||
internal const ushort FOF_WANTNUKEWARNING = 0x4000;
|
||||
|
||||
/// <summary>
|
||||
/// The user cancelled the delete operation. Not classified as an error for our purposes.
|
||||
/// </summary>
|
||||
internal const int ERROR_CANCELLED = 1223;
|
||||
|
||||
/// <summary>
|
||||
/// Common error codes when calling SHFileOperation to delete a file.
|
||||
/// </summary>
|
||||
|
|
|
@ -69,7 +69,7 @@
|
|||
DefaultButton="Close">
|
||||
<StackPanel VerticalAlignment="Stretch" HorizontalAlignment="Stretch" Spacing="12">
|
||||
<TextBlock x:Uid="DeleteConfirmationDialog_Message" TextWrapping="Wrap" />
|
||||
<CheckBox x:Name="DeleteDontAskCheckbox" x:Uid="DeleteConfirmationDialog_DontAskCheckbox" />
|
||||
<CheckBox x:Name="DeleteDontWarnCheckbox" x:Uid="DeleteConfirmationDialog_DontWarnCheckbox" />
|
||||
</StackPanel>
|
||||
</ContentDialog>
|
||||
</Grid>
|
||||
|
|
|
@ -86,8 +86,8 @@ namespace Peek.UI
|
|||
{
|
||||
if (await ShowDeleteConfirmationDialogAsync() == ContentDialogResult.Primary)
|
||||
{
|
||||
// Delete after asking for confirmation. Persist the "Don't ask again" choice if set.
|
||||
ViewModel.DeleteItem(DeleteDontAskCheckbox.IsChecked, this.GetWindowHandle());
|
||||
// Delete after asking for confirmation. Persist the "Don't warn again" choice if set.
|
||||
ViewModel.DeleteItem(DeleteDontWarnCheckbox.IsChecked, this.GetWindowHandle());
|
||||
}
|
||||
}
|
||||
else
|
||||
|
@ -104,8 +104,7 @@ namespace Peek.UI
|
|||
|
||||
private async Task<ContentDialogResult> ShowDeleteConfirmationDialogAsync()
|
||||
{
|
||||
DeleteDontAskCheckbox.IsChecked = false;
|
||||
|
||||
DeleteDontWarnCheckbox.IsChecked = false;
|
||||
DeleteConfirmationDialog.XamlRoot = Content.XamlRoot;
|
||||
|
||||
return await DeleteConfirmationDialog.ShowAsync();
|
||||
|
|
|
@ -369,7 +369,7 @@
|
|||
<data name="DeleteConfirmationDialog_Message.Text" xml:space="preserve">
|
||||
<value>Are you sure you want to delete this file?</value>
|
||||
</data>
|
||||
<data name="DeleteConfirmationDialog_DontAskCheckbox.Content" xml:space="preserve">
|
||||
<data name="DeleteConfirmationDialog_DontWarnCheckbox.Content" xml:space="preserve">
|
||||
<value>Don't show this warning again</value>
|
||||
</data>
|
||||
</root>
|
Загрузка…
Ссылка в новой задаче