static NSMenuItem CreateMenuItem(ContextMenuItem item) { if (item.IsSeparator) { return(NSMenuItem.SeparatorItem); } var menuItem = new NSMenuItem(item.Label, (s, e) => item.Click()); menuItem.Hidden = !item.Visible; menuItem.Enabled = item.Sensitive; menuItem.Image = item.Image.ToNSImage(); if (item is RadioButtonContextMenuItem) { var radioItem = (RadioButtonContextMenuItem)item; menuItem.State = radioItem.Checked ? NSCellStateValue.On : NSCellStateValue.Off; } else if (item is CheckBoxContextMenuItem) { var checkItem = (CheckBoxContextMenuItem)item; menuItem.State = checkItem.Checked ? NSCellStateValue.On : NSCellStateValue.Off; } if (item.SubMenu != null && item.SubMenu.Items.Count > 0) { menuItem.Submenu = FromMenu(item.SubMenu); } else { menuItem.Activated += (sender, e) => item.Click(); } return(menuItem); }
static void AddMenuItem(NSLocationAwareMenu menu, ContextMenuItem item) { if (item.IsSeparator) { menu.AddItem(NSMenuItem.SeparatorItem); return; } var menuItem = new NSMenuItem(item.Label.Replace("_", ""), (s, e) => item.Click()); menuItem.Hidden = !item.Visible; menuItem.Enabled = item.Sensitive; menuItem.Image = item.Image.ToNSImage(); if (item is RadioButtonContextMenuItem) { var radioItem = (RadioButtonContextMenuItem)item; menuItem.State = radioItem.Checked ? NSCellStateValue.On : NSCellStateValue.Off; } else if (item is CheckBoxContextMenuItem) { var checkItem = (CheckBoxContextMenuItem)item; menuItem.State = checkItem.Checked ? NSCellStateValue.On : NSCellStateValue.Off; } if (item.SubMenu != null && item.SubMenu.Items.Count > 0) { var subMenu = FromMenu(item.SubMenu, null); subMenu.Parent = menu; menuItem.Submenu = subMenu; } menu.AddItem(menuItem); }
static Gtk.MenuItem CreateMenuItem (ContextMenuItem item) { if (!item.Visible) return null; if (item.IsSeparator) { return new Gtk.SeparatorMenuItem (); } Gtk.MenuItem menuItem; if (item is RadioButtonContextMenuItem) { var radioItem = (RadioButtonContextMenuItem)item; menuItem = new Gtk.CheckMenuItem (item.Label) { Active = radioItem.Checked, DrawAsRadio = true }; } else if (item is CheckBoxContextMenuItem) { var checkItem = (CheckBoxContextMenuItem)item; menuItem = new Gtk.CheckMenuItem (item.Label) { Active = checkItem.Checked }; } else { menuItem = new Gtk.ImageMenuItem (item.Label); } if (item.SubMenu != null && item.SubMenu.Items.Count > 0) { menuItem.Submenu = FromMenu (item.SubMenu); } else { menuItem.Activated += (sender, e) => item.Click (); } menuItem.Sensitive = item.Sensitive; var label = (Gtk.Label) menuItem.Child; label.UseUnderline = item.UseMnemonic; if (item.UseMnemonic) label.TextWithMnemonic = item.Label; if (item.Image != null) { Gtk.ImageMenuItem imageItem = menuItem as Gtk.ImageMenuItem; if (imageItem != null) { var img = new ImageView (item.Image); img.ShowAll (); imageItem.Image = img; GtkWorkarounds.ForceImageOnMenuItem (imageItem); } } return menuItem; }
static NSMenuItem CreateMenuItem (ContextMenuItem item) { if (item.IsSeparator) { return NSMenuItem.SeparatorItem; } var menuItem = new NSMenuItem (item.Label.Replace ("_",""), (s, e) => item.Click ()); menuItem.Hidden = !item.Visible; menuItem.Enabled = item.Sensitive; menuItem.Image = item.Image.ToNSImage (); if (item is RadioButtonContextMenuItem) { var radioItem = (RadioButtonContextMenuItem)item; menuItem.State = radioItem.Checked ? NSCellStateValue.On : NSCellStateValue.Off; } else if (item is CheckBoxContextMenuItem) { var checkItem = (CheckBoxContextMenuItem)item; menuItem.State = checkItem.Checked ? NSCellStateValue.On : NSCellStateValue.Off; } if (item.SubMenu != null && item.SubMenu.Items.Count > 0) { menuItem.Submenu = FromMenu (item.SubMenu, null); } return menuItem; }
static Gtk.MenuItem CreateMenuItem(ContextMenuItem item) { if (!item.Visible) { return(null); } if (item.IsSeparator) { return(new Gtk.SeparatorMenuItem()); } Gtk.MenuItem menuItem; if (item is RadioButtonContextMenuItem) { var radioItem = (RadioButtonContextMenuItem)item; menuItem = new Gtk.CheckMenuItem(item.Label) { Active = radioItem.Checked, DrawAsRadio = true }; } else if (item is CheckBoxContextMenuItem) { var checkItem = (CheckBoxContextMenuItem)item; menuItem = new Gtk.CheckMenuItem(item.Label) { Active = checkItem.Checked }; } else { menuItem = new Gtk.ImageMenuItem(item.Label); } if (item.SubMenu != null && item.SubMenu.Items.Count > 0) { menuItem.Submenu = FromMenu(item.SubMenu, null); } else { menuItem.Activated += (sender, e) => item.Click(); } menuItem.Sensitive = item.Sensitive; var label = (Gtk.Label)menuItem.Child; label.UseUnderline = item.UseMnemonic; if (item.UseMnemonic) { label.TextWithMnemonic = item.Label; } if (item.Image != null) { Gtk.ImageMenuItem imageItem = menuItem as Gtk.ImageMenuItem; if (imageItem != null) { var img = new ImageView(item.Image); img.ShowAll(); imageItem.Image = img; Xwt.GtkBackend.GtkWorkarounds.ForceImageOnMenuItem(imageItem); } } return(menuItem); }
static Gtk.MenuItem CreateMenuItem (ContextMenuItem item) { if (!item.Visible) return null; if (item.IsSeparator) { return new Gtk.SeparatorMenuItem (); } Gtk.MenuItem menuItem; if (item is RadioButtonContextMenuItem) { var radioItem = (RadioButtonContextMenuItem)item; menuItem = new Gtk.CheckMenuItem (item.Label) { Active = radioItem.Checked, DrawAsRadio = true }; } else if (item is CheckBoxContextMenuItem) { var checkItem = (CheckBoxContextMenuItem)item; menuItem = new Gtk.CheckMenuItem (item.Label) { Active = checkItem.Checked }; } else { menuItem = new Gtk.ImageMenuItem (item.Label); } menuItem.Selected += delegate (object sender, EventArgs e) { var si = sender as Gtk.MenuItem; if (si == null || si.GdkWindow == null) return; int x, y; si.GdkWindow.GetOrigin (out x, out y); int rx, ry; IdeApp.Workbench.RootWindow.GdkWindow.GetOrigin (out rx, out ry); item.FireSelectedEvent (new Xwt.Rectangle (x - rx, y - ry, si.Allocation.Width, si.Allocation.Height)); }; menuItem.Deselected += delegate { item.FireDeselectedEvent (); }; if (item.SubMenu != null && item.SubMenu.Items.Count > 0) { menuItem.Submenu = FromMenu (item.SubMenu, null); } else { menuItem.Activated += (sender, e) => item.Click (); } menuItem.Sensitive = item.Sensitive; var label = (Gtk.Label) menuItem.Child; label.UseUnderline = item.UseMnemonic; if (item.UseMnemonic) label.TextWithMnemonic = item.Label; if (item.Image != null) { Gtk.ImageMenuItem imageItem = menuItem as Gtk.ImageMenuItem; if (imageItem != null) { var img = new ImageView (item.Image); img.ShowAll (); imageItem.Image = img; Xwt.GtkBackend.GtkWorkarounds.ForceImageOnMenuItem (imageItem); } } return menuItem; }
static Gtk.MenuItem CreateMenuItem(ContextMenuItem item) { if (!item.Visible) { return(null); } if (item.IsSeparator) { return(new Gtk.SeparatorMenuItem()); } Gtk.MenuItem menuItem; if (item is RadioButtonContextMenuItem) { var radioItem = (RadioButtonContextMenuItem)item; menuItem = new Gtk.CheckMenuItem(item.Label) { Active = radioItem.Checked, DrawAsRadio = true }; } else if (item is CheckBoxContextMenuItem) { var checkItem = (CheckBoxContextMenuItem)item; menuItem = new Gtk.CheckMenuItem(item.Label) { Active = checkItem.Checked }; } else { menuItem = new Gtk.ImageMenuItem(item.Label); } menuItem.Selected += delegate(object sender, EventArgs e) { var si = sender as Gtk.MenuItem; if (si == null || si.GdkWindow == null) { return; } int x, y; si.GdkWindow.GetOrigin(out x, out y); int rx, ry; IdeApp.Workbench.RootWindow.GdkWindow.GetOrigin(out rx, out ry); item.FireSelectedEvent(new Xwt.Rectangle(x - rx, y - ry, si.Allocation.Width, si.Allocation.Height)); }; menuItem.Deselected += delegate { item.FireDeselectedEvent(); }; if (item.SubMenu != null && item.SubMenu.Items.Count > 0) { menuItem.Submenu = FromMenu(item.SubMenu, null); } else { menuItem.Activated += (sender, e) => item.Click(); } menuItem.Sensitive = item.Sensitive; var label = (Gtk.Label)menuItem.Child; label.UseUnderline = item.UseMnemonic; if (item.UseMnemonic) { label.TextWithMnemonic = item.Label; } if (item.Image != null) { Gtk.ImageMenuItem imageItem = menuItem as Gtk.ImageMenuItem; if (imageItem != null) { var img = new ImageView(item.Image); img.ShowAll(); imageItem.Image = img; Xwt.GtkBackend.GtkWorkarounds.ForceImageOnMenuItem(imageItem); } } return(menuItem); }