Skip to main content

Implement command handler

Overview

You implement behavior by implementing commands for ribbon buttons and shortcut keys. Commands are implemented by inheriting CommandHandlerBase.

  • Command implementation can be implemented by overriding OnExecute.
  • Whether a command can be executed can be implemented by overriding OnCanExecute. This result is linked with the enabled/disabled judgment of the ribbon button. Always true if not implemented.

In addition, App CurrentProject etc. can be accessed in the CommandHandlerBase class.

Implementation example

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

namespace SampleExtension.Commands
{
///<summary>
///Implementation of the Hello command.
///</summary>
public class HelloCommand : CommandHandlerBase
{
///<summary>
///execute 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>
///Determining whether the command can be executed
///</summary>
///<returns>true if the command is valid</returns>
protected override bool OnCanExecute()
{
return true;
}
}
}