Skip to content

Latest commit

 

History

History
41 lines (31 loc) · 1.17 KB

qa008.md

File metadata and controls

41 lines (31 loc) · 1.17 KB

QA8. Dynamic menus

Q. How do I get dynamic menus?

A.

If your context menu is defined through a block it means is dynamic, and it will be evaluated each time the context menu is invoked.

contextMenu: aValuableOrMenuPresenter
    "Set the context menu.
     Context menu can be an instace of `SpMenuPresenter` or a block (that will answer eventually an 
     instance of `SpMenuPresenter` aswell. 
     If your context menu is defined through a block it means is dynamic, and it will be evaluated 
     each time the context menu is invoked."

    contextMenu := aValuableOrMenuPresenter

Example

Look at SpTreePresenter class>>#exampleWithContextMenu:

app := SpApplication new.
presenter := SpPresenter newApplication: app.

(tree := presenter newTree)
	roots: { Object };
	children: [ :aClass | aClass subclasses ];
	displayIcon: [ :aClass | self iconNamed: aClass systemIconName ];
	display: [ :aClass | aClass name ];
	contextMenu: [
			presenter newMenu 
				addGroup: [ :group | group 
					addItem: [ :item | item name: tree selectedItem asString ] ] ].

presenter layout: (SpBoxLayout newTopToBottom 
	add: tree;
	yourself).

presenter open