3.7.3 Context Menus
To add a context menu to your morph class, the first thing to do is take over mouse handling:
handlesMouseDown: anEvent
^ true.
Next, decide if you want to start with the standard menu, or go totally custom. If you want to include the standard options, compile:
defaultYellowButtonMenuEnabled
^ true.
Then create #addCustomMenuItems:hand: with your morph-specific items. Here's an excerpt from TextMorph:
addCustomMenuItems: aCustomMenu hand: aHandMorph
super addCustomMenuItems: aCustomMenu hand: aHandMorph.
aCustomMenu add: 'text margins...' translated action: #changeMargins:.
If you'd rather take full control and start from scratch, build your menu in #addYellowButtonMenuItemsTo:event:. Here's an excerpt from Morph's default menu:
addYellowButtonMenuItemsTo: aMenu event: evt
aMenu defaultTarget: self.
"snipped..."
aMenu addStayUpItem.
self cmdGesturesEnabled ifTrue: [
aMenu addLine.
aMenu add: 'inspect' translated action: #inspect].