Skip to content

Commit

Permalink
plugins: view/title menus in all non-editor views
Browse files Browse the repository at this point in the history
In VS Code, contributions of menus to the
"view/title" contribution point are supposed to
be included in all views that are not editors,
so long as the "when" condition (if any)
is satisfied. So the contribution handler is
updated to register the menu delegate in
all non-editors.

Fixes #12705

Signed-off-by: Christian W. Damus <cdamus.ext@eclipsesource.com>
  • Loading branch information
cdamus committed Aug 8, 2023
1 parent 6607185 commit bf4bd5c
Showing 1 changed file with 17 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@ import { MenuModelRegistry } from '@theia/core/lib/common';
import { TabBarToolbarRegistry } from '@theia/core/lib/browser/shell/tab-bar-toolbar';
import { DeployedPlugin, IconUrl, Menu } from '../../../common';
import { ScmWidget } from '@theia/scm/lib/browser/scm-widget';
import { PluginViewWidget } from '../view/plugin-view-widget';
import { QuickCommandService } from '@theia/core/lib/browser';
import { ApplicationShell, QuickCommandService, Widget } from '@theia/core/lib/browser';
import {
CodeEditorWidgetUtil, codeToTheiaMappings, ContributionPoint,
PLUGIN_EDITOR_TITLE_MENU, PLUGIN_EDITOR_TITLE_RUN_MENU, PLUGIN_SCM_TITLE_MENU, PLUGIN_VIEW_TITLE_MENU
Expand All @@ -45,6 +44,7 @@ export class MenusContributionPointHandler {
@inject(MenuCommandAdapterRegistry) protected readonly commandAdapterRegistry: MenuCommandAdapterRegistry;
@inject(ContextKeyService) protected readonly contextKeyService: ContextKeyService;
@inject(PluginSharedStyle) protected readonly style: PluginSharedStyle;
@inject(ApplicationShell) protected readonly shell: ApplicationShell;
@inject(QuickCommandService) @optional()
private readonly quickCommandService: QuickCommandService;

Expand All @@ -58,7 +58,7 @@ export class MenusContributionPointHandler {
this.tabBarToolbar.registerMenuDelegate(PLUGIN_EDITOR_TITLE_MENU, widget => this.codeEditorWidgetUtil.is(widget));
this.tabBarToolbar.registerMenuDelegate(PLUGIN_EDITOR_TITLE_RUN_MENU, widget => this.codeEditorWidgetUtil.is(widget));
this.tabBarToolbar.registerMenuDelegate(PLUGIN_SCM_TITLE_MENU, widget => widget instanceof ScmWidget);
this.tabBarToolbar.registerMenuDelegate(PLUGIN_VIEW_TITLE_MENU, widget => widget instanceof PluginViewWidget);
this.tabBarToolbar.registerMenuDelegate(PLUGIN_VIEW_TITLE_MENU, widget => this.isViewEligibleForTitleMenuContribution(widget));
this.tabBarToolbar.registerItem({ id: 'plugin-menu-contribution-title-contribution', command: '_never_', onDidChange: this.onDidChangeTitleContributionEmitter.event });
this.contextKeyService.onDidChange(event => {
if (event.affects(this.titleContributionContextKeys)) {
Expand Down Expand Up @@ -160,4 +160,18 @@ export class MenusContributionPointHandler {
toDispose.push(reference);
return reference.object.iconClass;
}

/**
* Queries whether for the purposes of contribution of the `"view/title"` VS Code menu, a `widget`
* is a view (non-editor). In the default implementation, this is any widget that
*
* - is not some kind of editor via `CodeEditorWidgetUtil` _and_
* - is not in the `'main'` area of the workbench layout
*
* @param widget a widget to which the `"view/title"` menu is possibly to be contributed
* @returns whether the `widget` is a view that should manifest the `"view/title"` menu contribution
*/
protected isViewEligibleForTitleMenuContribution(widget: Widget): boolean {
return !this.codeEditorWidgetUtil.is(widget) && this.shell.getAreaFor(widget) !== 'main';
}
}

0 comments on commit bf4bd5c

Please sign in to comment.