ExecuteCommandConfirmation.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 System; 6 using Microsoft.CommandPalette.Extensions.Toolkit; 7 8 namespace Microsoft.CmdPal.Ext.System; 9 10 public sealed partial class ExecuteCommandConfirmation : InvokableCommand 11 { 12 public ExecuteCommandConfirmation(string name, bool confirm, string confirmationMessage, Action command) 13 { 14 Name = name; 15 _command = command; 16 _confirm = confirm; 17 _confirmationMessage = confirmationMessage; 18 } 19 20 public override CommandResult Invoke() 21 { 22 if (_confirm) 23 { 24 var confirmationArgs = new ConfirmationArgs 25 { 26 Title = Resources.Microsoft_plugin_sys_confirmation, 27 Description = _confirmationMessage, 28 PrimaryCommand = new ExecuteCommand(_command), 29 IsPrimaryCommandCritical = true, 30 }; 31 32 return CommandResult.Confirm(confirmationArgs); 33 } 34 35 _command(); 36 return CommandResult.Dismiss(); 37 } 38 39 private bool _confirm; 40 private string _confirmationMessage; 41 private Action _command; 42 }