mirror of
https://github.com/microsoft/vscode.git
synced 2026-05-08 17:19:48 +01:00
reuse action and update resource since editor title area also reuses the actions, fixes #8317
This commit is contained in:
@@ -93,7 +93,7 @@ export class MenuService implements IMenuService {
|
||||
}
|
||||
}
|
||||
|
||||
type MenuItemGroup = [string, IMenuItem[]];
|
||||
type MenuItemGroup = [string, MenuItemAction[]];
|
||||
|
||||
class Menu implements IMenu {
|
||||
|
||||
@@ -121,7 +121,7 @@ class Menu implements IMenu {
|
||||
group = [groupName, []];
|
||||
this._menuGroups.push(group);
|
||||
}
|
||||
group[1].push(item);
|
||||
group[1].push(new MenuItemAction(item, this._keybindingService));
|
||||
|
||||
// keep keys for eventing
|
||||
Menu._fillInKbExprKeys(item.when, keysFilter);
|
||||
@@ -151,19 +151,18 @@ class Menu implements IMenu {
|
||||
}
|
||||
|
||||
getActions(): [string, IAction[]][] {
|
||||
const result: [string, IAction[]][] = [];
|
||||
const result: MenuItemGroup[] = [];
|
||||
for (let group of this._menuGroups) {
|
||||
const [id, items] = group;
|
||||
const actions: IAction[] = [];
|
||||
for (let item of items) {
|
||||
if (this._keybindingService.contextMatchesRules(item.when)) {
|
||||
actions.push(new MenuItemAction(item,
|
||||
this._keybindingService.getContextValue<URI>(ResourceContextKey.Resource),
|
||||
this._keybindingService));
|
||||
const [id, actions] = group;
|
||||
const activeActions: MenuItemAction[] = [];
|
||||
for (let action of actions) {
|
||||
if (this._keybindingService.contextMatchesRules(action.item.when)) {
|
||||
action.resource = this._keybindingService.getContextValue<URI>(ResourceContextKey.Resource);
|
||||
activeActions.push(action);
|
||||
}
|
||||
}
|
||||
if (actions.length > 0) {
|
||||
result.push([id, actions]);
|
||||
result.push([id, activeActions]);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
|
||||
@@ -61,9 +61,10 @@ export class MenuItemAction extends Actions.Action {
|
||||
return result;
|
||||
}
|
||||
|
||||
private _resource: URI;
|
||||
|
||||
constructor(
|
||||
private _item: IMenuItem,
|
||||
private _resource: URI,
|
||||
@IKeybindingService private _keybindingService: IKeybindingService
|
||||
) {
|
||||
super(MenuItemAction._getMenuItemId(_item), _item.command.title);
|
||||
@@ -71,6 +72,18 @@ export class MenuItemAction extends Actions.Action {
|
||||
this.order = 100000; //TODO@Ben order is menu item property, not an action property
|
||||
}
|
||||
|
||||
set resource(value: URI) {
|
||||
this._resource = value;
|
||||
}
|
||||
|
||||
get resource() {
|
||||
return this._resource;
|
||||
}
|
||||
|
||||
get item(): IMenuItem {
|
||||
return this._item;
|
||||
}
|
||||
|
||||
get command() {
|
||||
return this._item.command;
|
||||
}
|
||||
@@ -79,10 +92,6 @@ export class MenuItemAction extends Actions.Action {
|
||||
return this._item.alt;
|
||||
}
|
||||
|
||||
get selectedCommand() {
|
||||
return this.command;
|
||||
}
|
||||
|
||||
run(alt: boolean) {
|
||||
const {id} = alt === true && this._item.alt || this._item.command;
|
||||
return this._keybindingService.executeCommand(id, this._resource);
|
||||
|
||||
Reference in New Issue
Block a user