开发者

How do i add a right-click option to a menulet in Xcode and Interface Builder?

I'm trying to have a menulet that acts different on left-click and on right-click (and maybe combinations in the future like control-click, option-click or command-click).

Right now I have a menulet with a statusMenu attached to it that opens on left- an开发者_运维百科d on right-click. In the statusMenu are five options: one execution item, three preference-setting-items and one quit item.

I'd like to separate the behavior somewhat as the menulet is designed to be a one trick pony. Left-clicking it should execute the function, right-clicking should open the menu exactly as it is (including the execution).

Any ideas how to do this?

Right now I'm calling the statusMenu from the code as is usual with statusMenus

[statusItem setMenu:statusMenu];


To do this, you will need to display the menu manually. One way to do it is to create a custom view and place that in the status item, and then use the mouseUp: and rightMouseUp: event handlers to perform your actions. You can also get the modifier keys from the event to perform other actions. It may also be possible to use the built-in target-action mechanism of the status item, and get the information from the NSEvent class methods +pressedMouseButtons and +modifierFlags. Either way, you can display your menu using NSStatusItem's -popUpStatusItemMenu: method.

For an example of handling left and right clicks with a custom view, see my answer to this question.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜