Skip to content

Feature: Display keyboard shortcuts in the right click menu #13120

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

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions src/Files.App/Data/Models/ContextMenuFlyoutItemViewModelBuilder.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright (c) 2023 Files Community
// Licensed under the MIT License. See the LICENSE.

using Files.App.Data.Commands;
using Windows.System;

namespace Files.App.Data.Models
{
Expand Down Expand Up @@ -80,8 +80,17 @@ public ContextMenuFlyoutItemViewModel Build()
viewModel.GlyphFontFamilyName = glyph.FontFamily;
}

if (command.HotKeyText is not null)
viewModel.KeyboardAcceleratorTextOverride = command.HotKeyText;
if (command.HotKeys.Length > 0 &&
!(command.HotKeys[0].Key is Keys.Enter &&
command.HotKeys[0].Modifier is KeyModifiers.None))
{
viewModel.KeyboardAccelerator = new Microsoft.UI.Xaml.Input.KeyboardAccelerator()
{
Key = (VirtualKey)command.HotKeys[0].Key,
Modifiers = (VirtualKeyModifiers)command.HotKeys[0].Modifier
};
viewModel.KeyboardAcceleratorTextOverride = command.HotKeys[0].Label;
}

return viewModel;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,9 @@
// Copyright (c) 2023 Files Community
// Licensed under the MIT License. See the LICENSE.

using Files.App.UserControls;
using Files.App.ViewModels;
using Files.Shared.Extensions;
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Controls;
using Microsoft.UI.Xaml.Media;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;

namespace Files.App.Helpers.ContextFlyouts
{
/// <summary>
Expand Down Expand Up @@ -255,6 +247,12 @@ private static ICommandBarElement GetCommandBarButton(ContextMenuFlyoutItemViewM

if (item.IsPrimary || item.CollapseLabel)
toggleButton.SetValue(ToolTipService.ToolTipProperty, item.Text);

if (item.KeyboardAccelerator is not null && item.KeyboardAcceleratorTextOverride is not null)
{
toggleButton.KeyboardAccelerators.Add(item.KeyboardAccelerator);
toggleButton.KeyboardAcceleratorTextOverride = item.KeyboardAcceleratorTextOverride;
}
}
}
else
Expand All @@ -279,6 +277,12 @@ private static ICommandBarElement GetCommandBarButton(ContextMenuFlyoutItemViewM

if (item.IsPrimary || item.CollapseLabel)
button.SetValue(ToolTipService.ToolTipProperty, item.Text);

if (item.KeyboardAccelerator is not null && item.KeyboardAcceleratorTextOverride is not null)
{
button.KeyboardAccelerators.Add(item.KeyboardAccelerator);
button.KeyboardAcceleratorTextOverride = item.KeyboardAcceleratorTextOverride;
}
}
}

Expand Down