Skip to content
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 a new TypeConverter for ToolStripMenuItem.ShortcutKeys that does not provide standard items #13039

Closed

Conversation

Tanya-Solyanik
Copy link
Member

@Tanya-Solyanik Tanya-Solyanik commented Feb 27, 2025

Fixes #12982

Proposed changes

ToolStripMenuItem.ShortcutKeys property type (Keys enum) has a TypeConverter that reports that it has a set of standard values. This is not entirely accurate. Keys type has a set of standard values, but the ShortcutKeys property does not, even the ShortcutKeys type contains different key combinations from what can be generated by the shortcut key editor. Shortcuts are combinations of keys and modifiers, it's not practical to present all combinations for user to step through with up/down keys or with mouse wheel. To disable this behavior, we need to add a new TypeConverter that does not provide standard values.
I would like to add a new TypeConverter to this property. KeysConverter is defined on the Keys enum, the property does not have one right now. TypeDescriptor prioretizes attributese defined on properties over those defined on property types. This change is "borderline" allowed depending on whether this is considered a changed attribute or a new one https://github.com/dotnet/runtime/blob/main/docs/coding-guidelines/breaking-change-rules.md#attributes.

We don't have any other public instance properties of type Keys.

This behavior regressed when we added Keys.None value to the list of standard values - #8401. This was done to localize "None" (as "(none)") in the property grid. When the current value of the shortcut is not one of the standard values, property grid entry does not enter the "scroll through the standard items" functionality. This is a beneficial change, I'd prefer to keep it.

Video.Project.3.mp4
Microsoft Reviewers: Open in CodeFlow

@Tanya-Solyanik Tanya-Solyanik requested a review from a team as a code owner February 27, 2025 06:17
@Tanya-Solyanik Tanya-Solyanik requested review from Copilot and removed request for a team February 27, 2025 06:28
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PR Overview

This PR introduces a new ShortcutKeysConverter that disables the provision of standard shortcut key values for ToolStripMenuItem.ShortcutKeys, addressing an issue where standard values were erroneously reported. The changes include:

  • Adding a new ShortcutKeysConverter class and corresponding tests.
  • Updating ToolStripMenuItem to use the new converter and improving layout transaction calls.
  • Adjusting test naming and minor cleanups in supporting files.

Reviewed Changes

File Description
tests/UnitTests/System/Windows/Forms/ShortcutKeysConverterTests.cs Adds tests for the new converter ensuring no standard values are provided.
src/System/Windows/Forms/Controls/ToolStrips/ShortcutKeysConverter.cs Introduces the new converter with empty standard values and GetStandardValuesSupported returning false.
tests/UnitTests/System/Windows/Forms/PropertyGridTests.cs Adds a regression test to validate mouse wheel behavior on shortcut keys in the PropertyGrid.
src/System/Windows/Forms/Controls/ToolStrips/ToolStripMenuItem.cs Applies the new converter attribute and improves tooltip layout calls using nameof().
src/System.Private.Windows.Core/src/System/SpanHelpers.cs Removes obsolete pragma warning directives around string termination.
tests/UnitTests/System/Windows/Forms/PropertyGridInternal/PropertyGridView.DropDownHolderTests.cs Renames a test method for clarity.
src/System/Windows/Forms/Controls/PropertyGrid/PropertyGridInternal/PropertyGridView.cs Reformats a conditional check for improved readability.

Copilot reviewed 7 out of 7 changed files in this pull request and generated 1 comment.

Comments suppressed due to low confidence (1)

src/System.Private.Windows.Core/src/System/SpanHelpers.cs:24

  • [nitpick] The removal of #pragma warning disable/restore suggests that the assignment's potential warning is now expected; please add a comment clarifying that this assignment is intentional to prevent new IDE warnings.
destination[source.Length] = '\0';

Copy link

codecov bot commented Feb 27, 2025

Codecov Report

Attention: Patch coverage is 91.89189% with 3 lines in your changes missing coverage. Please review.

Project coverage is 76.11217%. Comparing base (6e112b8) to head (599e6d7).
Report is 1 commits behind head on main.

Additional details and impacted files
@@                 Coverage Diff                 @@
##                main      #13039         +/-   ##
===================================================
- Coverage   76.14135%   76.11217%   -0.02918%     
===================================================
  Files           3275        3277          +2     
  Lines         643775      643809         +34     
  Branches       47441       47443          +2     
===================================================
- Hits          490179      490017        -162     
- Misses        150036      150237        +201     
+ Partials        3560        3555          -5     
Flag Coverage Δ
Debug 76.11217% <91.89189%> (-0.02918%) ⬇️
integration 18.04788% <0.00000%> (-0.07833%) ⬇️
production 50.14809% <71.42857%> (-0.06751%) ⬇️
test 96.94986% <96.66667%> (+0.00024%) ⬆️
unit 47.55394% <71.42857%> (-0.00782%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

…er does not provide standard items
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Exception pops up when moving the mouse wheel up or down in ShortcutKeys property
2 participants