/// <summary>
        /// Adds the services menu.
        /// </summary>
        /// <param name="menuItems">The menu item collection to add this menu item to.</param>
        /// <param name="label">The label for the menu item.</param>
        /// <returns>The created menu item.</returns>
        public static MenuItem AddServicesMenu(this MenuItemCollection menuItems, string label = "Services")
        {
            var nativeMenu = new CocoaLabelMenuItem(label);
            var submenu    = nativeMenu.SetSubMenu("services");
            var menu       = new LabelMenuItem(nativeMenu);

            menuItems.Add(menu);

            ObjC.Call(MacApplication.Handle, "setServicesMenu:", submenu.Handle);

            return(menu);
        }
示例#2
0
        private static LabelMenuItem AddDefaultHandlerMenuItem(MenuItemCollection menuItems, string label, string command, long tag = 0)
        {
            if (menuItems == null)
            {
                throw new ArgumentNullException(nameof(menuItems));
            }
            if (label == null)
            {
                throw new ArgumentNullException(nameof(label));
            }

            // when setting target to null, cocoa will look for the first responder that can handle the action
            var nativeItem = new CocoaLabelMenuItem(label, command, null, 0);
            var item       = new LabelMenuItem(nativeItem);

            menuItems.Add(item);

            return(item);
        }