Subscribe to events
Overview
The event extension point is defined in the extension's OnActivate
method, just like in the Ribbon.
You can define event subscriptions by accessing the Events
property of the ExtensionPoints
property.
See manifest events for events you can subscribe to.
public class SampleExtensionEntryPoint : ExtensionBase
{
///<summary>
///Processing during activation.
///</summary>
protected override void OnActivate()
{
//event
ExtensionPoints.Events.Application.RegisterOnAfterStart<ApplicationAfterStartEvent>();
}
}
Subscribed events are processed by implementing the OnHandle
method in the event handler class derived from the base class.
///<summary>
///Application execution event
///</summary>
public class ApplicationAfterStartEvent : ApplicationAfterStartEventHandlerBase
{
///<summary>
///Event handler processing.
///</summary>
///<param name="c"></param>
///<param name="p"></param>
protected override void OnHandle(IEventContext c, AfterStartEventParams p)
{
//Implement event handling.
Output.WriteLine(ExtensionName, $"Events: ApplicationAfterStart Event. Version: {App.Version}");
}
}
Implementing event subscription
Applications
You can subscribe to events before application launch and exit.
//event
ExtensionPoints.Events.Application.RegisterOnAfterStart<ApplicationAfterStartEvent>();
ExtensionPoints.Events.Application.RegisterOnBeforeQuit<ApplicationBeforeQuitEvent>();
commands
You can subscribe to events before and after Next Design command execution.
//command
//add event for "MyExtensionCommand" command implemented in extension
ExtensionPoints.Events.AddCommandEvent("MyExtensionCommand").RegisterOnBeforeExecute<MyExtensionCommandsBeforeExecuteEvent>();
ExtensionPoints.Events.AddCommandEvent("MyExtensionCommand").RegisterOnAfterExecute<MyExtensionCommandsAfterExecuteEvent>();
You can also subscribe to events for system commands by setting the identifier corresponding to the argument of the AddCommandEvent
method.
ExtensionPoints.Events.AddCommandEvent(NextDesignAppCommands.Home_CheckError).RegisterOnBeforeExecute<CheckErrorCommandBeforeExecuteEvent>();
Project
You can subscribe to events such as new, open, and save projects.
//project
ExtensionPoints.Events.Project.RegisterOnAfterNew<ProjectAfterNewEvent>();
ExtensionPoints.Events.Project.RegisterOnBeforeOpen<ProjectBeforeOpenEvent>();
ExtensionPoints.Events.Project.RegisterOnAfterOpen<ProjectAfterOpenEvent>();
ExtensionPoints.Events.Project.RegisterOnBeforeSave<ProjectBeforeSaveEvent>();
ExtensionPoints.Events.Project.RegisterOnAfterSave<ProjectAfterSaveEvent>();
ExtensionPoints.Events.Project.RegisterOnBeforeClose<ProjectBeforeCloseEvent>();
ExtensionPoints.Events.Project.RegisterOnAfterClose<ProjectAfterCloseEvent>();
ExtensionPoints.Events.Project.RegisterOnBeforeReload<ProjectBeforeReloadEvent>();
ExtensionPoints.Events.Project.RegisterOnAfterReload<ProjectAfterReloadEvent>();
Model
You can subscribe to events related to model creation and editing. Specify the classes to subscribe to events with the AddModelEvent
method, and the model edit events to subscribe to with the RegisterOn...
methods.
//model
//add an event to the "SoftwareComponent" metamodel
ExtensionPoints.Events.AddModelEvent("SoftwareComponent").RegisterOnBeforeNew<ModelsBeforeNewEvent>();
ExtensionPoints.Events.AddModelEvent("SoftwareComponent").RegisterOnAfterNew<ModelsAfterNewEvent>();
ExtensionPoints.Events.AddModelEvent("SoftwareComponent").RegisterOnFieldChanged<ModelsFieldChangedEvent>();
ExtensionPoints.Events.AddModelEvent("SoftwareComponent").RegisterOnBeforeDelete<ModelsBeforeDeleteEvent>();
ExtensionPoints.Events.AddModelEvent("SoftwareComponent").RegisterOnBeforeChangeOwner<ModelsBeforeChangeOwnerEvent>();
ExtensionPoints.Events.AddModelEvent("SoftwareComponent").RegisterOnAfterChangeOwner<ModelsAfterChangeOwnerEvent>();
ExtensionPoints.Events.AddModelEvent("SoftwareComponent").RegisterOnBeforeChangeOrder<ModelsBeforeChangeOrderEvent>();
ExtensionPoints.Events.AddModelEvent("SoftwareComponent").RegisterOnAfterChangeOrder<ModelsAfterChangeOrderEvent>();
ExtensionPoints.Events.AddModelEvent("SoftwareComponent").RegisterOnBeforeNewRelation<ModelsBeforeNewRelationEvent>();
ExtensionPoints.Events.AddModelEvent("SoftwareComponent").RegisterOnAfterNewRelation<ModelsAfterNewRelationEvent>();
ExtensionPoints.Events.AddModelEvent("SoftwareComponent").RegisterOnValidate<ModelsValidateEvent>();
ExtensionPoints.Events.AddModelEvent("SoftwareComponent").RegisterOnError<ModelsErrorEvent>();
ExtensionPoints.Events.AddModelEvent("SoftwareComponent").RegisterOnSelectionChanged<ModelsSelectionChangedEvent>();
ExtensionPoints.Events.AddModelEvent("SoftwareComponent").RegisterOnModelEdited<ModelsModelEditedEvent>();
ExtensionPoints.Events.AddModelEvent("SoftwareComponent").RegisterOnUndoRedo<ModelsUndoRedoEvent>();
Multiple class names can be specified by separating them with commas.
ExtensionPoints.Events.AddModelEvent("Actor,UseCase,UseCaseStep").RegisterOnAfterNew<ModelsAfterNewEvent>();
Omitting the metamodel name subscribes to events for all models. This has the same meaning as *
in the manifest.
ExtensionPoints.Events.AddModelEvent().RegisterOnAfterNew<ModelsAfterNewEvent>();
Editor
You can subscribe to editor display and selection events.
//editor
//add an event to the view for "MyViewDefenition"
ExtensionPoints.Events.AddEditorEvent("MyViewDefenition").RegisterOnShow<EditorsShowEvent>();
ExtensionPoints.Events.AddEditorEvent("MyViewDefenition").RegisterOnHide<EditorsHideEvent>();
ExtensionPoints.Events.AddEditorEvent("MyViewDefenition").RegisterOnSelectionChanged<EditorsSelectionChangedEvent>();
Omitting the editor name subscribes to events for all views.
ExtensionPoints.Events.AddEditorEvent().RegisterOnShow<EditorsShowEvent>();
Page
You can subscribe to events before and after page changes.
ExtensionPoints.Events.Pages.RegisterOnBeforeChange<PagesBeforeChangeEvent>();
ExtensionPoints.Events.Pages.RegisterOnAfterChange<PagesAfterChangeEvent>();
Navigator
You can subscribe to navigator change events. Register the event handler with the AddNavigatorEvent
method.
//navigator
ExtensionPoints.Events.AddNavigatorEvent().RegisterOnShow<NavigatorsShowEvent>();
ExtensionPoints.Events.AddNavigatorEvent().RegisterOnHide<NavigatorsHideEvent>();
ExtensionPoints.Events.AddNavigatorEvent().RegisterOnSelectionChanged<NavigatorsSelectionChangedEvent>();
When specifying the tab of the navigator to subscribe to, specify the navigator type with the EventTargetNavigatorType
enumeration as follows.
//subscribe to model navigator display events
ExtensionPoints.Events.AddNavigatorEvent(EventTargetNavigatorType.Model).RegisterOnShow<NavigatorsShowEvent>();
Info Window
You can show/hide the info window, change the selection, and subscribe to double-click.
//navigator
ExtensionPoints.Events.AddInformationEvent().RegisterOnShow<InformationsShowEvent>();
ExtensionPoints.Events.AddInformationEvent().RegisterOnHide<InformationsHideEvent>();
ExtensionPoints.Events.AddInformationEvent().RegisterOnSelectionChanged<InformationsSelectionChangedEvent>();
ExtensionPoints.Events.AddInformationEvent().RegisterOnDoubleClick<InformationsDoubleClickEvent>();
To specify the tab of the information window to subscribe to, specify the type of information window with the EventTargetInformationAreaType
enumeration as follows.
ExtensionPoints.Events.AddInformationEvent(EventTargetInformationAreaType.Error).RegisterOnDoubleClick<InformationsDoubleClickEvent>();