Skip to main content

Implementation of handler

Implement those processes for commands and events defined as extension points in the manifest. Class methods that implement these processes are called command handlersandevent handlers. These handlers are implemented as public methods in the public class (hereinafter referred to as the main class) that implements IExtension. The name of the main class and the name of the class file can be arbitrary.

Implementation example

The following is an implementation example of the command handler when the following command is defined in the manifest.

Manifest command definition example

  "extensionPoints": {
"commands": [
{
"id": "Command.SayHello",
"execFunc": "SayHello"
}
],,
...
}

In the above command definition example, implement the command handler named SayHello specified in the extensionPoints.commands [0] .execFunc property as a public method of the main class.

Implementation example of command handler in main class

//Declare the namespace of the API to be referenced in extension development
using NextDesign.Extension;
using NextDesign.Core;
using NextDesign.Desktop;

//Main class of DLL that is the entry point
//Implement IExtension in the main class.
//Implement the handler as a public method of this class.
public class MyExtension: IExtension
{
//Extension initialization process
public void Activate (IContext context)
{
//Implemented as an empty method even if there is no processing
}

//Extension termination processing
public void Deactivate (IContext context)
{
//Implemented as an empty method even if there is no processing
}

//Command handler
public void SayHello (ICommandContext context, ICommandParams commandParams)
{
context.App.Window.UI.ShowInformationDialog ("Hello!", "Hello World");
}

}
  • In case of DLL implementation method, define a class that implements IExtension in the DLL file specified as the entry point. increase.

  • Implement public methods named Activate, Deactviate in this class.

    Activate method: Executes only once immediately after the extension life cycle begins. Deactivate method: Executed only once just before the end of the extension's life cycle.

    Even if initialization processing and termination processing are not required, implement it as an empty method.

  • The Activate and Deactivate methods can implement initialization and termination processing for the entire extension, in addition to the processing of the handler that is called for each command or event.

    Example of initialization processing: Initialization of common variables, reading of configuration file, etc. Example of termination processing: Saving status and settings to a file, etc.

See the following references for more information on the arguments passed to the command handler.

remarks

important

The DLL file specified for the entry point must contain one main class that implements IExtension. All handlers must be implemented as public methods of their main class.

Tip

For large-scale extension development, the number of handlers is large, and the implementation code of the entry point is also bloated. In order to make the entry point implementation code compact, it is recommended to have the following file structure.

  • Implement the actual processing in a file different from the entry point and divide the file.
  • In the handler implemented in the entry point file, the function implemented in another file or the class method implemented in another class is called.