Files
PowerToys/src/modules/cmdpal/Microsoft.CmdPal.UI.ViewModels/CommandContextItemViewModel.cs
Mike Griese abdd298c3c Add support for commands on content pages (#495)
Basically just abstracts what we already had for list items, and uses that abstraction for contentpageviewmodel too


Closes #476
2025-03-05 14:08:14 -08:00

43 lines
1.3 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 Microsoft.CmdPal.UI.ViewModels.Models;
using Microsoft.CommandPalette.Extensions;
namespace Microsoft.CmdPal.UI.ViewModels;
public partial class CommandContextItemViewModel(ICommandContextItem contextItem, IPageContext context) : CommandItemViewModel(new(contextItem), context)
{
public new ExtensionObject<ICommandContextItem> Model { get; } = new(contextItem);
public bool IsCritical { get; private set; }
public KeyChord? RequestedShortcut { get; private set; }
public override void InitializeProperties()
{
if (IsInitialized)
{
return;
}
base.InitializeProperties();
var contextItem = Model.Unsafe;
if (contextItem == null)
{
return; // throw?
}
IsCritical = contextItem.IsCritical;
if (contextItem.RequestedShortcut != null)
{
RequestedShortcut = new(
contextItem.RequestedShortcut.Modifiers,
contextItem.RequestedShortcut.Vkey,
contextItem.RequestedShortcut.ScanCode);
}
}
}