forked from microsoft/VSExtensibility
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSampleCommand.cs
69 lines (59 loc) · 2.23 KB
/
SampleCommand.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
namespace UserPromptSample;
using System.Diagnostics;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.VisualStudio.Extensibility;
using Microsoft.VisualStudio.Extensibility.Commands;
using Microsoft.VisualStudio.Extensibility.Shell;
[VisualStudioContribution]
public class SampleCommand : Command
{
public enum TokenThemeResult
{
None,
Solarized,
OneDark,
GruvBox,
}
/// <inheritdoc />
public override CommandConfiguration CommandConfiguration => new("%UserPromptSample.SampleCommand.DisplayName%")
{
TooltipText = "%UserPromptSample.SampleCommand.ToolTip%",
Placements = new[] { CommandPlacement.KnownPlacements.ToolsMenu },
};
/// <inheritdoc />
public override async Task ExecuteCommandAsync(IClientContext context, CancellationToken ct)
{
var shell = this.Extensibility.Shell();
// Asking the user to confirm an operation.
if (!await shell.ShowPromptAsync("Continue with executing the command?", PromptOptions.OKCancel, ct))
{
return;
}
// Asking the user to confirm a dangerous operation.
if (!await shell.ShowPromptAsync("Continue with executing the command?", PromptOptions.OKCancel.WithCancelAsDefault(), ct))
{
return;
}
// OK-only prompt
await shell.ShowPromptAsync("The extension must reload.", PromptOptions.OK, ct);
// Custom prompt
var themeResult = await shell.ShowPromptAsync(
"Which theme should be used for the generated output?",
new PromptOptions<TokenThemeResult>
{
Choices =
{
{ "Solarized Is Awesome", TokenThemeResult.Solarized },
{ "OneDark Is The Best", TokenThemeResult.OneDark },
{ "GruvBox Is Groovy", TokenThemeResult.GruvBox },
},
DismissedReturns = TokenThemeResult.None,
DefaultChoiceIndex = 2,
},
ct);
Debug.WriteLine($"Selected Token Theme: {themeResult}");
}
}