Skip to content

Instantly share code, notes, and snippets.

@chamons
Created December 8, 2014 17:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chamons/66c79fedd7a643022376 to your computer and use it in GitHub Desktop.
Save chamons/66c79fedd7a643022376 to your computer and use it in GitHub Desktop.
//#define MEM_CORRECT
using System;
using System.Drawing;
using MonoMac.Foundation;
using MonoMac.AppKit;
using MonoMac.ObjCRuntime;
namespace MenuDelTest
{
public partial class AppDelegate : NSApplicationDelegate
{
MainWindowController mainWindowController;
#if MEM_CORRECT
MyMenuDel del;
#endif
public AppDelegate ()
{
}
public override void DidFinishLaunching (NSNotification notification)
{
mainWindowController = new MainWindowController ();
mainWindowController.Window.MakeKeyAndOrderFront (this);
NSMenuItem newMenuItem = new NSMenuItem ("some menu");
NSMenu myMenu = new NSMenu ("Menu Under Test");
newMenuItem.Submenu = myMenu;
NSMenuItem item1 = myMenu.AddItem ("On the fly menu", null, "");
NSMenu onTheFlyMenu = new NSMenu ("On the fly menu");
#if MEM_CORRECT
del = new MyMenuDel ();
onTheFlyMenu.Delegate = del;
#else
onTheFlyMenu.Delegate = new MyMenuDel ();
#endif
item1.Submenu = onTheFlyMenu;
NSApplication.SharedApplication.MainMenu.AddItem (newMenuItem);
NSButton b = new NSButton (new RectangleF (0, 0, 50, 50));
b.Activated += HandleActivated;
mainWindowController.Window.ContentView.AddSubview (b);
}
void HandleActivated (object sender, EventArgs e)
{
GC.Collect (2);
}
}
public partial class MyMenuDel : NSMenuDelegate
{
public override void MenuWillHighlightItem (NSMenu menu, NSMenuItem item)
{
}
public override void MenuWillOpen (NSMenu menu)
{
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment