Adding to browser menus
The EtToolsVendorExtensionsApp provides protocol for extending the configuration map, applications, classes, methods, and text browser menus in the form of the following twelve SubApplication class methods:
addToApplicationsMenu:browser:
addToCategoriesMenu:browser:
addToClassesMenu:browser:
addToDefaultTextMenu:browser:
addToDependentsMenu:browser
addToExpressionsMenu:browser:
addToGroupMembersMenu:browser:
addToMethodsMenu:browser:
addToNamesMenu:browser:
addToPrerequisitesMenu:browser:
addToRequiredMapsMenu:browser:
addToSubApplicationsMenu:browser:
Each of these methods has two parameters: aMenu is the menu (an instance of CwMenu) that you are adding item(s) to, and aBrowser is the browser that the menu is being built for. You’ve probably already noticed that not all of these methods are applicable to every browser. The rule for applicability is pretty simple. Each of these methods contains the name of a browser menu bar item in its selector. If the browser you want to extend has a menu bar item with that name, then the method is applicable; otherwise it isn’t.
In many cases, you will want to point your callback to the browser, since it serves as a source of state information.
Adding items to main menus
The simplest use of these methods is to add an item to the identified main menu. Let's look at a short example of doing this.
MyApp class>>#addToApplicationsMenu: aMenu browser: aBrowser
"The default behavior for the receiver is to add
nothing to the applications menu."
"Subclasses can override this message to add items."
 
aMenu
add: #inspect
label: 'Inspect Browser'
enable: [ aBrowser isApplicationSelected ]
for: aBrowser
This method adds a new menu item labeled Inspect Browser to the end of aMenu owned by aBrowser.
Adding items to submenus
Sometimes you want your tool to be installed on a submenu rather than the main menu. For this purpose, you can use the #menuItemWithValue: method to access submenus. Here's an example of how to use it:
MedThreeWayDifferencesApp class>>#addToClassesMenu: aMenu browser: aBrowser
 
| theMenu |
 
theMenu := aMenu menuItemWithValue: #compareClassSubMenu.
theMenu isNil ifTrue: [ ^ self ].
theMenu subMenu
add: #diffClass3Ways
label: '3-way Diff'
enable: [ aBrowser isOneClassSelected ]
for: aBrowser
This example is taken from the code for the three-way differences browser goodie supplied in the repository. We use #menuItemWithValue: because we want the menu item to appear on the Compare… submenu along with all other differencing options.
Last modified date: 01/29/2015