Skip to main content

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

    keydescriptionrangerequired
    idID that uniquely identifies the command. Unique string for all deployed extensionsString representing IDRequired
    titlecommand title 1any string-
    descriptionCommand description 1Any string-
    groupgroup to which the command belongs 1string representing the group name-
    execFuncname of the command handler implemented in the entry pointstring representing the method namerequired
    canExecWhenCommand valid condition. See lower property for detailsObject-
    canExecWhen.uiStateOne 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.profilesProfile name of target projectCharacter string representing profile name-
    canExecWhen.metamodelsThe 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 not ModelSelected, ModelSelectedInEditor."*" or a string representing the class name. If multiple, specify them by separating them with commas.-
    canExecWhen.viewDefinitionsTarget 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 than ModelSelectedInEditor."*" or a string representing the view definition name. If multiple, specify them by separating them with commas.-
    canExecFuncThe 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. 3string 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

  1. In the current version it does not affect the behavior of the extension and is not displayed.
    2 3 4

  2. 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

  3. Always evaluates to true if you set canExecFunc in a scripted extension. Only set canExecWhen in scripted extensions. 2