Skip to main content

Command Handler Implementation

Overview​

Behavior is implemented by implementing commands for ribbon buttons and shortcut keys. Commands are implemented by inheriting CommandHandlerBase.

  • Command implementation can be done by overriding OnExecute.
  • Whether a command can be executed can be done by overriding OnCanExecute. This result is linked to the enabled/disabled status of the ribbon button. If not implemented, it will always be true.
Note

Referencing model field values ​​in OnCanExecute may cause unloaded model files to load, potentially slowing down the response of operations immediately after opening the project. It is recommended to perform field value-dependent checks in OnExecute. See Changes in V5.1 for details. :::

Note that within the CommandHandlerBase class, you can access App, CurrentProject, etc.

Implementation Example

using NextDesign.Desktop;
using NextDesign.Desktop.ExtensionPoints;

namespace SampleExtension.Commands
{
//<summary>
//This is an implementation of the Hello command.

///</summary>
public class HelloCommand : CommandHandlerBase
{
//<summary>
//Executes a command
///</summary>
///<param name="c"></param>
///<param name="p"></param>
protected override void OnExecute(ICommandContext c, ICommandParams p)
{
if (CurrentProject != null)
{
Output.WriteLine(ExtensionName, $"ProjectName : {CurrentProject.Name}");
}
else
{
Output.WriteLine(ExtensionName, $"Project is not opened");
}
//Activate
App.Window.IsInformationPaneVisible = true;
App.Window.CurrentOutputCategory = ExtensionName;
App.Window.ActiveInfoWindow = "Output";
}
///<summary>
///Determines whether the command can be executed
///</summary>
///<returns>Returns true if the command is valid</returns>
protected override bool OnCanExecute()
{
return true;
}
}
}