Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
//#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