2025-07-15 12:21:44 -05:00
|
|
|
// Copyright (c) Microsoft Corporation
|
2025-06-05 08:56:13 -05:00
|
|
|
// The Microsoft Corporation licenses this file to you under the MIT license.
|
|
|
|
// See the LICENSE file in the project root for more information.
|
|
|
|
|
2025-07-15 12:21:44 -05:00
|
|
|
using Microsoft.CmdPal.Core.ViewModels.Models;
|
2025-06-05 08:56:13 -05:00
|
|
|
using Microsoft.CommandPalette.Extensions;
|
|
|
|
|
2025-07-15 12:21:44 -05:00
|
|
|
namespace Microsoft.CmdPal.Core.ViewModels;
|
2025-06-05 08:56:13 -05:00
|
|
|
|
|
|
|
public partial class DetailsCommandsViewModel(
|
|
|
|
IDetailsElement _detailsElement,
|
|
|
|
WeakReference<IPageContext> context) : DetailsElementViewModel(_detailsElement, context)
|
|
|
|
{
|
|
|
|
public List<CommandViewModel> Commands { get; private set; } = [];
|
|
|
|
|
|
|
|
public bool HasCommands => Commands.Count > 0;
|
|
|
|
|
|
|
|
private readonly ExtensionObject<IDetailsCommands> _dataModel =
|
|
|
|
new(_detailsElement.Data as IDetailsCommands);
|
|
|
|
|
|
|
|
public override void InitializeProperties()
|
|
|
|
{
|
|
|
|
base.InitializeProperties();
|
|
|
|
var model = _dataModel.Unsafe;
|
2025-08-18 06:07:28 -05:00
|
|
|
if (model is null)
|
2025-06-05 08:56:13 -05:00
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
Commands = model
|
|
|
|
.Commands?
|
|
|
|
.Select(c =>
|
|
|
|
{
|
|
|
|
var vm = new CommandViewModel(c, PageContext);
|
|
|
|
vm.InitializeProperties();
|
|
|
|
return vm;
|
|
|
|
})
|
|
|
|
.ToList() ?? [];
|
|
|
|
UpdateProperty(nameof(HasCommands));
|
|
|
|
UpdateProperty(nameof(Commands));
|
|
|
|
}
|
|
|
|
}
|