Skip to content

Commit 5ab136f

Browse files
authored
Merge pull request microsoft#74017 from microsoft/rebornix/extcmd-precondition
Precondition for command and alt command
2 parents 4ca38ce + d681615 commit 5ab136f

1 file changed

Lines changed: 17 additions & 0 deletions

File tree

src/vs/workbench/api/common/menusExtensionPoint.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ namespace schema {
2121
export interface IUserFriendlyMenuItem {
2222
command: string;
2323
alt?: string;
24+
precondition?: string;
2425
when?: string;
2526
group?: string;
2627
}
@@ -74,6 +75,10 @@ namespace schema {
7475
collector.error(localize('optstring', "property `{0}` can be omitted or must be of type `string`", 'alt'));
7576
return false;
7677
}
78+
if (item.precondition && typeof item.precondition !== 'string') {
79+
collector.error(localize('optstring', "property `{0}` can be omitted or must be of type `string`", 'precondition'));
80+
return false;
81+
}
7782
if (item.when && typeof item.when !== 'string') {
7883
collector.error(localize('optstring', "property `{0}` can be omitted or must be of type `string`", 'when'));
7984
return false;
@@ -98,6 +103,10 @@ namespace schema {
98103
description: localize('vscode.extension.contributes.menuItem.alt', 'Identifier of an alternative command to execute. The command must be declared in the \'commands\'-section'),
99104
type: 'string'
100105
},
106+
precondition: {
107+
description: localize('vscode.extension.contributes.menuItem.precondition', 'Condition which must be true to enable this item'),
108+
type: 'string'
109+
},
101110
when: {
102111
description: localize('vscode.extension.contributes.menuItem.when', 'Condition which must be true to show this item'),
103112
type: 'string'
@@ -401,6 +410,14 @@ ExtensionsRegistry.registerExtensionPoint<{ [loc: string]: schema.IUserFriendlyM
401410
}
402411
}
403412

413+
if (item.precondition) {
414+
command.precondition = ContextKeyExpr.deserialize(item.precondition);
415+
}
416+
417+
if (alt && item.precondition) {
418+
alt.precondition = command.precondition;
419+
}
420+
404421
const registration = MenuRegistry.appendMenuItem(menu, {
405422
command,
406423
alt,

0 commit comments

Comments
 (0)