[Mono-osx] Enabling menu items

Jon Lipsky jon.lipsky at elevenworks.com
Thu Apr 5 20:53:48 UTC 2012


This won't get called when the menu item is selected.  This will get called when the parent NSMenu itself is presented assuming that the the NSMenu is setup to auto validate it's child menu items.  From your original message I thought you wanted to control whether the item was enabled or not (which is what the sample code will do).

If you want to get a callback when the item is selected, you should wire up the menu item to an action (that you create) in XCode.  For example, if you wired it up to call an action called "myAction:", you'd add the following to your first responder:

[Export("myAction:")] 
public void MyAction () 
{ 
    // Do something
}

That method would then be called when the menu is selected.

All of my MonoMac applications are document based applications, so I always put these methods into my NSDocument subclass; however it sounds like you're not creating a document based application, thus I would think that the methods should go onto the window controller.

On Apr 5, 2012, at 3:40 PM, tlapse wrote:

> Thanks, but I still have no idea where to put your sample code.
> 
> I tried MainWindowController.cs, but it isn't reached by the debugger when a
> menu item is selected.
> 
> 
> 
> --
> View this message in context: http://mono.1490590.n4.nabble.com/Enabling-menu-items-tp4535796p4535995.html
> Sent from the Mono - OSX mailing list archive at Nabble.com.
> _______________________________________________
> Mono-osx mailing list
> Mono-osx at lists.ximian.com
> http://lists.ximian.com/mailman/listinfo/mono-osx

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.ximian.com/pipermail/mono-osx/attachments/20120405/f22f4b16/attachment.html>


More information about the Mono-osx mailing list