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 a few vscode menu contribution points #13226

Merged
merged 5 commits into from
Feb 27, 2024
Merged
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
4 changes: 3 additions & 1 deletion packages/core/src/browser/frontend-application-module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,9 @@ export const frontendApplicationModule = new ContainerModule((bind, _unbind, _is
const commandService = container.get<CommandService>(CommandService);
const corePreferences = container.get<CorePreferences>(CorePreferences);
const hoverService = container.get(HoverService);
return new TabBarRenderer(contextMenuRenderer, tabBarDecoratorService, iconThemeService, selectionService, commandService, corePreferences, hoverService);
const contextKeyService: ContextKeyService = container.get(ContextKeyService);
return new TabBarRenderer(contextMenuRenderer, tabBarDecoratorService, iconThemeService,
selectionService, commandService, corePreferences, hoverService, contextKeyService);
});
bind(TheiaDockPanel.Factory).toFactory(({ container }) => (options?: DockPanel.IOptions) => {
const corePreferences = container.get<CorePreferences>(CorePreferences);
Expand Down
6 changes: 5 additions & 1 deletion packages/core/src/browser/shell/tab-bars.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import { SelectComponent } from '../widgets/select-component';
import { createElement } from 'react';
import { PreviewableWidget } from '../widgets/previewable-widget';
import { EnhancedPreviewWidget } from '../widgets/enhanced-preview-widget';
import { ContextKeyService } from '../context-key-service';

/** The class name added to hidden content nodes, which are required to render vertical side bars. */
const HIDDEN_CONTENT_CLASS = 'theia-TabBar-hidden-content';
Expand Down Expand Up @@ -102,7 +103,8 @@ export class TabBarRenderer extends TabBar.Renderer {
protected readonly selectionService?: SelectionService,
protected readonly commandService?: CommandService,
protected readonly corePreferences?: CorePreferences,
protected readonly hoverService?: HoverService
protected readonly hoverService?: HoverService,
protected readonly contextKeyService?: ContextKeyService,
) {
super();
if (this.decoratorService) {
Expand Down Expand Up @@ -646,10 +648,12 @@ export class TabBarRenderer extends TabBar.Renderer {
this.selectionService.selection = NavigatableWidget.is(widget) ? { uri: widget.getResourceUri() } : widget;
}

const contextKeyServiceOverlay = this.contextKeyService?.createOverlay([['isTerminalTab', widget && 'terminalId' in widget]]);
this.contextMenuRenderer.render({
menuPath: this.contextMenuPath!,
anchor: event,
args: [event],
contextKeyService: contextKeyServiceOverlay,
// We'd like to wait until the command triggered by the context menu has been run, but this should let it get through the preamble, at least.
onHide: () => setTimeout(() => { if (this.selectionService) { this.selectionService.selection = oldSelection; } })
});
Expand Down
7 changes: 7 additions & 0 deletions packages/plugin-ext/src/main/browser/command-registry-main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ import { RPCProtocol } from '../../common/rpc-protocol';
import { KeybindingRegistry } from '@theia/core/lib/browser';
import { PluginContributionHandler } from './plugin-contribution-handler';
import { ArgumentProcessor } from '../../common/commands';
import { ContributionProvider } from '@theia/core';

export const ArgumentProcessorContribution = Symbol('ArgumentProcessorContribution');

export class CommandRegistryMainImpl implements CommandRegistryMain, Disposable {
private readonly proxy: CommandRegistryExt;
Expand All @@ -41,6 +44,10 @@ export class CommandRegistryMainImpl implements CommandRegistryMain, Disposable
this.delegate = container.get(CommandRegistry);
this.keyBinding = container.get(KeybindingRegistry);
this.contributions = container.get(PluginContributionHandler);

container.getNamed<ContributionProvider<ArgumentProcessor>>(ContributionProvider, ArgumentProcessorContribution).getContributions().forEach(processor => {
this.registerArgumentProcessor(processor);
});
}

dispose(): void {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,10 @@ export class PluginMenuCommandAdapter implements MenuCommandAdapter {
['timeline/item/context', (...args) => this.toTimelineArgs(...args)],
['view/item/context', (...args) => this.toTreeArgs(...args)],
['view/title', noArgs],
['webview/context', firstArgOnly]
['webview/context', firstArgOnly],
['extension/context', noArgs],
['terminal/context', noArgs],
['terminal/title/context', noArgs],
]).forEach(([contributionPoint, adapter]) => {
if (adapter) {
const paths = codeToTheiaMappings.get(contributionPoint);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import { WEBVIEW_CONTEXT_MENU, WebviewWidget } from '../webview/webview';
import { EDITOR_LINENUMBER_CONTEXT_MENU } from '@theia/editor/lib/browser/editor-linenumber-contribution';
import { TEST_VIEW_CONTEXT_MENU } from '@theia/test/lib/browser/view/test-view-contribution';
import { TEST_RUNS_CONTEXT_MENU } from '@theia/test/lib/browser/view/test-run-view-contribution';
import { TerminalMenus } from '@theia/terminal/lib/browser/terminal-frontend-contribution';

export const PLUGIN_EDITOR_TITLE_MENU = ['plugin_editor/title'];
export const PLUGIN_EDITOR_TITLE_RUN_MENU = ['plugin_editor/title/run'];
Expand Down Expand Up @@ -61,7 +62,10 @@ export const implementedVSCodeContributionPoints = [
'testing/message/context',
'view/item/context',
'view/title',
'webview/context'
'webview/context',
'extension/context',
'terminal/context',
'terminal/title/context'
] as const;

export type ContributionPoint = (typeof implementedVSCodeContributionPoints)[number];
Expand Down Expand Up @@ -89,7 +93,11 @@ export const codeToTheiaMappings = new Map<ContributionPoint, MenuPath[]>([
['timeline/item/context', [TIMELINE_ITEM_CONTEXT_MENU]],
['view/item/context', [VIEW_ITEM_CONTEXT_MENU]],
['view/title', [PLUGIN_VIEW_TITLE_MENU]],
['webview/context', [WEBVIEW_CONTEXT_MENU]]
['webview/context', [WEBVIEW_CONTEXT_MENU]],
['extension/context', [['extensions_context_menu', '3_contribution']]],
['terminal/context', [TerminalMenus.TERMINAL_CONTRIBUTIONS]],
['terminal/title/context', [TerminalMenus.TERMINAL_TITLE_CONTRIBUTIONS]]

]);

type CodeEditorWidget = EditorWidget | WebviewWidget;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ import { CellOutputWebviewFactory } from '@theia/notebook/lib/browser';
import { CellOutputWebviewImpl, createCellOutputWebviewContainer } from './notebooks/renderers/cell-output-webview';
import { NotebookCellModel } from '@theia/notebook/lib/browser/view-model/notebook-cell-model';
import { NotebookModel } from '@theia/notebook/lib/browser/view-model/notebook-model';
import { ArgumentProcessorContribution } from './command-registry-main';

export default new ContainerModule((bind, unbind, isBound, rebind) => {

Expand Down Expand Up @@ -266,4 +267,6 @@ export default new ContainerModule((bind, unbind, isBound, rebind) => {
bind(CellOutputWebviewFactory).toFactory(ctx => async (cell: NotebookCellModel, notebook: NotebookModel) =>
createCellOutputWebviewContainer(ctx.container, cell, notebook).getAsync(CellOutputWebviewImpl)
);

bindContributionProvider(bind, ArgumentProcessorContribution);
});
17 changes: 15 additions & 2 deletions packages/terminal/src/browser/terminal-frontend-contribution.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,13 @@ import {
Emitter,
Event,
ViewColumn,
OS
OS,
CompoundMenuNodeRole
} from '@theia/core/lib/common';
import {
ApplicationShell, KeybindingContribution, KeyCode, Key, WidgetManager, PreferenceService,
KeybindingRegistry, LabelProvider, WidgetOpenerOptions, StorageService, QuickInputService,
codicon, CommonCommands, FrontendApplicationContribution, OnWillStopAction, Dialog, ConfirmDialog, FrontendApplication, PreferenceScope, Widget
codicon, CommonCommands, FrontendApplicationContribution, OnWillStopAction, Dialog, ConfirmDialog, FrontendApplication, PreferenceScope, Widget, SHELL_TABBAR_CONTEXT_MENU
} from '@theia/core/lib/browser';
import { TabBarToolbarContribution, TabBarToolbarRegistry } from '@theia/core/lib/browser/shell/tab-bar-toolbar';
import { TERMINAL_WIDGET_FACTORY_ID, TerminalWidgetFactoryOptions, TerminalWidgetImpl } from './terminal-widget-impl';
Expand Down Expand Up @@ -68,6 +69,9 @@ export namespace TerminalMenus {
export const TERMINAL_OPEN_EDITORS_CONTEXT_MENU = ['open-editors-context-menu', 'navigation'];

export const TERMINAL_CONTEXT_MENU = ['terminal-context-menu'];
export const TERMINAL_CONTRIBUTIONS = [...TERMINAL_CONTEXT_MENU, '5_terminal_contributions'];

export const TERMINAL_TITLE_CONTRIBUTIONS = [...SHELL_TABBAR_CONTEXT_MENU, 'terminal_title_contributions'];
}

export namespace TerminalCommands {
Expand Down Expand Up @@ -732,6 +736,15 @@ export class TerminalFrontendContribution implements FrontendApplicationContribu
menus.registerMenuAction([...TerminalMenus.TERMINAL_CONTEXT_MENU, '_4'], {
commandId: TerminalCommands.KILL_TERMINAL.id
});

menus.registerSubmenu(TerminalMenus.TERMINAL_CONTRIBUTIONS, '', {
role: CompoundMenuNodeRole.Group
});

menus.registerSubmenu(TerminalMenus.TERMINAL_TITLE_CONTRIBUTIONS, '', {
role: CompoundMenuNodeRole.Group,
when: 'isTerminalTab'
});
}

registerToolbarItems(toolbar: TabBarToolbarRegistry): void {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// *****************************************************************************
// Copyright (C) 2024 TypeFox and others.
//
// This program and the accompanying materials are made available under the
// terms of the Eclipse Public License v. 2.0 which is available at
// http://www.eclipse.org/legal/epl-2.0.
//
// This Source Code may also be made available under the following Secondary
// Licenses when the conditions for such availability set forth in the Eclipse
// Public License v. 2.0 are satisfied: GNU General Public License, version 2
// with the GNU Classpath Exception which is available at
// https://www.gnu.org/software/classpath/license.html.
//
// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
// *****************************************************************************

import { injectable } from '@theia/core/shared/inversify';
import { ArgumentProcessor } from '@theia/plugin-ext/lib/common/commands';
import { VSXExtension } from './vsx-extension';

@injectable()
export class VsxExtensionArgumentProcessor implements ArgumentProcessor {

processArgument(arg: unknown): unknown {
if (arg instanceof VSXExtension) {
return arg.id;
}

return arg;
}

}
6 changes: 6 additions & 0 deletions packages/vsx-registry/src/browser/vsx-extension.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ export const EXTENSIONS_CONTEXT_MENU: MenuPath = ['extensions_context_menu'];
export namespace VSXExtensionsContextMenu {
export const INSTALL = [...EXTENSIONS_CONTEXT_MENU, '1_install'];
export const COPY = [...EXTENSIONS_CONTEXT_MENU, '2_copy'];
export const CONTRIBUTION = [...EXTENSIONS_CONTEXT_MENU, '3_contribution'];
}

@injectable()
Expand Down Expand Up @@ -495,6 +496,11 @@ export class VSXExtensionComponent<Props extends VSXExtensionComponent.Props = V
position: 'right'
});
}}
onMouseUp={event => {
if (event.button === 2) {
this.manage(event);
}
}}
>
{iconUrl ?
<img className='theia-vsx-extension-icon' src={iconUrl} /> :
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import { ColorRegistry } from '@theia/core/lib/browser/color-registry';
import { FrontendApplication } from '@theia/core/lib/browser/frontend-application';
import { FrontendApplicationContribution } from '@theia/core/lib/browser/frontend-application-contribution';
import { AbstractViewContribution } from '@theia/core/lib/browser/shell/view-contribution';
import { MenuModelRegistry, MessageService, SelectionService, nls } from '@theia/core/lib/common';
import { CompoundMenuNodeRole, MenuModelRegistry, MessageService, SelectionService, nls } from '@theia/core/lib/common';
import { Color } from '@theia/core/lib/common/color';
import { Command, CommandRegistry } from '@theia/core/lib/common/command';
import URI from '@theia/core/lib/common/uri';
Expand Down Expand Up @@ -159,6 +159,10 @@ export class VSXExtensionsContribution extends AbstractViewContribution<VSXExten
label: VSXExtensionsCommands.INSTALL_VSIX_FILE.label,
when: 'resourceScheme == file && resourceExtname == .vsix'
});

menus.registerSubmenu(VSXExtensionsContextMenu.CONTRIBUTION, '', {
jonah-iden marked this conversation as resolved.
Show resolved Hide resolved
role: CompoundMenuNodeRole.Group,
});
}

registerColors(colors: ColorRegistry): void {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ import { bindVsxExtensionsPreferences } from './vsx-extensions-preferences';
import { VSXEnvironment, VSX_ENVIRONMENT_PATH } from '../common/vsx-environment';
import { LanguageQuickPickService } from '@theia/core/lib/browser/i18n/language-quick-pick-service';
import { VSXLanguageQuickPickService } from './vsx-language-quick-pick-service';
import { VsxExtensionArgumentProcessor } from './vsx-extension-argument-processor';
import { ArgumentProcessorContribution } from '@theia/plugin-ext/lib/main/browser/command-registry-main';

export default new ContainerModule((bind, unbind, isBound, rebind) => {
bind(VSXEnvironment)
Expand Down Expand Up @@ -105,4 +107,7 @@ export default new ContainerModule((bind, unbind, isBound, rebind) => {
bindExtensionPreferences(bind);
bindPreferenceProviderOverrides(bind, unbind);
bindVsxExtensionsPreferences(bind);

bind(VsxExtensionArgumentProcessor).toSelf().inSingletonScope();
bind(ArgumentProcessorContribution).toService(VsxExtensionArgumentProcessor);
});
Loading