Path: blob/main/src/vs/workbench/contrib/chat/browser/chatContentParts/chatCommandContentPart.ts
3296 views
/*---------------------------------------------------------------------------------------------1* Copyright (c) Microsoft Corporation. All rights reserved.2* Licensed under the MIT License. See License.txt in the project root for license information.3*--------------------------------------------------------------------------------------------*/45import * as dom from '../../../../../base/browser/dom.js';6import { Button } from '../../../../../base/browser/ui/button/button.js';7import { Disposable } from '../../../../../base/common/lifecycle.js';8import { localize } from '../../../../../nls.js';9import { ICommandService } from '../../../../../platform/commands/common/commands.js';10import { defaultButtonStyles } from '../../../../../platform/theme/browser/defaultStyles.js';11import { IChatContentPart, IChatContentPartRenderContext } from './chatContentParts.js';12import { IChatProgressRenderableResponseContent } from '../../common/chatModel.js';13import { IChatCommandButton } from '../../common/chatService.js';14import { isResponseVM } from '../../common/chatViewModel.js';1516const $ = dom.$;1718export class ChatCommandButtonContentPart extends Disposable implements IChatContentPart {19public readonly domNode: HTMLElement;2021constructor(22commandButton: IChatCommandButton,23context: IChatContentPartRenderContext,24@ICommandService private readonly commandService: ICommandService25) {26super();2728this.domNode = $('.chat-command-button');29const enabled = !isResponseVM(context.element) || !context.element.isStale;30const tooltip = enabled ?31commandButton.command.tooltip :32localize('commandButtonDisabled', "Button not available in restored chat");33const button = this._register(new Button(this.domNode, { ...defaultButtonStyles, supportIcons: true, title: tooltip }));34button.label = commandButton.command.title;35button.enabled = enabled;3637// TODO still need telemetry for command buttons38this._register(button.onDidClick(() => this.commandService.executeCommand(commandButton.command.id, ...(commandButton.command.arguments ?? []))));39}4041hasSameContent(other: IChatProgressRenderableResponseContent): boolean {42// No other change allowed for this content type43return other.kind === 'command';44}45}464748