Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/src/vs/workbench/contrib/chat/browser/chatContentParts/chatCommandContentPart.ts
3296 views
1
/*---------------------------------------------------------------------------------------------
2
* Copyright (c) Microsoft Corporation. All rights reserved.
3
* Licensed under the MIT License. See License.txt in the project root for license information.
4
*--------------------------------------------------------------------------------------------*/
5
6
import * as dom from '../../../../../base/browser/dom.js';
7
import { Button } from '../../../../../base/browser/ui/button/button.js';
8
import { Disposable } from '../../../../../base/common/lifecycle.js';
9
import { localize } from '../../../../../nls.js';
10
import { ICommandService } from '../../../../../platform/commands/common/commands.js';
11
import { defaultButtonStyles } from '../../../../../platform/theme/browser/defaultStyles.js';
12
import { IChatContentPart, IChatContentPartRenderContext } from './chatContentParts.js';
13
import { IChatProgressRenderableResponseContent } from '../../common/chatModel.js';
14
import { IChatCommandButton } from '../../common/chatService.js';
15
import { isResponseVM } from '../../common/chatViewModel.js';
16
17
const $ = dom.$;
18
19
export class ChatCommandButtonContentPart extends Disposable implements IChatContentPart {
20
public readonly domNode: HTMLElement;
21
22
constructor(
23
commandButton: IChatCommandButton,
24
context: IChatContentPartRenderContext,
25
@ICommandService private readonly commandService: ICommandService
26
) {
27
super();
28
29
this.domNode = $('.chat-command-button');
30
const enabled = !isResponseVM(context.element) || !context.element.isStale;
31
const tooltip = enabled ?
32
commandButton.command.tooltip :
33
localize('commandButtonDisabled', "Button not available in restored chat");
34
const button = this._register(new Button(this.domNode, { ...defaultButtonStyles, supportIcons: true, title: tooltip }));
35
button.label = commandButton.command.title;
36
button.enabled = enabled;
37
38
// TODO still need telemetry for command buttons
39
this._register(button.onDidClick(() => this.commandService.executeCommand(commandButton.command.id, ...(commandButton.command.arguments ?? []))));
40
}
41
42
hasSameContent(other: IChatProgressRenderableResponseContent): boolean {
43
// No other change allowed for this content type
44
return other.kind === 'command';
45
}
46
}
47
48