Fix: Nested presets failing with 17+ files due to menu collision#644
Open
cypress-exe wants to merge 1 commit intoTichau:integrationfrom
Open
Fix: Nested presets failing with 17+ files due to menu collision#644cypress-exe wants to merge 1 commit intoTichau:integrationfrom
cypress-exe wants to merge 1 commit intoTichau:integrationfrom
Conversation
On the current upstream branch, converting 17+ files at once revealed an underlying issue where the program wouldn't necessarily choose the correct conversion profile. After 16 files are selected, Windows Explorer seems to optimize the context menu such that multiple `ToolStripMenuItems` with identical `text` properties share the same callback, which causes ambiguity issues. As a workaround, each menu's `text` property has a unique number of zero-width characters appended to it. This makes the text technically unique, ensuring that Windows maintains the distinction. Furthermore, it preserves the UI, has a minimal code refactor, and resolves an issue that has been reported at least twice and likely impacts all instances of FileConverter. Fixes Tichau#614, Tichau#567
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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