Exemplo n.º 1
0
        private static void AddToolbarItem(NSMutableDictionary theDict, NSString identifier, NSString label, NSString paletteLabel, NSString toolTip, Id target, IntPtr settingSelector, Id itemContent, IntPtr action, NSMenu menu)
        {
            NSMenuItem mItem;

            // here we create the NSToolbarItem and setup its attributes in line with the parameters
            NSToolbarItem item = new NSToolbarItem(identifier);
            item.Autorelease();
            item.Label = label;
            item.PaletteLabel = paletteLabel;
            item.ToolTip = toolTip;
            // the settingSelector parameter can either be @selector(setView:) or @selector(setImage:).  Pass in the right
            // one depending upon whether your NSToolbarItem will have a custom view or an image, respectively
            // (in the itemContent parameter).  Then this next line will do the right thing automatically.
            item.PerformSelectorWithObject(settingSelector, itemContent);
            item.Target = target;
            item.Action = action;
            // If this NSToolbarItem is supposed to have a menu "form representation" associated with it (for text-only mode),
            // we set it up here.  Actually, you have to hand an NSMenuItem (not a complete NSMenu) to the toolbar item,
            // so we create a dummy NSMenuItem that has our real menu as a submenu.
            if (menu != null)
            {
                // we actually need an NSMenuItem here, so we construct one
                mItem = new NSMenuItem();
                mItem.Autorelease();
                mItem.Submenu = menu;
                mItem.Title = menu.Title;
                item.MenuFormRepresentation = mItem;
            }

            // Now that we've setup all the settings for this new toolbar item, we add it to the dictionary.
            // The dictionary retains the toolbar item for us, which is why we could autorelease it when we created
            // it (above).
            theDict[identifier] = item;
        }