precondition for commands

This commit is contained in:
Peng Lyu
2019-05-20 11:57:04 -07:00
parent 82127d5c22
commit e0666b4323
2 changed files with 18 additions and 0 deletions

View File

@@ -21,6 +21,7 @@ namespace schema {
export interface IUserFriendlyMenuItem {
command: string;
alt?: string;
precondition?: string;
when?: string;
group?: string;
}
@@ -78,6 +79,10 @@ namespace schema {
collector.error(localize('optstring', "property `{0}` can be omitted or must be of type `string`", 'alt'));
return false;
}
if (item.precondition && typeof item.precondition !== 'string') {
collector.error(localize('optstring', "property `{0}` can be omitted or must be of type `string`", 'precondition'));
return false;
}
if (item.when && typeof item.when !== 'string') {
collector.error(localize('optstring', "property `{0}` can be omitted or must be of type `string`", 'when'));
return false;
@@ -102,6 +107,10 @@ namespace schema {
description: localize('vscode.extension.contributes.menuItem.alt', 'Identifier of an alternative command to execute. The command must be declared in the \'commands\'-section'),
type: 'string'
},
precondition: {
description: localize('vscode.extension.contributes.menuItem.precondition', 'Condition which must be true to enable this item'),
type: 'string'
},
when: {
description: localize('vscode.extension.contributes.menuItem.when', 'Condition which must be true to show this item'),
type: 'string'
@@ -425,6 +434,14 @@ ExtensionsRegistry.registerExtensionPoint<{ [loc: string]: schema.IUserFriendlyM
}
}
if (item.precondition) {
command.precondition = ContextKeyExpr.deserialize(item.precondition);
}
if (item.alt && alt && item.precondition) {
alt.precondition = command.precondition;
}
const registration = MenuRegistry.appendMenuItem(menu, {
command,
alt,