microsoft/TypeAgent

Public

mirrored fromhttps://github.com/microsoft/TypeAgentAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
78c691a1dc6954d7bec8ba6b3df51daf1480fffe

Branches

Tags

  • No tags available.
0Branches0Tags
Go to file
Add file
Code

Clone

HTTPS

Download ZIP

dotnet/visualStudioTypeAgent/ChatToolWindowCommand.cs

55lines · modecode

1// Copyright (c) Microsoft Corporation.
2// Licensed under the MIT License.
3
4using System;
5using System.ComponentModel.Design;
6using Microsoft.VisualStudio.Shell;
7using Microsoft.VisualStudio.Shell.Interop;
8using Microsoft.VisualStudio.Threading;
9using Task = System.Threading.Tasks.Task;
10
11namespace Microsoft.TypeAgent.VisualStudio;
12
13internal sealed class ChatToolWindowCommand
14{
15 public const int CommandId = 0x0100;
16 public static readonly Guid CommandSet = new Guid("c2a30f9d-8c64-4f3e-ad2a-af2f3b4e6f12");
17
18 private readonly AsyncPackage _package;
19
20 private ChatToolWindowCommand(AsyncPackage package, OleMenuCommandService commandService)
21 {
22 _package = package ?? throw new ArgumentNullException(nameof(package));
23 commandService = commandService ?? throw new ArgumentNullException(nameof(commandService));
24
25 var menuCommandID = new CommandID(CommandSet, CommandId);
26 var menuItem = new MenuCommand(Execute, menuCommandID);
27 commandService.AddCommand(menuItem);
28 }
29
30 public static async Task InitializeAsync(AsyncPackage package)
31 {
32 await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync(package.DisposalToken);
33 var commandService = (OleMenuCommandService?)await package.GetServiceAsync(typeof(IMenuCommandService));
34 if (commandService is null)
35 {
36 return;
37 }
38 _ = new ChatToolWindowCommand(package, commandService);
39 }
40
41 private void Execute(object sender, EventArgs e)
42 {
43 _package.JoinableTaskFactory.RunAsync(async () =>
44 {
45 // Marshal to the UI thread explicitly so the VSTHRD010 analyzer
46 // can see the IVsWindowFrame access is main-thread-safe.
47 await _package.JoinableTaskFactory.SwitchToMainThreadAsync(_package.DisposalToken);
48 var window = await _package.ShowToolWindowAsync(typeof(ChatToolWindow), 0, create: true, cancellationToken: _package.DisposalToken);
49 if (window?.Frame is IVsWindowFrame frame)
50 {
51 Microsoft.VisualStudio.ErrorHandler.ThrowOnFailure(frame.Show());
52 }
53 }).FileAndForget("typeagent/vsix/show-tool-window");
54 }
55}
56