Example #1
0
        static void AddMenuItem(NSLocationAwareMenu menu, ContextMenuItem item)
        {
            if (item.IsSeparator)
            {
                menu.AddItem(NSMenuItem.SeparatorItem);
                return;
            }

            var menuItem = new NSContextMenuItem(item.Label.Replace("_", ""), item);

            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, menu);
                menuItem.Submenu = subMenu;
            }

            menu.AddItem(menuItem);
        }