Define Menu Items

Return to Introduction  Previous page  Next page

Menu items are defined by responding to the GetMenuItems event.

The first time this event is called, MenuName is an empty string, representing the top-level menu.  For a simple Add-In with just a single menu option you can return a string, eg:

Function EA_GetMenuItems(Repository as EA.Repository, MenuLocation As String, MenuName As String) As Variant

   EA_GetMenuItems = "&Joe's Add-In"

End Function

 

To define sub-menus, prefix a parent menu with a dash. Parent and sub-items are defined as follows:

Function EA_GetMenuItems(Repository as EA.Repository, MenuLocation As String, MenuName As String) As Variant

   Select Case MenuName

   Case ""

           'Parent Menu Item

       EA_GetMenuItems = "-&Joe's Add-In"

   Case "-&Joe's Add-In"

           'Define Sub-Menu Items using the Array notation. 

           'In this example, "Diagram" and "Treeview" compose the "Joe's Add-In" sub-menu.

       EA_GetMenuItems = Array("&Diagram", "&Treeview")

   Case Else

       MsgBox "Invalid Menu", vbCritical

   End Select

End Function

 

Similarly, you can define further sub-items:

Function EA_GetMenuItems(Repository as EA.Repository, MenuLocation As String, MenuName As String) As Variant

   Select Case MenuName

   Case ""

       EA_GetMenuItems = "-Joe's Add-In"

   Case "-Joe's Add-In"

       EA_GetMenuItems = Array("-&Diagram", "&TreeView")

   Case "-&Diagram"

       EA_GetMenuItems = "&Properties"

   Case Else

       MsgBox "Invalid Menu", vbCritical

   End Select

End Function

 

If you want to enable or disable menu options by default, you can use this method to show particular items to the user:

Sub EA_GetMenuState(Repository As EA.Repository, Location As String, MenuName As String, ItemName As String, IsEnabled As Boolean, IsChecked As Boolean)

   Select Case Location

   Case "TreeView"

       'Always enable

   Case "Diagram"

       'Always enable

   Case "MainMenu"

       Select Case ItemName

       Case "&Translate", "Save &Project"

           If GetIsProjectSelected() Then

               IsEnabled = False

           End If

       End Select

   End Select

   IsChecked = GetIsCurrentSelection()

End Sub