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

Rename Accelerator to KeyboardAccelerator and Refactor APIs #16740

Merged
merged 28 commits into from
Aug 30, 2023

Conversation

rachelkang
Copy link
Member

@rachelkang rachelkang commented Aug 14, 2023

Description of Change

  • Obsoletes Accelerator and AcceleratorTypeConverter
  • Introduces KeyboardAccelerator
  • Refactors KeyboardAccelerator code
    • moved property to MenuFlyoutItem (this is the only place where it was currently working anyways)
    • introduces Modifiers as an Enum, KeyboardAcceleratorModifiers
    • supports multiple accelerators on Windows
    • removes prioritization over system on MacCatalyst

New usage:

<MenuFlyoutItem Clicked="ItemClicked" Text="Sample text">
    <MenuFlyoutItem.KeyboardAccelerators>
        <KeyboardAccelerator Modifiers="Shift,Ctrl" Key="A" />
    </MenuFlyoutItem.KeyboardAccelerators>
</MenuFlyoutItem>

or

MenuFlyoutItemName.KeyboardAccelerators.Add(new KeyboardAccelerator() { Modifiers=KeyboardAcceleratorModifiers.Shift|KeyboardAcceleratorModifiers.Ctrl, Key="A" });

@samhouts samhouts added this to the .NET 8 GA milestone Aug 15, 2023
@samhouts samhouts added the area-keyboard Keyboard, soft keyboard label Aug 15, 2023
src/Core/src/Core/IMenuElement.cs Outdated Show resolved Hide resolved
@rachelkang rachelkang marked this pull request as ready for review August 17, 2023 16:35
@rachelkang rachelkang requested a review from a team as a code owner August 17, 2023 16:35
@mattleibow
Copy link
Member

mattleibow commented Aug 18, 2023

Is there a reason why? Any conflicts?

Was this a thing in forms?

@rachelkang
Copy link
Member Author

@mattleibow We had some offline team discussions about this that you may have missed :(
We decided to make this change mainly for clarity and discoverability. For those who aren't familiar with the API, "Accelerator" is hard to associate with Keyboard shortcuts. So renaming to "KeyboardAccelerator" more clearly associates the API to Keyboard. From our investigation and understanding, there are not really any other "Accelerator"s other than the Keyboard shortcut kind. And yes, this API was introduced in Forms, but it hadn't been fully implemented before.

@mattleibow
Copy link
Member

mattleibow commented Aug 18, 2023

Is there a reason this is on the element as opposed to an attached property?

<Button Keyboard.Accelerator="" />

This way we can potentially group various arbitrary keyboard things? So we would also do this on menu and stuff.

The people can use it to Seton random things for custom handlers.

I may have a drawn view that allows for something like this:

<MagicView>
    <NotAVisualElement Keyboard.Accelerator="X" />
    <NotAVisualElement Keyboard.Accelerator="Y" />
    <NotAVisualElement Keyboard.Accelerator="Z" />
</MagicView>

I can then have a custom handler MagicViewHandler that understands how to support this. Otherwise we force people to add all accelerators to the root view.

This does not change how we do core. IView or whatever still does the accelerators, but this allows people to reuse the whole parsing and Xaml converters on any element.

@mattleibow
Copy link
Member

D:\a\1\s\src\Core\src\PublicAPI\net-tizen\PublicAPI.Unshipped.txt(60,1): error RS0025: The symbol 'Microsoft.Maui.IMenuElement.KeyboardAccelerators.get -> System.Collections.Generic.IReadOnlyList<Microsoft.Maui.IKeyboardAccelerator!>?' appears more than once in the public API files [D:\a\1\s\src\Core\src\Core.csproj::TargetFramework=net7.0-tizen]

@mattleibow
Copy link
Member

Thinking about my comments and what could happen, I also see UWP uses a property on UIElement. So we probably don't need to over engineer it.

mattleibow
mattleibow previously approved these changes Aug 22, 2023
@rachelkang
Copy link
Member Author

@mattleibow I created an issue to capture the work we'll do later based on our convo offline. Feel free to add more notes there #16936

rachelkang and others added 2 commits August 23, 2023 09:51
…erators

# Conflicts:
#	src/Core/src/PublicAPI/net-android/PublicAPI.Unshipped.txt
#	src/Core/src/PublicAPI/net-ios/PublicAPI.Unshipped.txt
#	src/Core/src/PublicAPI/net-maccatalyst/PublicAPI.Unshipped.txt
#	src/Core/src/PublicAPI/net-tizen/PublicAPI.Unshipped.txt
#	src/Core/src/PublicAPI/net-windows/PublicAPI.Unshipped.txt
#	src/Core/src/PublicAPI/net/PublicAPI.Unshipped.txt
#	src/Core/src/PublicAPI/netstandard/PublicAPI.Unshipped.txt
#	src/Core/src/PublicAPI/netstandard2.0/PublicAPI.Unshipped.txt
@rachelkang
Copy link
Member Author

API diff files, API docs, mac testing in progress

Copy link
Member

@mattleibow mattleibow left a comment

Choose a reason for hiding this comment

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

Looking good. I have a few comments so far.

src/Controls/src/Core/KeyboardAccelerator.cs Outdated Show resolved Hide resolved
src/Controls/src/Core/Menu/MenuFlyoutItem.cs Show resolved Hide resolved
src/Controls/src/Core/Menu/MenuFlyoutItem.cs Outdated Show resolved Hide resolved
src/Controls/src/Core/Menu/MenuItem.cs Show resolved Hide resolved

namespace Microsoft.Maui.Controls.Core.UnitTests
{
public class AcceleratorTypeConverterUnitTests : BaseTestFixture
Copy link
Member

Choose a reason for hiding this comment

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

We can keep this for now, and maybe add some tests to convert from this old type into the new type for compat reasons?

src/Controls/src/Core/Menu/MenuItem.cs Outdated Show resolved Hide resolved
src/Controls/src/Core/Menu/MenuItem.cs Outdated Show resolved Hide resolved
src/Controls/src/Core/Menu/MenuItem.cs Outdated Show resolved Hide resolved
@rachelkang rachelkang requested a review from mattleibow August 29, 2023 21:03
@rachelkang rachelkang changed the title Rename Accelerator to KeyboardAccelerator Rename Accelerator to KeyboardAccelerator and Refactor APIs Aug 29, 2023
mattleibow
mattleibow previously approved these changes Aug 30, 2023
@rmarinho rmarinho enabled auto-merge (squash) August 30, 2023 12:43
@rmarinho rmarinho merged commit f525117 into main Aug 30, 2023
@rmarinho rmarinho deleted the rename-keyboard-accelerators branch August 30, 2023 14:52
@github-actions github-actions bot locked and limited conversation to collaborators Dec 7, 2023
@samhouts samhouts added the fixed-in-8.0.0-rc.1.9171 Look for this fix in 8.0.0-rc.1.9171 label Aug 2, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-keyboard Keyboard, soft keyboard fixed-in-8.0.0-rc.1.9171 Look for this fix in 8.0.0-rc.1.9171
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants