diff --git a/ChangeLog b/ChangeLog index 43d65afb4..8ea1bc069 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +1999-07-12 Michael Hanni + + * Source/NSMenu.m: added code to convert anything that conforms to + into an NSMenuItemCell. Not tested, but should work. + Also fixed a small bug in -init, it was not returning. + Mon Jul 12 5:40:00 1999 Richard Frith-Macdonald * Source/NSOpenPanel.m: In ([-runModalForTypes:]) made change diff --git a/Source/NSMenu.m b/Source/NSMenu.m index e4e2a2424..7ef67dc31 100644 --- a/Source/NSMenu.m +++ b/Source/NSMenu.m @@ -61,7 +61,7 @@ static NSZone *menuZone = NULL; - (id)init { - [self initWithTitle:@"Menu"]; + return [self initWithTitle:@"Menu"]; } - (id)initWithTitle:(NSString *)aTitle @@ -89,13 +89,37 @@ static NSZone *menuZone = NULL; return self; } +/* + * - (void)insertItem:(id )newItem + * atIndex:(int)index + * + * This method has been modified to convert anything that conforms to the + * Protocol into a NSMenuItemCell which will be added to the + * items array. + * + * Blame: Michael + */ + - (void)insertItem:(id )newItem atIndex:(int)index { - if ([(NSMenuItemCell *)newItem isKindOfClass:[NSMenuItemCell class]]) - [menu_items insertObject:newItem atIndex:index]; + if ([newItem conformsToProtocol:@protocol(NSMenuItem)]) + { + if ([newItem isKindOfClass:[NSMenuItemCell class]]) + [menu_items insertObject:newItem atIndex:index]; + else + { + [self insertItemWithTitle:[newItem title] + action:[newItem action] + keyEquivalent:[newItem keyEquivalent] + atIndex:index]; + [(NSMenuItem *)newItem release]; + } + } else - NSLog(@"You must use an NSMenuItemCell, or a derivative thereof.\n"); + NSLog(@"You must use an object that conforms to NSMenuItem.\n"); + + menu_changed = YES; } - (id )insertItemWithTitle:(NSString *)aString @@ -117,13 +141,7 @@ static NSZone *menuZone = NULL; - (void)addItem:(id )newItem { - // The spec says we call [self insertItem]; but why waste the overhead? - if ([(NSMenuItemCell *)newItem isKindOfClass:[NSMenuItemCell class]]) - [menu_items insertObject:newItem atIndex:[menu_items count]]; - else - NSLog(@"You must use an NSMenuItemCell, or a derivative thereof.\n"); - - menu_changed = YES; + [self insertItem:newItem atIndex:[menu_items count]]; } - (id )addItemWithTitle:(NSString *)aString