<commit_before>using System;
using System.Reflection;
using Eto.Drawing;
using Eto.Forms;
using MonoMac.AppKit;
using MonoMac.Foundation;
using MonoMac.ObjCRuntime;
using sd = System.Drawing;

namespace Eto.Platform.Mac
{

	public class ImageMenuItemHandler : MenuHandler<NSMenuItem, ImageMenuItem>, IImageMenuItem, IMenuActionHandler
	{
		Image image;
		bool showImage = ShowImageDefault;

		public static bool ShowImageDefault = false;

		public bool ShowImage
		{
			get { return showImage; }
			set {
				showImage = value;
				SetImage ();
			}
		}

		public ImageMenuItemHandler ()
		{
			Control = new NSMenuItem ();
			Enabled = true;
			Control.Target = new MenuActionHandler{ Handler = this };
			Control.Action = MenuActionHandler.selActivate;
		}
		
		public void HandleClick ()
		{
			Widget.OnClick (EventArgs.Empty);
		}

		public override void AttachEvent (string handler)
		{
			switch (handler) {
			case ImageMenuItem.ValidateEvent:
				// handled in MenuActionHandler
				break;
			default:
				base.AttachEvent (handler);
				break;
			}
		}
		
		public bool Enabled {
			get { return Control.Enabled; }
			set { Control.Enabled = value; }
		}

		public string Text {
			get	{ return Control.Title; }
			set { 
				Control.SetTitleWithMnemonic (value);
				if (Control.HasSubmenu)
					Control.Submenu.Title = Control.Title;
			}
		}
		
		public string ToolTip {
			get {
				return Control.ToolTip;
			}
			set {
				Control.ToolTip = value;
			}
		}

		public Key Shortcut {
			get { return KeyMap.Convert (Control.KeyEquivalent, Control.KeyEquivalentModifierMask); }
			set { 
				this.Control.KeyEquivalent = KeyMap.KeyEquivalent (value);
				this.Control.KeyEquivalentModifierMask = KeyMap.KeyEquivalentModifierMask (value);
			}
		}

		public Image Image {
			get { return image; }
			set {
				image = value;
				SetImage ();
			}
		}

		void SetImage ()
		{
#if XAMMAC
			Control.Image = ShowImageDefault ? this.image.ToNS (16) : new NSImage (new sd.SizeF (1,1));
#else
			Control.Image = ShowImageDefault ? this.image.ToNS (16) : null;
#endif
		}

		public override void AddMenu (int index, MenuItem item)
		{
			base.AddMenu (index, item);
			//if (Control.HasSubmenu) Control.Submenu.Title = Control.Title;
		}

		MenuActionItem IMenuActionHandler.Widget {
			get { return Widget; }
		}

	}
}<commit_msg>Add null check to avoid an exception that was encountered.<commit_after>using System;
using System.Reflection;
using Eto.Drawing;
using Eto.Forms;
using MonoMac.AppKit;
using MonoMac.Foundation;
using MonoMac.ObjCRuntime;
using sd = System.Drawing;

namespace Eto.Platform.Mac
{

	public class ImageMenuItemHandler : MenuHandler<NSMenuItem, ImageMenuItem>, IImageMenuItem, IMenuActionHandler
	{
		Image image;
		bool showImage = ShowImageDefault;

		public static bool ShowImageDefault = false;

		public bool ShowImage
		{
			get { return showImage; }
			set {
				showImage = value;
				SetImage ();
			}
		}

		public ImageMenuItemHandler ()
		{
			Control = new NSMenuItem ();
			Enabled = true;
			Control.Target = new MenuActionHandler{ Handler = this };
			Control.Action = MenuActionHandler.selActivate;
		}
		
		public void HandleClick ()
		{
			Widget.OnClick (EventArgs.Empty);
		}

		public override void AttachEvent (string handler)
		{
			switch (handler) {
			case ImageMenuItem.ValidateEvent:
				// handled in MenuActionHandler
				break;
			default:
				base.AttachEvent (handler);
				break;
			}
		}
		
		public bool Enabled {
			get { return Control.Enabled; }
			set { Control.Enabled = value; }
		}

		public string Text {
			get	{ return Control.Title; }
			set { 
				Control.SetTitleWithMnemonic (value);
				if (Control.HasSubmenu)
					Control.Submenu.Title = Control.Title;
			}
		}
		
		public string ToolTip {
			get {
				return Control.ToolTip;
			}
			set {
				Control.ToolTip = value;
			}
		}

		public Key Shortcut {
			get { return KeyMap.Convert (Control.KeyEquivalent, Control.KeyEquivalentModifierMask); }
			set { 
				this.Control.KeyEquivalent = KeyMap.KeyEquivalent (value);
				this.Control.KeyEquivalentModifierMask = KeyMap.KeyEquivalentModifierMask (value);
			}
		}

		public Image Image {
			get { return image; }
			set {
				image = value;
				SetImage ();
			}
		}

		void SetImage ()
		{
#if XAMMAC
			Control.Image = ShowImageDefault ? this.image.ToNS (16) : new NSImage (new sd.SizeF (1,1));
#else
			if (this.image != null && ShowImageDefault)
				Control.Image = ShowImageDefault ? this.image.ToNS(16) : null;
#endif
		}

		public override void AddMenu (int index, MenuItem item)
		{
			base.AddMenu (index, item);
			//if (Control.HasSubmenu) Control.Submenu.Title = Control.Title;
		}

		MenuActionItem IMenuActionHandler.Widget {
			get { return Widget; }
		}

	}
}
{'fraction_non_alphanumeric': 0.09991603694374475, 'fraction_numerical': 0.0025188916876574307, 'mean_word_length': 3.1255411255411256, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3630093', 'n_tokens_mistral': 1829, 'n_tokens_neox': 1498, 'n_words': 370}