Creating a custom command |
A user interface extension project can implement custom commands in addition to event handlers and property pages. The commands will appear in the menu bar menus and context menus for the objects to which the extension is applied. The commands can also be grouped together on a sub-menu.
The following procedure includes steps for creating a command and a command group. Follow the steps as directed to create either or both.
To create a custom command with the UIExtensionComposer:
Private Sub UIExtensionComposer_CommandExecute(ByVal sender As Object, _ ByVal e As CommandItemEventArgs) Handles MyBase.CommandExecute ' TODO: Add your execute command event handling code here. End Sub
This procedure will handle the Execute event for all commands defined in the extension. If you have more than one command in the same project, then you can use Tag property to distinguish between the commands, similar to the following example.
Private Sub UIExtensionComposer_CommandExecute(ByVal sender As Object, _ ByVal e As CommandItemEventArgs) Handles MyBase.CommandExecute Dim command As BCExtensionCommand = e.Command ' Use Tag property to distinguish between commands. Select Case e.Command.Tag.ToString() Case "MyCommand" ' Add handling code here for the command. End Select End Sub
You can also add a command programmatically:
Private Sub CustomCommandHandler(ByVal sender As Object, ByVal e As CommandEventArgs) ' TODO: Add your execute command event handling code here. End Sub
Public Class UIExtensionComposer Public Sub New() ' Initialization code goes here... ' Add custom command programmatically. Dim command As BCExtensionCommand = New BCExtensionCommand( _ "Custom Command", AddressOf CustomCommandHandler) Commands.Add(command) End Sub ' Extension code goes here... End Class
The custom command can be shown in the Tools menu of Meridian Enteprise PowerUser. To do so, apply the extension to the Environment class either with Meridian Enteprise Configurator or programmatically in the ExtensionRegister event handler similar to the following example:
Private Sub UIExtensionComposer_ExtensionRegister(ByVal sender As Object, _ ByVal e As ExtensionRegisterEventArgs) Handles MyBase.ExtensionRegister ' This assigns your extension the environment class ' You only need to register this extension in your vault to add ' the commands to the Tools menu of the PowerUser AddExtensionToClass(e.Environment, e.ExtensionRef, ObjectKind.AMEDM_AMENVIRONMENT) End Sub