Path: blob/main/extensions/copilot/test/simulation/fixtures/edit-refactor-loop/index.ts
13399 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 { reset } from 'vs/base/browser/dom';6import { BaseActionViewItem, IBaseActionViewItemOptions } from 'vs/base/browser/ui/actionbar/actionViewItems';7import { IHoverDelegate } from 'vs/base/browser/ui/iconLabel/iconHoverDelegate';8import { setupCustomHover } from 'vs/base/browser/ui/iconLabel/iconLabelHover';9import { IAction, SubmenuAction } from 'vs/base/common/actions';10import { Codicon } from 'vs/base/common/codicons';11import { Emitter, Event } from 'vs/base/common/event';12import { DisposableStore } from 'vs/base/common/lifecycle';13import { localize } from 'vs/nls';14import { createActionViewItem } from 'vs/platform/actions/browser/menuEntryActionViewItem';15import { HiddenItemStrategy, MenuWorkbenchToolBar, WorkbenchToolBar } from 'vs/platform/actions/browser/toolbar';16import { MenuId, MenuRegistry, SubmenuItemAction } from 'vs/platform/actions/common/actions';17import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';18import { IKeybindingService } from 'vs/platform/keybinding/common/keybinding';19import { IQuickInputService } from 'vs/platform/quickinput/common/quickInput';20import { WindowTitle } from 'vs/workbench/browser/parts/titlebar/windowTitle';2122export class CommandCenterControl {2324private readonly _disposables = new DisposableStore();2526private readonly _onDidChangeVisibility = new Emitter<void>();27readonly onDidChangeVisibility: Event<void> = this._onDidChangeVisibility.event;2829readonly element: HTMLElement = document.createElement('div');3031constructor(32windowTitle: WindowTitle,33hoverDelegate: IHoverDelegate,34@IInstantiationService instantiationService: IInstantiationService,35@IQuickInputService quickInputService: IQuickInputService,36@IKeybindingService keybindingService: IKeybindingService37) {38this.element.classList.add('command-center');3940const titleToolbar = instantiationService.createInstance(MenuWorkbenchToolBar, this.element, MenuId.CommandCenter, {41contextMenu: MenuId.TitleBarContext,42hiddenItemStrategy: HiddenItemStrategy.Ignore,43toolbarOptions: {44primaryGroup: () => true,45},46telemetrySource: 'commandCenter',47actionViewItemProvider: (action) => {48if (action instanceof SubmenuItemAction && action.item.submenu === MenuId.CommandCenterCenter) {49return instantiationService.createInstance(CommandCenterCenterViewItem, action, windowTitle, hoverDelegate, {});50} else {51return createActionViewItem(instantiationService, action, { hoverDelegate });52}53}54});5556this._disposables.add(quickInputService.onShow(this._setVisibility.bind(this, false)));57this._disposables.add(quickInputService.onHide(this._setVisibility.bind(this, true)));58this._disposables.add(titleToolbar);59}6061private _setVisibility(show: boolean): void {62this.element.classList.toggle('hide', !show);63this._onDidChangeVisibility.fire();64}6566dispose(): void {67this._disposables.dispose();68}69}707172class CommandCenterCenterViewItem extends BaseActionViewItem {7374private static readonly _quickOpenCommandId = 'workbench.action.quickOpenWithModes';7576constructor(77private readonly _submenu: SubmenuItemAction,78private readonly _windowTitle: WindowTitle,79private readonly _hoverDelegate: IHoverDelegate,80options: IBaseActionViewItemOptions,81@IKeybindingService private _keybindingService: IKeybindingService,82@IInstantiationService private _instaService: IInstantiationService,83) {84super(undefined, _submenu.actions[0], options);85}8687override render(container: HTMLElement): void {88super.render(container);89container.classList.add('command-center');90if (this._submenu.actions.length === 1 && this._submenu.actions[0].id === CommandCenterCenterViewItem._quickOpenCommandId) {91this._renderSingleItem(container);92} else {93this._renderMultipleItems(container);94container.classList.add('multiple');95}96}9798private _renderMultipleItems(container: HTMLElement) {99100const groups: (readonly IAction[])[] = [];101for (const action of this._submenu.actions) {102if (action instanceof SubmenuAction) {103groups.push(action.actions);104} else {105groups.push([action]);106}107}108109for (const group of groups) {110111// nested toolbar112const toolbar = this._instaService.createInstance(WorkbenchToolBar, container, {113hiddenItemStrategy: HiddenItemStrategy.NoHide,114telemetrySource: 'commandCenterCenter',115actionViewItemProvider: (action, options) => {116return createActionViewItem(this._instaService, action, {117...options,118hoverDelegate: this._hoverDelegate,119});120}121});122toolbar.setActions(group);123this._store.add(toolbar);124125}126}127128private _renderSingleItem(container: HTMLElement) {129130const action = this._submenu.actions[0];131132// icon (search)133const searchIcon = document.createElement('span');134searchIcon.className = action.class ?? '';135searchIcon.classList.add('search-icon');136137// label: just workspace name and optional decorations138const label = this._getLabel();139const labelElement = document.createElement('span');140labelElement.classList.add('search-label');141labelElement.innerText = label;142reset(container, searchIcon, labelElement);143144const hover = this._store.add(setupCustomHover(this._hoverDelegate, container, this.getTooltip()));145146// update label & tooltip when window title changes147this._store.add(this._windowTitle.onDidChange(() => {148hover.update(this.getTooltip());149labelElement.innerText = this._getLabel();150}));151}152153private _getLabel(): string {154const { prefix, suffix } = this._windowTitle.getTitleDecorations();155let label = this._windowTitle.isCustomTitleFormat() ? this._windowTitle.getWindowTitle() : this._windowTitle.workspaceName;156if (!label) {157label = localize('label.dfl', "Search");158}159if (prefix) {160label = localize('label1', "{0} {1}", prefix, label);161}162if (suffix) {163label = localize('label2', "{0} {1}", label, suffix);164}165return label;166}167168protected override getTooltip() {169170// tooltip: full windowTitle171const kb = this._keybindingService.lookupKeybinding(this.action.id)?.getLabel();172const title = kb173? localize('title', "Search {0} ({1}) \u2014 {2}", this._windowTitle.workspaceName, kb, this._windowTitle.value)174: localize('title2', "Search {0} \u2014 {1}", this._windowTitle.workspaceName, this._windowTitle.value);175176return title;177}178}179180181MenuRegistry.appendMenuItem(MenuId.CommandCenter, {182submenu: MenuId.CommandCenterCenter,183title: localize('title3', "Command Center"),184icon: Codicon.shield,185order: 101,186});187188189