Fix: Nested presets failing with 17+ files due to menu collision #644
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Upstream Issue:
On the current upstream branch, converting 17+ files at once revealed a bug where the program wouldn't necessarily choose the correct conversion profile. The issue lies in Windows Explorer's context menu, which runs an optimization when more than 16 files are selected.
Explanation of the Bug:
My investigation suggests that when 16 or less files are selected, Windows Explorer creates the context menu such that each
ToolStripMenuItemis unique in memory, meaning that even two options with identicaltextproperties are still differentiable and execute different conversion presets.However, with 17+ files, Windows Explorer seems to do an optimization such that multiple instances of
ToolStripMenuItemwith identicaltextproperties are not differentiated. I bet Windows assumes that all menu items with identicaltextproperties reference the same callback, so it assigns them to the handler of the first item instead of creating separate callbacks. However in this case, multipleToolStripMenuItemswith identicaltextproperties were not, in fact, identical.My Workaround:
To prevent Windows from assigning identically named instances of
ToolStripMenuItemto the same callback, I added a unique number of invisible zero-width characters to each option. This makes each menu item'stextproperty unique while keeping the user interface unchanged.Justification:
This approach inflicts a relatively minor refactor of just a few lines. While it is a workaround, the "proper" fix would be a major endeavor and refactor. It would probably consist of giving each menu item its own unique command ID or verb at the shell level (
IContextMenu), but that would either require changes toSharpShellor would require writing native code. Suffice to say—major endeavor.This solution is minimal, doesn’t break existing functionality, and targets a specific, reproducible bug that has been reported at least twice and likely affects all instances of the application.
Issues Resolved:
Fixes #614, #567