Skip to content

Commit

Permalink
pass context key service down to MenuEntryActionViewItem so that keyb…
Browse files Browse the repository at this point in the history
…inding label picks up the best match
  • Loading branch information
jrieken committed Jul 1, 2021
1 parent 2ae3209 commit ac1c2ea
Show file tree
Hide file tree
Showing 9 changed files with 30 additions and 40 deletions.
13 changes: 1 addition & 12 deletions src/vs/editor/contrib/suggest/suggestWidgetStatus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,9 @@ import { MenuEntryActionViewItem } from 'vs/platform/actions/browser/menuEntryAc
import { IMenuService, MenuItemAction } from 'vs/platform/actions/common/actions';
import { IContextKeyService } from 'vs/platform/contextkey/common/contextkey';
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
import { IKeybindingService } from 'vs/platform/keybinding/common/keybinding';
import { INotificationService } from 'vs/platform/notification/common/notification';

class StatusBarViewItem extends MenuEntryActionViewItem {

constructor(
action: MenuItemAction,
@IKeybindingService keybindingService: IKeybindingService,
@INotificationService notificationService: INotificationService,
@IContextKeyService private _contextKeyService: IContextKeyService,
) {
super(action, undefined, keybindingService, notificationService);
}

override updateLabel() {
const kb = this._keybindingService.lookupKeybinding(this._action.id, this._contextKeyService);
if (!kb) {
Expand Down Expand Up @@ -60,7 +49,7 @@ export class SuggestWidgetStatus {
this.element = dom.append(container, dom.$('.suggest-status-bar'));

const actionViewItemProvider = <IActionViewItemProvider>(action => {
return action instanceof MenuItemAction ? instantiationService.createInstance(StatusBarViewItem, action) : undefined;
return action instanceof MenuItemAction ? instantiationService.createInstance(StatusBarViewItem, action, undefined) : undefined;
});
this._leftActions = new ActionBar(this.element, { actionViewItemProvider });
this._rightActions = new ActionBar(this.element, { actionViewItemProvider });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { MenuItemAction } from 'vs/platform/actions/common/actions';
import { MenuEntryActionViewItem } from 'vs/platform/actions/browser/menuEntryActionViewItem';
import { IKeybindingService } from 'vs/platform/keybinding/common/keybinding';
import { INotificationService } from 'vs/platform/notification/common/notification';
import { IContextKeyService } from 'vs/platform/contextkey/common/contextkey';

export class DropdownWithPrimaryActionViewItem extends BaseActionViewItem {
private _primaryAction: ActionViewItem;
Expand All @@ -33,10 +34,11 @@ export class DropdownWithPrimaryActionViewItem extends BaseActionViewItem {
className: string,
private readonly _contextMenuProvider: IContextMenuProvider,
@IKeybindingService _keybindingService: IKeybindingService,
@INotificationService _notificationService: INotificationService
@INotificationService _notificationService: INotificationService,
@IContextKeyService _contextKeyService: IContextKeyService
) {
super(null, primaryAction);
this._primaryAction = new MenuEntryActionViewItem(primaryAction, undefined, _keybindingService, _notificationService);
this._primaryAction = new MenuEntryActionViewItem(primaryAction, undefined, _keybindingService, _notificationService, _contextKeyService);
this._dropdown = new DropdownMenuActionViewItem(dropdownAction, dropdownMenuActions, this._contextMenuProvider, {
menuAsChild: true,
classNames: ['codicon', 'codicon-chevron-down']
Expand Down
8 changes: 5 additions & 3 deletions src/vs/platform/actions/browser/menuEntryActionViewItem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import { ActionViewItem } from 'vs/base/browser/ui/actionbar/actionViewItems';
import { DropdownMenuActionViewItem } from 'vs/base/browser/ui/dropdown/dropdownActionViewItem';
import { isWindows, isLinux, OS } from 'vs/base/common/platform';
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
import { IContextKeyService } from 'vs/platform/contextkey/common/contextkey';

export function createAndFillInContextMenuActions(menu: IMenu, options: IMenuActionOptions | undefined, target: IAction[] | { primary: IAction[]; secondary: IAction[]; }, primaryGroup?: string): IDisposable {
const groups = menu.getActions(options);
Expand Down Expand Up @@ -129,7 +130,8 @@ export class MenuEntryActionViewItem extends ActionViewItem {
_action: MenuItemAction,
options: IMenuEntryActionViewItemOptions | undefined,
@IKeybindingService protected readonly _keybindingService: IKeybindingService,
@INotificationService protected _notificationService: INotificationService
@INotificationService protected _notificationService: INotificationService,
@IContextKeyService protected _contextKeyService: IContextKeyService
) {
super(undefined, _action, { icon: !!(_action.class || _action.item.icon), label: !_action.class && !_action.item.icon, draggable: options?.draggable });
this._altKey = ModifierKeyEmitter.getInstance();
Expand Down Expand Up @@ -200,7 +202,7 @@ export class MenuEntryActionViewItem extends ActionViewItem {

override updateTooltip(): void {
if (this.label) {
const keybinding = this._keybindingService.lookupKeybinding(this._commandAction.id);
const keybinding = this._keybindingService.lookupKeybinding(this._commandAction.id, this._contextKeyService);
const keybindingLabel = keybinding && keybinding.getLabel();

const tooltip = this._commandAction.tooltip || this._commandAction.label;
Expand All @@ -209,7 +211,7 @@ export class MenuEntryActionViewItem extends ActionViewItem {
: tooltip;
if (!this._wantsAltCommand && this._menuItemAction.alt) {
const altTooltip = this._menuItemAction.alt.tooltip || this._menuItemAction.alt.label;
const altKeybinding = this._keybindingService.lookupKeybinding(this._menuItemAction.alt.id);
const altKeybinding = this._keybindingService.lookupKeybinding(this._menuItemAction.alt.id, this._contextKeyService);
const altKeybindingLabel = altKeybinding && altKeybinding.getLabel();
const altTitleSection = altKeybindingLabel
? localize('titleAndKb', "{0} ({1})", altTooltip, altKeybindingLabel)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ class PropertyHeader extends Disposable {
this._toolbar = new ToolBar(cellToolbarContainer, this.contextMenuService, {
actionViewItemProvider: action => {
if (action instanceof MenuItemAction) {
const item = new CodiconActionViewItem(action, this.keybindingService, this.notificationService);
const item = new CodiconActionViewItem(action, this.keybindingService, this.notificationService, this.contextKeyService);
return item;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ export class CellDiffSideBySideRenderer implements IListRenderer<SideBySideDiffE
const toolbar = new ToolBar(cellToolbarContainer, this.contextMenuService, {
actionViewItemProvider: action => {
if (action instanceof MenuItemAction) {
const item = new CodiconActionViewItem(action, this.keybindingService, this.notificationService);
const item = new CodiconActionViewItem(action, this.keybindingService, this.notificationService, this.contextKeyService);
return item;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import { IContextKeyService } from 'vs/platform/contextkey/common/contextkey';
import { IContextMenuService } from 'vs/platform/contextview/browser/contextView';
import { IInstantiationService, optional } from 'vs/platform/instantiation/common/instantiation';
import { IKeybindingService } from 'vs/platform/keybinding/common/keybinding';
import { INotificationService } from 'vs/platform/notification/common/notification';
import { toolbarActiveBackground } from 'vs/platform/theme/common/colorRegistry';
import { registerThemingParticipant } from 'vs/platform/theme/common/themeService';
import { SELECT_KERNEL_ID } from 'vs/workbench/contrib/notebook/browser/contrib/coreActions';
Expand Down Expand Up @@ -56,7 +55,6 @@ export class NotebookEditorToolbar extends Disposable {
@IMenuService readonly menuService: IMenuService,
@IEditorService private readonly editorService: IEditorService,
@IKeybindingService private readonly keybindingService: IKeybindingService,
@INotificationService private readonly notificationService: INotificationService,
@optional(ITASExperimentService) private readonly experimentService: ITASExperimentService
) {
super();
Expand Down Expand Up @@ -118,7 +116,7 @@ export class NotebookEditorToolbar extends Disposable {
return this.instantiationService.createInstance(NotebooKernelActionViewItem, action, this.notebookEditor);
}

return action instanceof MenuItemAction ? new ActionViewWithLabel(action, this.keybindingService, this.notificationService) : undefined;
return action instanceof MenuItemAction ? this.instantiationService.createInstance(ActionViewWithLabel, action) : undefined;
};

this._notebookLeftToolbar = new ToolBar(this._notebookTopLeftToolbarContainer, this.contextMenuService, {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,16 @@ import { MenuEntryActionViewItem } from 'vs/platform/actions/browser/menuEntryAc
import { MenuItemAction } from 'vs/platform/actions/common/actions';
import { IKeybindingService } from 'vs/platform/keybinding/common/keybinding';
import { INotificationService } from 'vs/platform/notification/common/notification';
import { IContextKeyService } from 'vs/platform/contextkey/common/contextkey';

export class CodiconActionViewItem extends MenuEntryActionViewItem {
constructor(
_action: MenuItemAction,
keybindingService: IKeybindingService,
notificationService: INotificationService,
@IKeybindingService keybindingService: IKeybindingService,
@INotificationService notificationService: INotificationService,
@IContextKeyService contextKeyService: IContextKeyService,
) {
super(_action, undefined, keybindingService, notificationService);
super(_action, undefined, keybindingService, notificationService, contextKeyService);
}
override updateLabel(): void {
if (this.options.label && this.label) {
Expand All @@ -30,10 +32,11 @@ export class ActionViewWithLabel extends MenuEntryActionViewItem {

constructor(
_action: MenuItemAction,
keybindingService: IKeybindingService,
notificationService: INotificationService,
@IKeybindingService keybindingService: IKeybindingService,
@INotificationService notificationService: INotificationService,
@IContextKeyService contextKeyService: IContextKeyService,
) {
super(_action, undefined, keybindingService, notificationService);
super(_action, undefined, keybindingService, notificationService, contextKeyService);
}

override render(container: HTMLElement): void {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,9 +114,9 @@ abstract class AbstractCellRenderer {
actionViewItemProvider: action => {
if (action instanceof MenuItemAction) {
if (notebookOptions.getLayoutConfiguration().insertToolbarAlignment === 'center') {
return new CodiconActionViewItem(action, this.keybindingService, this.notificationService);
return this.instantiationService.createInstance(CodiconActionViewItem, action);
} else {
return new MenuEntryActionViewItem(action, undefined, this.keybindingService, this.notificationService);
return this.instantiationService.createInstance(MenuEntryActionViewItem, action, undefined);
}
}

Expand Down Expand Up @@ -862,14 +862,12 @@ export class CodeCellRenderer extends AbstractCellRenderer implements IListRende
return undefined;
}

const item = new DropdownWithPrimaryActionViewItem(
const item = this.instantiationService.createInstance(DropdownWithPrimaryActionViewItem,
primary,
dropdownAction,
actions.secondary,
'notebook-cell-run-toolbar',
this.contextMenuService,
this.keybindingService,
this.notificationService);
this.contextMenuService);
actionViewItemDisposables.add(item.onDidChangeDropdownVisibility(visible => {
cellContainer.classList.toggle('cell-run-toolbar-dropdown-active', visible);
}));
Expand Down Expand Up @@ -1212,9 +1210,7 @@ export class ListTopCellToolbar extends Disposable {
insertionIndicatorContainer: HTMLElement,
@IInstantiationService protected readonly instantiationService: IInstantiationService,
@IContextMenuService protected readonly contextMenuService: IContextMenuService,
@IMenuService protected readonly menuService: IMenuService,
@IKeybindingService private readonly keybindingService: IKeybindingService,
@INotificationService private readonly notificationService: INotificationService,
@IMenuService protected readonly menuService: IMenuService
) {
super();

Expand All @@ -1223,7 +1219,7 @@ export class ListTopCellToolbar extends Disposable {
this.toolbar = this._register(new ToolBar(this.topCellToolbar, this.contextMenuService, {
actionViewItemProvider: action => {
if (action instanceof MenuItemAction) {
const item = new CodiconActionViewItem(action, this.keybindingService, this.notificationService);
const item = this.instantiationService.createInstance(CodiconActionViewItem, action);
return item;
}

Expand Down
4 changes: 2 additions & 2 deletions src/vs/workbench/contrib/terminal/browser/terminalView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ export class TerminalViewPane extends ViewPane {
}
const actions = this._getTabActionBarArgs(this._terminalService.availableProfiles);

this._tabButtons = new DropdownWithPrimaryActionViewItem(actions.primaryAction, actions.dropdownAction, actions.dropdownMenuActions, actions.className, this._contextMenuService, this._keybindingService, this._notificationService);
this._tabButtons = new DropdownWithPrimaryActionViewItem(actions.primaryAction, actions.dropdownAction, actions.dropdownMenuActions, actions.className, this._contextMenuService, this._keybindingService, this._notificationService, this._contextKeyService);
this._updateTabActionBar(this._terminalService.availableProfiles);
return this._tabButtons;
}
Expand Down Expand Up @@ -430,7 +430,7 @@ class SingleTerminalTabActionViewItem extends MenuEntryActionViewItem {
_commandService
), {
draggable: true
}, keybindingService, notificationService);
}, keybindingService, notificationService, contextKeyService);

// Register listeners to update the tab
this._register(this._terminalService.onInstancePrimaryStatusChanged(e => this.updateLabel(e)));
Expand Down

0 comments on commit ac1c2ea

Please sign in to comment.