-
Notifications
You must be signed in to change notification settings - Fork 6.6k
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
Add Delete functionality for Peek #35418
base: main
Are you sure you want to change the base?
Conversation
Removed package updates, as these are not relevant to the new functionality.
…rce text. Also altered the text style to be consistent with the FailedFallbackPreviewControl error page.
…into peek-delete
{ | ||
wFunc = FO_DELETE, | ||
pFrom = path + "\0\0", | ||
fFlags = (ushort)(FOF_NOCONFIRMATION | (permanent ? 0 : FOF_ALLOWUNDO)), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this override the recycle bin property? (It is possible to configure the delete confirmation in the recycle bin properties.)
How does Fotos app handle it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This replicates how the Photos application handles deletes. Pressing Delete immediately sends the file to the Recycle Bin without popping up a message, and then it moves on to the next file.
The permanent
argument is there for possible future use, but is always false for now.
@daverayment |
This reverts commit 3a10918.
This comment has been minimized.
This comment has been minimized.
Thanks for your comments and suggestions. I've updated the code with an error InfoBar, which is shown when a delete fails: I've added user-friendly messages for the most common failures. Others result in a generic message being shown on the InfoBar. The failure is also logged, with the code and a more technical error message (taken from If the file still exists after the deletion attempt, it is kept in the items collection for previewing; otherwise it is removed. An aside: Windows Photo handles files being renamed or deleted differently to Peek, in that it seems to constantly monitor the folder. (Try changing the filename of a photo you're previewing and you can see it update in the UI after a second or two.) We may wish to replicate this functionality in the future, as it would be increase robustness, but that it outside of the scope of this issue. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for opening the pull request.
Generally looks good to me, but there's the issue that this might be unintentionally pressed by the user, getting a file deleted he might not have intended. Even though it ends up in the Recycling Bin, I think having a Message Box Prompt first would be safer. I'm OK with a setting to disable this warning, but it should show a confirmation prompt by default.
Hope this makes sense.
Agree. Could also try to get/use the setting for the Recycle Bin itself. |
Doesn't the code does this yet? Or better asked: Isn't this handled by Recycle Bin itself? |
Nope, the code uses |
@jaimecbernardo @htcfreek @Jay-o-Way Thank you for the review and guidance. However, I disagree with displaying a prompt. The default Windows functionality for file deletions is not to show a confirmation prompt. The whole purpose of the Recycle Bin is to to protect against accidental deletions. The behaviour in Peek was deliberately chosen to be consistent with both Windows Explorer and other file viewer tools such as the Windows Photo App and third party apps like IrfanView. I believe users would find a confirmation dialog unnecessary or redundant every time they want to delete a file, which could be a common action when sorting through a large folder of files. Also, PowerToys is supposed to be for power users, so I don't think we should go out of our way to provide guardrails for easily-reversible common mistakes such as accidentally pressing the delete key (which is also not near the default Peek navigation keys). To summarise, I don't think we should provide non-default behaviour which would slow down a user's workflow. |
I imagine you might've already clicked that "Don't show this warning again" @daverayment . |
I've also just tried the feature on an external drive. As expected, files were permanently deleted without going to the recycle bin. I don't feel easy causing potential data loss with a feature that wasn't there before without some initial guardrails so the user understands that feature is there 😅 Hope this makes sense to you. |
Thanks, @jaimecbernardo Sorry, yes, you're right! I must have clicked the "Don't Show" checkbox when I initially started using Windows Photo. Please forgive the lapse in memory - it was a long time ago... 😬 My main concern was that presenting dialogs every time a delete was requested would get in the way, but I'm fine with your suggestion of replicating the Photo app's behaviour with the "Don't Show" checkbox. This will give me a chance to have a play with the Settings code, too, which I've been avoiding. I'm very concerned that the delete operation skipped the Recycle Bin for a file on your external device. Would you mind seeing what your Recycle Bin properties are for that drive, please? It is possible to turn off the Recycle Bin on a per-drive basis: The Peek code just calls the underlying Shell API, so it should be consistent with doing a delete from Explorer (without holding Shift down); it is a bug if it behaves differently for external drives. |
@daverayment using a
https://www.c-sharpcorner.com/blogs/extension-methods-for-delete-files-and-folders-to-recycle-bin Also check out |
@daverayment There's nothing on Recycle Bin for this drive and another I've tested. I'm guessing because their file system is FAT32. |
@daverayment , @jaimecbernardo |
Hi, @Jay-o-Way ! Thanks for the message. It is certainly a shame that System.IO doesn't include recycling options when deleting files. As you noticed, this update to Peek uses the Shell File Operation This isn't enough for our needs, though, so I will add the dialog box to prompt the user when they try to delete a file, as previously discussed. Giving users the option to permanently dismiss this warning replicates what the Windows Photo App does, and is a good compromise for power users. The reason @jaimecbernardo experienced the issue with the FAT32 volume is because I needed to include a flag called The VB Core library containing |
Yes, that's what I assumed we'd be doing. I haven't used the Settings system before, but I'll give it a go and I'll ask if I get stuck! |
Summary of the Pull Request
This PR adds the ability for users to delete the file currently being previewed in Peek.
PR Checklist
Detailed Description of the Pull Request / Additional comments
There are several new and changed elements in this PR:
Items
collection (which could be very large). There are nowDisplayIndex
andDisplayItemCount
properties, which reflect the calculated position and total. The oldCurrentIndex
still points to the actual index of the current item in the collection, but this is now internal only.Shift + Delete
could do a permanent delete, and this is certainly possible in the future, but this release errs on the side of caution, especially as it's a new feature and involves deleting things.NativeMethods.cs
for the API call, struct, flags, and error messages.Screenshots
No More Files message
File Count For Single Remaining File
Validation Steps Performed
(Manual tests only.)
Tested: