/ src / modules / cmdpal / Core / Microsoft.CmdPal.Core.ViewModels / ConfirmResultViewModel.cs
ConfirmResultViewModel.cs
 1  // Copyright (c) Microsoft Corporation
 2  // The Microsoft Corporation licenses this file to you under the MIT license.
 3  // See the LICENSE file in the project root for more information.
 4  
 5  using Microsoft.CmdPal.Core.ViewModels.Models;
 6  using Microsoft.CommandPalette.Extensions;
 7  
 8  namespace Microsoft.CmdPal.Core.ViewModels;
 9  
10  public partial class ConfirmResultViewModel(IConfirmationArgs _args, WeakReference<IPageContext> context) :
11      ExtensionObjectViewModel(context)
12  {
13      public ExtensionObject<IConfirmationArgs> Model { get; } = new(_args);
14  
15      // Remember - "observable" properties from the model (via PropChanged)
16      // cannot be marked [ObservableProperty]
17      public string Title { get; private set; } = string.Empty;
18  
19      public string Description { get; private set; } = string.Empty;
20  
21      public bool IsPrimaryCommandCritical { get; private set; }
22  
23      public CommandViewModel PrimaryCommand { get; private set; } = new(null, context);
24  
25      public override void InitializeProperties()
26      {
27          var model = Model.Unsafe;
28          if (model is null)
29          {
30              return;
31          }
32  
33          Title = model.Title;
34          Description = model.Description;
35          IsPrimaryCommandCritical = model.IsPrimaryCommandCritical;
36          PrimaryCommand = new(model.PrimaryCommand, PageContext);
37          PrimaryCommand.InitializeProperties();
38  
39          UpdateProperty(nameof(Title));
40          UpdateProperty(nameof(Description));
41          UpdateProperty(nameof(IsPrimaryCommandCritical));
42          UpdateProperty(nameof(PrimaryCommand));
43      }
44  }