Path: blob/main/src/vs/workbench/contrib/comments/browser/commentThreadAdditionalActions.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';67import { IAction } from '../../../../base/common/actions.js';8import { IMenu, SubmenuItemAction } from '../../../../platform/actions/common/actions.js';9import { Disposable } from '../../../../base/common/lifecycle.js';10import { MarshalledId } from '../../../../base/common/marshallingIds.js';11import { IRange } from '../../../../editor/common/core/range.js';12import * as languages from '../../../../editor/common/languages.js';13import { IContextKeyService } from '../../../../platform/contextkey/common/contextkey.js';14import { CommentFormActions } from './commentFormActions.js';15import { CommentMenus } from './commentMenus.js';16import { ICellRange } from '../../notebook/common/notebookRange.js';17import { IKeybindingService } from '../../../../platform/keybinding/common/keybinding.js';18import { IContextMenuService } from '../../../../platform/contextview/browser/contextView.js';1920export class CommentThreadAdditionalActions<T extends IRange | ICellRange> extends Disposable {21private _container: HTMLElement | null;22private _buttonBar: HTMLElement | null;23private _commentFormActions!: CommentFormActions;2425constructor(26container: HTMLElement,27private _commentThread: languages.CommentThread<T>,28private _contextKeyService: IContextKeyService,29private _commentMenus: CommentMenus,30private _actionRunDelegate: (() => void) | null,31@IKeybindingService private _keybindingService: IKeybindingService,32@IContextMenuService private _contextMenuService: IContextMenuService,33) {34super();3536this._container = dom.append(container, dom.$('.comment-additional-actions'));37dom.append(this._container, dom.$('.section-separator'));3839this._buttonBar = dom.append(this._container, dom.$('.button-bar'));40this._createAdditionalActions(this._buttonBar);41}4243private _showMenu() {44this._container?.classList.remove('hidden');45}4647private _hideMenu() {48this._container?.classList.add('hidden');49}5051private _enableDisableMenu(menu: IMenu) {52const groups = menu.getActions({ shouldForwardArgs: true });5354// Show the menu if at least one action is enabled.55for (const group of groups) {56const [, actions] = group;57for (const action of actions) {58if (action.enabled) {59this._showMenu();60return;61}6263for (const subAction of (action as SubmenuItemAction).actions ?? []) {64if (subAction.enabled) {65this._showMenu();66return;67}68}69}70}7172this._hideMenu();73}747576private _createAdditionalActions(container: HTMLElement) {77const menu = this._commentMenus.getCommentThreadAdditionalActions(this._contextKeyService);78this._register(menu);79this._register(menu.onDidChange(() => {80this._commentFormActions.setActions(menu, /*hasOnlySecondaryActions*/ true);81this._enableDisableMenu(menu);82}));8384this._commentFormActions = new CommentFormActions(this._keybindingService, this._contextKeyService, this._contextMenuService, container, async (action: IAction) => {85this._actionRunDelegate?.();8687action.run({88thread: this._commentThread,89$mid: MarshalledId.CommentThreadInstance90});91}, 4, true);9293this._register(this._commentFormActions);94this._commentFormActions.setActions(menu, /*hasOnlySecondaryActions*/ true);95this._enableDisableMenu(menu);96}97}9899100