示例#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;
        }
示例#2
0
        public NSToolbarItem ToolbarItemForItemIdentifierWillBeInsertedIntoToolbar(NSToolbar toolbar, NSString itemIdentifier, bool flag)
        {
            // We create and autorelease a new NSToolbarItem, and then go through the process of setting up its
            // attributes from the master toolbar item matching that identifier in our dictionary of items.
            NSToolbarItem newItem = new NSToolbarItem(itemIdentifier);
            newItem.Autorelease();
            NSToolbarItem item = this.toolbarItems[itemIdentifier].CastTo<NSToolbarItem>();

            newItem.Label = item.Label;
            newItem.PaletteLabel = item.PaletteLabel;
            if (item.View != null)
            {
                newItem.View = item.View;
            }
            else
            {
                newItem.Image = item.Image;
            }
            newItem.ToolTip = item.ToolTip;
            newItem.Target = item.Target;
            newItem.Action = item.Action;
            newItem.MenuFormRepresentation = item.MenuFormRepresentation;
            // If we have a custom view, we *have* to set the min/max size - otherwise, it'll default to 0,0 and the custom
            // view won't show up at all!  This doesn't affect toolbar items with images, however.
            if (newItem.View != null)
            {
                newItem.MinSize = item.View.Bounds.size;
                newItem.MaxSize = item.View.Bounds.size;
            }

            return newItem;
        }