By Barbara Han
Vault 2013 introduces a new feature “Custom Entity” (also called “Custom Object” from Vault Explorer UI), and our 3-rd party developers may want to add commands to the context menu on the custom entity. This can be done straightly.
First of all, find the Name of the Custom Entity. This Name is not display name or display plural name as what you see from UI. It is a string like a GUID. You can run a small app to find the Name of the Custom Entity. Please refer to below VB.NET sample code:
Dim custEntSvc As CustomEntityService = ServiceManager.CustomEntityService
Dim defs As CustEntDef() = custEntSvc.GetAllCustomEntityDefinitions()
For Each def As CustEntDef In defs
If def.DispName = "CustObjTest" Then
System.Diagnostics.Debug.Print(def.Name)
Exit For
End If
Next
Next, you can add the command through a Vault Explorer extension application. The code is very similar like the one that creating the command for file or other entities, but the CommandItem.NavigationTypes needs to change to create a SelectionTypeId for the custom entity and CommandSite.Location needs to point to custom entity’s context menu. Please refer to below VB.NET sample code snippet for more details:
' This function tells Vault Explorer what custom commands this extension provides.
' Part of the IExtension interface.
' A collection of CommandSites, which are collections of custom commands.
Public Function CommandSites() As IEnumerable(Of CommandSite) Implements IExtension.CommandSites
' Create the Hello World command object.
' This command is active when a custom entity is selected
' This command is not active if there are multiple entities selected
Dim helloWorldCmdItem As New CommandItem("HelloWorldCommand", "Hello World...") With { _
.NavigationTypes = New SelectionTypeId() {New SelectionTypeId("45466327-8edd-4ef4-a6df-295d8c1bd2cb")}, _
.MultiSelectEnabled = False _
}
'.NavigationTypes = New SelectionTypeId() {SelectionTypeId.File, SelectionTypeId.FileVersion}, _
' The HelloWorldCommandHandler function is called when the custom command is executed.
AddHandler helloWorldCmdItem.Execute, AddressOf HelloWorldCommandHandler
' Create a command site to hook the command to the Advanced toolbar
Dim toolbarCmdSite As New CommandSite("HelloWorldCommand.Toolbar", "Hello World Menu") With { _
.Location = CommandSiteLocation.AdvancedToolbar, _
.DeployAsPulldownMenu = False _
}
toolbarCmdSite.AddCommand(helloWorldCmdItem)
' Create another command site to hook the command to the right-click menu for custom entity.
Dim fileContextCmdSite As New CommandSite("HelloWorldCommand.FileContextMenu", "Hello World Menu") With { _
.Location = New CommandSiteLocation("45466327-8edd-4ef4-a6df-295d8c1bd2cb", CommandSiteLocationType.ContextMenu), _
.DeployAsPulldownMenu = False _
}
'.Location = CommandSiteLocation.FileContextMenu, _
fileContextCmdSite.AddCommand(helloWorldCmdItem)
' Now the custom command is available in 2 places.
' Gather the sites in a List.
Dim sites As New List(Of CommandSite)()
sites.Add(toolbarCmdSite)
sites.Add(fileContextCmdSite)
' Return the list of CommandSites.
Return sites
End Function