Command
Overview
- By defining a command and associating it with the command handler implemented in the extension, you can call your own processing from the extension point of the ribbon.
- You can specify the model selection state, model class, and target view definition as command enable/disable conditions.
Command details
Properties
Key Description Range Required? id An ID that uniquely identifies the command. Unique string for all deployed extensions ID string Required title Command title 1 Arbitrary string - description Command description 1 Arbitrary string - group The group to which the command belongs 1 A string representing the group name - execFunc Command handler name implemented at the entry point String representing function/method name Required canExecWhen Command valid condition. Details are as shown in the lower properties Object - canExecWhen.uiState One of the following values that represents the state of the UI:
Always
: Always enabled (default property default).
ProjectOpened
: Valid when the project is open.
ModelSelected
: Valid when a model is selected.
ModelSelectedInEditor
: Valid when a model is selected on the editor."Always", "ProjectOpened", "ModelSelected", "ModelSelectedInEditor" - canExecWhen.profiles Target project profile name Character string representing the profile name - canExecWhen.metamodels The class name of the selected model, or the class name from which it is inherited. If you specify *
as the value or omit the property, it is valid for all models. Ignored if the uiState property is anything other thanModelSelected
,ModelSelectedInEditor
."*" Or a string that represents the class name. If there are multiple, specify them separated by commas. - canExecWhen.viewDefinitions Target view definition name. If you specify *
as the value or omit the property, it is valid in all view definitions. Ignored if the uiState property is anything other thanModelSelectedInEditor
."*" Or a string that represents the view definition name. If there are multiple, specify them separated by commas. - canExecFunc Function name that evaluates the validity condition of the command. 2 If it is set at the same time as canExecWhen, this will be prioritized. However, functions configured only with .NET DLL-style extensions are evaluated. 3 Character string representing function name/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"
}
]
}
}
Command handler implementation example
public void GenerateCode (ICommandContext commandContext, ICommandParams commandParams)
{
//Command handler implementation code
}
Example of using command parameters
When you run the commands defined in the manifest extension point from inside the extension, you can specify parameters.
void ExcecSomeCommands ()
{
//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 the command by specifying the parameter
App.ExecuteCommand ("otherExtension.someCommand", execParams);
}
- In the current version, it does not affect the operation of the extension and is not displayed.↩
- The function signatures that can be set for canExecFunc are:
bool function-name (ICommandContext context, ICommandParams parameters)
. If the configured function is not found, it evaluates to false.↩ - Always evaluates to true if canExecFunc is set in a scripted extension. Only set canExecWhen for scripted extensions.↩