// // DSMenuCategories.m // Shared categories // // Created by David Sinclair on Thu Oct 09 2003. // Copyright (c) 2003 - 2007 Dejal Systems, LLC. All rights reserved. // // Redistribution and use in source and binary forms, with or without modification, // are permitted provided that the following conditions are met: // // Redistributions of source code must retain this list of conditions and the following disclaimer. // // The name of Dejal Systems, LLC may not be used to endorse or promote products derived from this // software without specific prior written permission. // // THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, // INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR // PURPOSE AND NONINFRINGEMENT OF THIRD PARTY RIGHTS. IN NO EVENT SHALL THE AUTHORS OR // COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN // ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE // SOFTWARE OR THE USE OR OTHER DEALINGS IN THIS SOFTWARE. // #import "DSMenuCategories.h" @implementation NSMenu (DSMenuCategories) /* addSeparatorItem Adds a separator item to the menu. Written by DJS 2006-10. */ - (void)addSeparatorItem; { [self addItem:[NSMenuItem separatorItem]]; } /* addItemWithTitle:target:action:keyEquivalent: Similar to -addItemWithTitle:action:keyEquivalent:, but allows specifying a target object as well. The key equivalent should be @"" if not required, not nil, though nil is also accepted by these categories. Written by DJS 2003-10. */ - (id )addItemWithTitle:(NSString *)aString target:(id)target action:(SEL)aSelector keyEquivalent:(NSString *)keyEquiv { return [self addItemWithTitle:aString target:target action:aSelector keyEquivalent:keyEquiv icon:nil]; } /* addItemWithTitle:target:action:keyEquivalent:icon: Similar to -addItemWithTitle:target:action:keyEquivalent:, but allows specifying an icon image as well. The key equivalent should be @"" if not required, not nil, though nil is also accepted by these categories. Written by DJS 2004-01. */ - (id )addItemWithTitle:(NSString *)aString target:(id)target action:(SEL)aSelector keyEquivalent:(NSString *)keyEquiv icon:(NSImage *)icon { return [self addItemWithTitle:aString target:target action:aSelector keyEquivalent:keyEquiv icon:icon representedObject:nil]; } /* addItemWithTitle:target:action:keyEquivalent:icon:representedObject: Similar to -addItemWithTitle:target:action:keyEquivalent:icon:, but allows specifying a represented object as well. The key equivalent should be @"" if not required, not nil, though nil is also accepted by these categories. Written by DJS 2004-01. */ - (id )addItemWithTitle:(NSString *)aString target:(id)target action:(SEL)aSelector keyEquivalent:(NSString *)keyEquiv icon:(NSImage *)icon representedObject:(id)object { return [self addItemWithTitle:aString target:target action:aSelector keyEquivalent:keyEquiv modifierMask:0 icon:icon representedObject:object]; } /* addItemWithTitle:target:action:keyEquivalent:modifierMask:icon:representedObject: Similar to -addItemWithTitle:target:action:keyEquivalent:icon:representedObject:, but allows specifying a modifier mask as well; if zero, the mask is not changed. The key equivalent should be @"" if not required, not nil, though nil is also accepted by these categories. Written by DJS 2004-01. Changed by DJS 2004-04 to add modifierMask. */ - (id )addItemWithTitle:(NSString *)aString target:(id)target action:(SEL)aSelector keyEquivalent:(NSString *)keyEquiv modifierMask:(unsigned int)modifierMask icon:(NSImage *)icon representedObject:(id)object { if (!keyEquiv) keyEquiv = @""; NSMenuItem *item = [[[NSMenuItem alloc] initWithTitle:aString action:aSelector keyEquivalent:keyEquiv] autorelease]; if (modifierMask) [item setKeyEquivalentModifierMask:modifierMask]; [item setTarget:target]; [item setImage:icon]; [item setRepresentedObject:object]; [self addItem:item]; return item; } /* removeAllItems Removes all items from the receiver. Written by DJS 2004-03. */ - (void)removeAllItems { while ([self numberOfItems]) [self removeItemAtIndex:0]; } @end