Skip to main content

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

1 2 3

  • Properties

    KeyDescriptionRangeRequired?
    idAn ID that uniquely identifies the command. Unique string for all deployed extensionsID stringRequired
    titleCommand title 1Arbitrary string-
    descriptionCommand description 1Arbitrary string-
    groupThe group to which the command belongs 1A string representing the group name-
    execFuncCommand handler name implemented at the entry pointString representing function/method nameRequired
    canExecWhenCommand valid condition. Details are as shown in the lower propertiesObject-
    canExecWhen.uiStateOne 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.profilesTarget project profile nameCharacter string representing the profile name-
    canExecWhen.metamodelsThe 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 than ModelSelected, ModelSelectedInEditor."*" Or a string that represents the class name. If there are multiple, specify them separated by commas.-
    canExecWhen.viewDefinitionsTarget 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 than ModelSelectedInEditor."*" Or a string that represents the view definition name. If there are multiple, specify them separated by commas.-
    canExecFuncFunction 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. 3Character 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);
}

  1. In the current version, it does not affect the operation of the extension and is not displayed.
  2. 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.
  3. Always evaluates to true if canExecFunc is set in a scripted extension. Only set canExecWhen for scripted extensions.