command
Overview
- By defining commands and associating them with command handlers implemented in extensions, custom processing can be called from extension points on the ribbon.
- You can specify model selection status, model class, and target view definition as valid/invalid conditions for the command.
Command details
-
property
key description range required id ID that uniquely identifies the command. Unique string for all deployed extensions String representing ID Required title command title 1 any string - description Command description 1 Any string - group group to which the command belongs 1 string representing the group name - execFunc name of the command handler implemented in the entry point string representing the method name required canExecWhen Command valid condition. See lower property for details Object - canExecWhen.uiState One of the following values representing the state of the UI. Always
: Always enabled (default value when the property is omitted).ProjectOpened
: Enabled if the project is open.ModelSelected
: Enabled when a model is selected.ModelSelectedInEditor
: Enabled when a model is selected in the editor."Always", "ProjectOpened", "ModelSelected", "ModelSelectedInEditor" - canExecWhen.profiles Profile name of target project Character string representing profile name - canExecWhen.metamodels The class name of the selected model or its inherited class name. Specifying *
as the value or omitting the property is valid for all models. Ignored if uiState property is notModelSelected
,ModelSelectedInEditor
."*" or a string representing the class name. If multiple, specify them by separating them with commas. - canExecWhen.viewDefinitions Target view definition name. Specifying *
for the value or omitting the property is valid for all view definitions. Ignored if the uiState property is anything other thanModelSelectedInEditor
."*" or a string representing the view definition name. If multiple, specify them by separating them with commas. - canExecFunc The name of the method that evaluates the valid condition of the command. 2 If set at the same time as canExecWhen, this takes precedence. However, functions set only in .NET DLL-style extensions are evaluated. 3 string representing method name -
Command definition example
{
"extensionPoints": {
"commandGroups" :
[
{
"name": "codegen",
"title": "Generate Source Code"
}
],
"commands":
[
{
"id": "myExtension.generateCode",
"title": "Generate Code",
"description": "generate code description",
"group": "codegen",
"execFunc": "GenerateCode",
"canExecWhen" :
{
"uiState": "ModelSelected",
"metamodels": "FunctionalComponent,Component",
"viewDefinitions": "*"
}
},
{
"id": "myExtension.checkError",
"execFunc": "CheckError"
}
]
}
}
Implementation example of command handler
public void GenerateCode(ICommandContext commandContext, ICommandParams commandParams)
{
//Command handler implementation code
}
Example of using command parameters
When executing a command defined in a manifest extension point from inside an extension, you can specify parameters.
void ExecSomeCommands()
{
//generate parameters
var execParams = App.CreateCommandParams();
execParams.AddParam("value1"); //value can be referenced with execParams[0]
execParams.AddParam("value2"); //value can be referenced with execParams[1]
//execParams.AddParamWithName("param1", "value1"); //value can be referenced with execParams["param1"]
//execParams.AddParamWithName("param2", "value2"); //value can be referenced with execParams["param2"]
//execute command with parameters
App.ExecuteCommand("otherExtension.someCommand", execParams);
}
Footnotes
-
In the current version it does not affect the behavior of the extension and is not displayed.
↩ ↩2 ↩3 ↩4 -
The function signatures that can be set to canExecFunc are:
bool function-name(ICommandContext context, ICommandParams parameters)
. Evaluates to false if the configured function is not found.
↩ ↩2 -
Always evaluates to true if you set canExecFunc in a scripted extension. Only set canExecWhen in scripted extensions. ↩ ↩2