Skip to main content

Implementation of command handler

Implement the behavior by implementing commands for buttons and shortcut keys on the ribbon. The command inherits and implements CommandHandlerBase. Within the CommandHandlerBase class, you can access things like App CurrentProject.

Command implementation example

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

namespace SampleExtension.Commands
{
///<summary>
///Implementation of Hello command.
///</summary>
public class HelloCommand: CommandHandlerBase
{
///<summary>
///Command execution
///</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 else
{
Output.WriteLine (ExtensionName, $ "Project is not opened");
}

//activate
App.Window.IsInformationPaneVisible = true;
App.Window.CurrentOutputCategory = ExtensionName;
App.Window.ActiveInfoWindow = "Output";
}
}
}

Whether the command can be executed

Whether the command can be executed can be implemented by overriding OnCanExecute. This result is linked to the validity/invalidity judgment of the button on the ribbon. If not implemented, it will always be true.

public class HelloCommand: CommandHandlerBase
{
///<summary>
///Judgment whether the command can be executed
///</summary>
///true if the <returns> command is valid </returns>
protected override bool OnCanExecute ()
{
return true;
}
}