Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add terminal/command contributable menu #233115

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/vs/platform/actions/common/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,7 @@ export class MenuId {
static readonly TerminalTabContext = new MenuId('TerminalTabContext');
static readonly TerminalTabEmptyAreaContext = new MenuId('TerminalTabEmptyAreaContext');
static readonly TerminalStickyScrollContext = new MenuId('TerminalStickyScrollContext');
static readonly TerminalCommand = new MenuId('TerminalCommand');
static readonly WebviewContext = new MenuId('WebviewContext');
static readonly InlineCompletionsActions = new MenuId('InlineCompletionsActions');
static readonly InlineEditsActions = new MenuId('InlineEditsActions');
Expand Down
13 changes: 11 additions & 2 deletions src/vs/workbench/contrib/terminal/browser/xterm/decorationAddon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ import { TERMINAL_COMMAND_DECORATION_DEFAULT_BACKGROUND_COLOR, TERMINAL_COMMAND_
import { ILifecycleService } from '../../../../services/lifecycle/common/lifecycle.js';
import { IHoverService } from '../../../../../platform/hover/browser/hover.js';
import { MarkdownString } from '../../../../../base/common/htmlContent.js';
import { IMenuService, MenuId, type IMenu } from '../../../../../platform/actions/common/actions.js';
import { getFlatContextMenuActions } from '../../../../../platform/actions/browser/menuEntryActionViewItem.js';
import { IContextKeyService } from '../../../../../platform/contextkey/common/contextkey.js';

interface IDisposableDecoration { decoration: IDecoration; disposables: IDisposable[]; exitCode?: number; markProperties?: IMarkProperties }

Expand All @@ -37,6 +40,8 @@ export class DecorationAddon extends Disposable implements ITerminalAddon, IDeco
private _placeholderDecoration: IDecoration | undefined;
private _showGutterDecorations?: boolean;
private _showOverviewRulerDecorations?: boolean;
private readonly _menu: IMenu;

private readonly _registeredMenuItems: Map<ITerminalCommand, IAction[]> = new Map();

private readonly _onDidRequestRunCommand = this._register(new Emitter<{ command: ITerminalCommand; noNewLine?: boolean }>());
Expand All @@ -56,9 +61,12 @@ export class DecorationAddon extends Disposable implements ITerminalAddon, IDeco
@ICommandService private readonly _commandService: ICommandService,
@IAccessibilitySignalService private readonly _accessibilitySignalService: IAccessibilitySignalService,
@INotificationService private readonly _notificationService: INotificationService,
@IHoverService private readonly _hoverService: IHoverService
@IHoverService private readonly _hoverService: IHoverService,
@IMenuService private readonly _menuService: IMenuService,
@IContextKeyService private readonly _contextKeyService: IContextKeyService
) {
super();
this._menu = this._register(this._menuService.createMenu(MenuId.TerminalCommand, this._contextKeyService));
this._register(toDisposable(() => this._dispose()));
this._register(this._configurationService.onDidChangeConfiguration(e => {
if (e.affectsConfiguration(TerminalSettingId.FontSize) || e.affectsConfiguration(TerminalSettingId.LineHeight)) {
Expand Down Expand Up @@ -384,7 +392,8 @@ export class DecorationAddon extends Disposable implements ITerminalAddon, IDeco
}),
dom.addDisposableListener(element, dom.EventType.CLICK, async (e) => {
e.stopImmediatePropagation();
const actions = await this._getCommandActions(command);
const actions = getFlatContextMenuActions(this._menu.getActions({ shouldForwardArgs: true }));
actions.push(...await this._getCommandActions(command));
this._contextMenuService.showContextMenu({ getAnchor: () => element, getActions: () => actions });
}),
dom.addDisposableListener(element, dom.EventType.CONTEXT_MENU, async (e) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,11 @@ const apiMenus: IAPIMenu[] = [
id: MenuId.TerminalTabContext,
description: localize('menus.terminalTabContext', "The terminal tabs context menu")
},
{
key: 'terminal/command',
id: MenuId.TerminalCommand,
description: localize('menus.terminalCommand', "The terminal command menu that shows when shell integration is enabled")
},
{
key: 'view/title',
id: MenuId.ViewTitle,
Expand Down
Loading