NSTextField in CustomView in NSMenuItem

I have a menubar app where I am setting a custom view to one of the menu items. Upon launch, the view is there but the view doesn’t respond to my clicks.

Is there something I am missing that is causing this behavior?


set myMenu to (my NSMenu's alloc)'s initWithTitle_("myMenu")
set menuItem to (my NSMenuItem's alloc)'s init
menuItem's setView_(custView)
menuItem's setTarget_(me)
menuItem's setEnabled_(true)
myMenu's addItem_(menuItem)
menuItem's release()

You don’t seem to have set an action for it.

Well, the custom view contains a text field and two buttons so it wouldn’t be a single action (EDIT: would it?).

The view being rendered, I am just unable to focus on the text field or get any response from the buttons (they do depress, but no action is called).

The docs seem to have half your answer:

Wow! Good find! Although that kinda ruins my plans. I guess I’ll have to bind a window to that location to make it appear like a drop-down. Don’t really like that either, though.

So if keyboard events are ignored, how did they make the spotlight menu and the search field in the help menu work? I find that strange that they would not allow us to make NSTextFields work inside an NSMenu… maybe if you created a delegate for that text field and use textDidChange: or textDidEndEditing: methods?

Browser: Safari 531.22.7
Operating System: Mac OS X (10.6)

It is possible to workaround this by rendering the custom view inside an attached NSWindow that is drawn programmatically.

This will allow you to focus the text field. Just tried it in this Cocoa example: http://mattgemmell.com/2008/03/04/using-maattachedwindow-with-an-nsstatusitem

and it works!

I am sure there is another way to do this, but this is the only one that I’ve found so far that creates the NSWindow.

To set the level of the window is in the comments of Matt’s site.

Cheers,

gt :slight_smile: