简体   繁体   English

将菜单添加到ListModel

[英]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? 菜单有什么指导方针吗?

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, HTH,

Benjamin Van Ryseghem Benjamin Van Ryseghem

#

EDIT: ListModel is still using the old menus (for compatibility reason in Pharo 3.0). 编辑:ListModel仍在使用旧菜单(出于兼容性原因,在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) 请注意,菜单块应返回菜单(PluggableListMorph的限制,应该封装)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM