Uko
Uko

Reputation: 13396

Add menu to ListModel

How can I add a menu to a list model with decent actions?

I've seen some code like:

list menu: [ :menu |
  menu
    add: 'Name'
    action: [ "some action" ].

but when I do this I get an error because the block is not evaluated but sent as a message to something else…

Are there any guidelines for menus?

Upvotes: 3

Views: 168

Answers (1)

Benjamin Van Ryseghem
Benjamin Van Ryseghem

Reputation: 136

Menus have been redone.

Now you should do something like

list menu: [ :menu | aMenu addGroup: [:aGroup |
    aGroup addItem: [ :item |
        item
            name: 'Inspect' translated;
            action: [ self inspectSelectedObjectInNewWindow ];
            shortcut: $i command mac | $i alt win | $i alt unix ].
    aGroup addItem: [ :item |
        item
            name: 'Explore' translated;
            action: [ self exploreSelectedObject ];
            shortcut: $i shift command mac | $i shift alt win | $i shift alt unix ] ].

HTH,

Benjamin Van Ryseghem

#

EDIT: ListModel is still using the old menus (for compatibility reason in Pharo 3.0). A working example is

ListModel new
    menu: [:m | 
        m 
            add: 'test' 
            target: [self halt ] 
            action: #value. 
        m ];
    openWithSpec

Note that the menu block should return the menu (a limitation from PluggableListMorph that should be encapsulated)

Upvotes: 3

Related Questions