Window Focus and file deletion with Recycle Bin

Hi all

There seems to be some odd interaction with the Recycle Bin and DO12 (and DO11 and probably previous versions according to this and this)

Specifically, If I have only one window open, being DO itself, highlight a file and press the 'delete' key on the keyboard, or press the 'Delete' button on the tool bar, the title bar will flash as the file is deleted.

This appears to be DO momentarily losing focus. This is only a problem if HELP or a Copy/Move dialog is visible, as the focus occasionally shifts to another window, usually the copy dialog.

I initially disabled preferences/File Operations/Deleting Files/Delete to Recycle Bin where possible, and turned off the delete confirmation, and the problem disappears entirely. (obviously with the delete confirmation focus shifts to the confirmation and back without issue).

I then re-enabled the Recycle Bin usage in DO, but disabled it directly in the Recycle Bin Properties panel. This also fixed the problem.

Can anyone else see this happen? I used a VM to confirm it behaves the same in DO12 and DO11 with a vanilla configuration, and under Windows 8.1 and Windows 10 (I don't have a windows 7 lying around unfortunately).

Explorer replacement mode was initally set to Replace Explorer for All Folders, and turning it off made no difference.

Any idea's?

Thanks in advance

As far as I can tell, It's caused by the Recycle Bin itself.

When you send a file to it, it instantly gives focus to its progress dialog (OperationStatusWindow/Progress in the debug output below), even though the progress dialog has not been made visible and would only be displayed if the operation took much longer. (That's arguably a bug in Windows. It shouldn't take focus until the dialog actually opens.)

Some debug output which tracks window focus during the deletion:

I think this used to happen with Explorer as well, unless I am mistaken, but it seems to prevent it somehow now. I'm not sure if that is done via anything publicly accessible, though. Interestingly, it also happens in File Open dialogs when you delete, but it seems to happen too fast to see it (my debug tool still picks it up). But when I Ctrl-Z to undo the delete in the File Open dialog, that does take enough time to make the dialog's title flash, just like when sending files to the Recycle Bin in Opus.

So this kind of thing is happening to parts of the OS itself as well as Opus, but it seems Explorer has some way to prevent it, which is possibly private to Explorer/Microsoft, since both it and the Recycle Bin are part of the same component.

It's also possible it is a difference between the older SHFileOperation and newer (but very similar) IFileOperation APIs, although I have not investigated that. We use the older API for the Recycle Bin as the newer one is only available on Vista & above only and there hasn't been any need to switch to it. Switching would potentially introduce bugs, by changing something that already works, and would introduce separate code paths for XP and everything else which makes testing harder, but isn't out of the question if there is a benefit. At the same time, it's entirely possible that exactly the same thing happens, as I believe SHFileOperation is actually just a thin wrapper around IFileOperation these days.

Normally the effect is invisible as the confirmation dialog takes focus and it just means there is a very short extra moment before focus returns to the lister.