mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-02-24 04:00:02 +01:00
_targets #38573_ At first I just wanted to add support for nested context menus. But then I also had to add a search box, so the focus wouldn't get weird. End result:  This gets rid of the need to have the search box and the command bar both track item keybindings - now it's just in the command bar. Closes #38299 Closes #38442
56 lines
1.9 KiB
C#
56 lines
1.9 KiB
C#
// Copyright (c) Microsoft Corporation
|
|
// The Microsoft Corporation licenses this file to you under the MIT license.
|
|
// See the LICENSE file in the project root for more information.
|
|
|
|
using System.ComponentModel;
|
|
using Microsoft.CommandPalette.Extensions;
|
|
|
|
namespace Microsoft.CmdPal.UI.ViewModels.Messages;
|
|
|
|
/// <summary>
|
|
/// Used to update the command bar at the bottom to reflect the commands for a list item
|
|
/// </summary>
|
|
public record UpdateCommandBarMessage(ICommandBarContext? ViewModel)
|
|
{
|
|
}
|
|
|
|
public interface IContextMenuContext : INotifyPropertyChanged
|
|
{
|
|
public IEnumerable<CommandContextItemViewModel> MoreCommands { get; }
|
|
|
|
public bool HasMoreCommands { get; }
|
|
|
|
public List<CommandContextItemViewModel> AllCommands { get; }
|
|
|
|
/// <summary>
|
|
/// Generates a mapping of key -> command item for this particular item's
|
|
/// MoreCommands. (This won't include the primary Command, but it will
|
|
/// include the secondary one). This map can be used to quickly check if a
|
|
/// shortcut key was pressed
|
|
/// </summary>
|
|
/// <returns>a dictionary of KeyChord -> Context commands, for all commands
|
|
/// that have a shortcut key set.</returns>
|
|
public Dictionary<KeyChord, CommandContextItemViewModel> Keybindings()
|
|
{
|
|
return MoreCommands
|
|
.Where(c => c.HasRequestedShortcut)
|
|
.ToDictionary(
|
|
c => c.RequestedShortcut ?? new KeyChord(0, 0, 0),
|
|
c => c);
|
|
}
|
|
}
|
|
|
|
// Represents everything the command bar needs to know about to show command
|
|
// buttons at the bottom.
|
|
//
|
|
// This is implemented by both ListItemViewModel and ContentPageViewModel,
|
|
// the two things with sub-commands.
|
|
public interface ICommandBarContext : IContextMenuContext
|
|
{
|
|
public string SecondaryCommandName { get; }
|
|
|
|
public CommandItemViewModel? PrimaryCommand { get; }
|
|
|
|
public CommandItemViewModel? SecondaryCommand { get; }
|
|
}
|