diff --git a/src/vs/editor/contrib/contextmenu/browser/contextmenu.ts b/src/vs/editor/contrib/contextmenu/browser/contextmenu.ts index 993075689432494ac5af393a0a7c59b5857114e7..e8cbb52e5bba16f0b37307331ccf9488ce652aa5 100644 --- a/src/vs/editor/contrib/contextmenu/browser/contextmenu.ts +++ b/src/vs/editor/contrib/contextmenu/browser/contextmenu.ts @@ -126,7 +126,7 @@ export class ContextMenuController implements IEditorContribution { const result: IAction[] = []; let contextMenu = this._menuService.createMenu(MenuId.EditorContext, this._contextKeyService); - const groups = contextMenu.getActions(this._editor.getModel().uri); + const groups = contextMenu.getActions(() => [this._editor.getModel().uri]); contextMenu.dispose(); for (let group of groups) { diff --git a/src/vs/platform/actions/browser/menuItemActionItem.ts b/src/vs/platform/actions/browser/menuItemActionItem.ts index a8433b4ecea2b05d04eb9c1c6d9d6c2c04f80621..4d97f2893e13652da3223de8e75f9ee9d73b1cbf 100644 --- a/src/vs/platform/actions/browser/menuItemActionItem.ts +++ b/src/vs/platform/actions/browser/menuItemActionItem.ts @@ -17,8 +17,8 @@ import { domEvent } from 'vs/base/browser/event'; import { Emitter } from 'vs/base/common/event'; -export function fillInActions(menu: IMenu, context: any, target: IAction[] | { primary: IAction[]; secondary: IAction[]; }, isPrimaryGroup: (group: string) => boolean = group => group === 'navigation'): void { - const groups = menu.getActions(context); +export function fillInActions(menu: IMenu, contextProvider: () => any[], target: IAction[] | { primary: IAction[]; secondary: IAction[]; }, isPrimaryGroup: (group: string) => boolean = group => group === 'navigation'): void { + const groups = menu.getActions(contextProvider); if (groups.length === 0) { return; } diff --git a/src/vs/platform/actions/common/actions.ts b/src/vs/platform/actions/common/actions.ts index 180007f4822b21a8dacb97ac9201271f03d70b18..38f4c1c531b0be5e43232370868126e97152a628 100644 --- a/src/vs/platform/actions/common/actions.ts +++ b/src/vs/platform/actions/common/actions.ts @@ -58,7 +58,7 @@ export class MenuId { export interface IMenu extends IDisposable { onDidChange: Event; - getActions(arg?: any): [string, MenuItemAction[]][]; + getActions(contextProvider?: () => any[]): [string, MenuItemAction[]][]; } export const IMenuService = createDecorator('menuService'); @@ -154,7 +154,7 @@ export class ExecuteCommandAction extends Action { export class MenuItemAction extends ExecuteCommandAction { - private _arg: any; + private _contextProvider: any; readonly item: ICommandAction; readonly alt: MenuItemAction; @@ -162,20 +162,20 @@ export class MenuItemAction extends ExecuteCommandAction { constructor( item: ICommandAction, alt: ICommandAction, - arg: any, + contextProvider: () => any[], @ICommandService commandService: ICommandService ) { super(item.id, item.title, commandService); this._cssClass = item.iconClass; this._enabled = true; - this._arg = arg; + this._contextProvider = contextProvider; this.item = item; - this.alt = alt ? new MenuItemAction(alt, undefined, arg, commandService) : undefined; + this.alt = alt ? new MenuItemAction(alt, undefined, contextProvider, commandService) : undefined; } run(): TPromise { - return super.run(this._arg); + return super.run(...this._contextProvider()); } } diff --git a/src/vs/platform/actions/common/menu.ts b/src/vs/platform/actions/common/menu.ts index e4b241d8bb8b536b09e09a268bd2e951dae42f52..667aa58fae8c1467d740dd22efa4b91e154a7471 100644 --- a/src/vs/platform/actions/common/menu.ts +++ b/src/vs/platform/actions/common/menu.ts @@ -69,14 +69,14 @@ export class Menu implements IMenu { return this._onDidChange.event; } - getActions(arg?: any): [string, MenuItemAction[]][] { + getActions(contextProvider: () => any[] = () => []): [string, MenuItemAction[]][] { const result: [string, MenuItemAction[]][] = []; for (let group of this._menuGroups) { const [id, items] = group; const activeActions: MenuItemAction[] = []; for (const item of items) { if (this._contextKeyService.contextMatchesRules(item.when)) { - const action = new MenuItemAction(item.command, item.alt, arg, this._commandService); + const action = new MenuItemAction(item.command, item.alt, contextProvider, this._commandService); action.order = item.order; //TODO@Ben order is menu item property, not an action property activeActions.push(action); } diff --git a/src/vs/workbench/browser/parts/editor/titleControl.ts b/src/vs/workbench/browser/parts/editor/titleControl.ts index 345d247dc08926a2eb5dcb1f74fc70f6b5da96ba..8aacbee19846deb9ccaff349e1c8e6bd4e962442 100644 --- a/src/vs/workbench/browser/parts/editor/titleControl.ts +++ b/src/vs/workbench/browser/parts/editor/titleControl.ts @@ -325,7 +325,7 @@ export abstract class TitleControl extends Themable implements ITitleAreaControl const titleBarMenu = this.menuService.createMenu(MenuId.EditorTitle, scopedContextKeyService); this.disposeOnEditorActions.push(titleBarMenu, titleBarMenu.onDidChange(_ => this.update())); - fillInActions(titleBarMenu, this.resourceContext.get(), { primary, secondary }); + fillInActions(titleBarMenu, () => [this.resourceContext.get()], { primary, secondary }); } return { primary, secondary }; @@ -475,7 +475,7 @@ export abstract class TitleControl extends Themable implements ITitleAreaControl } // Fill in contributed actions - fillInActions(this.contextMenu, this.resourceContext.get(), actions); + fillInActions(this.contextMenu, () => [this.resourceContext.get()], actions); return actions; } diff --git a/src/vs/workbench/parts/files/browser/views/explorerViewer.ts b/src/vs/workbench/parts/files/browser/views/explorerViewer.ts index af9ef658fcd3f819aefe06dbce27929f89d798e2..4cc050643e345f6a1f006a114a70dc074a203f1a 100644 --- a/src/vs/workbench/parts/files/browser/views/explorerViewer.ts +++ b/src/vs/workbench/parts/files/browser/views/explorerViewer.ts @@ -479,7 +479,7 @@ export class FileController extends DefaultController { getAnchor: () => anchor, getActions: () => { return this.state.actionProvider.getSecondaryActions(tree, stat).then(actions => { - fillInActions(this.contributedContextMenu, stat.resource, actions); + fillInActions(this.contributedContextMenu, () => [stat.resource], actions); return actions; }); }, diff --git a/src/vs/workbench/parts/scm/electron-browser/scmMenus.ts b/src/vs/workbench/parts/scm/electron-browser/scmMenus.ts index 6446431418cdd7a27852f2740e5c8bc3a328aed3..c54b394db4015ed123288666dbdda24dade81168 100644 --- a/src/vs/workbench/parts/scm/electron-browser/scmMenus.ts +++ b/src/vs/workbench/parts/scm/electron-browser/scmMenus.ts @@ -121,7 +121,7 @@ export class SCMMenus implements IDisposable { const primary = []; const secondary = []; const result = { primary, secondary }; - fillInActions(menu, context, result, g => g === 'inline'); + fillInActions(menu, () => [context], result, g => g === 'inline'); menu.dispose(); contextKeyService.dispose();