Re: NSImage allocation issues
Re: NSImage allocation issues
- Subject: Re: NSImage allocation issues
- From: Jesus De Meyer <email@hidden>
- Date: Fri, 30 Apr 2004 15:45:47 +0200
Well, I do release the menu item. Here's the full method for building
the files menu. Perhaps the bug is very obvious but I just can't see
it.
Thanks for the help though:
- (void)buildFilesMenu:(NSMenu*)menu fromArray:(NSArray*)items
withPath:(NSString*)path {
NSEnumerator *theEnumerator = [items objectEnumerator];
NSMenu *subMenu;
NSString *theItem;
while (theItem = [theEnumerator nextObject]) {
NSString *itemPath;
NSString *itemType;
itemPath = [NSString stringWithFormat:@"%@/%@", path, theItem];
itemType = [[fileManager fileAttributesAtPath:itemPath
traverseLink:NO] objectForKey:NSFileType];
BOOL isExe = [self fileIsApp:itemPath];
if ([itemType isEqualTo:NSFileTypeDirectory]) {
if (!isExe) {
subMenu = [[NSMenu alloc] init];
NSMenuItem *mi = [[NSMenuItem alloc] initWithTitle:theItem
action:nil keyEquivalent:@""];
NSImage *icon = [[NSWorkspace sharedWorkspace]
iconForFile:itemPath];
if ([[[NSUserDefaults standardUserDefaults]
objectForKey:@"showIcons"] intValue] && icon) {
[icon setSize:NSMakeSize(16, 16)];
[mi setImage:icon];
}
[menu addItem:mi];
if (wasExecutable) {
wasExecutable = NO;
[self buildFilesMenu:subMenu fromArray:[fileManager
directoryContentsAtPath:itemPath] withPath:path];
} else {
[self buildFilesMenu:subMenu fromArray:[fileManager
directoryContentsAtPath:itemPath] withPath:itemPath];
}
[menu setSubmenu:subMenu forItem:mi];
[mi release];
[subMenu release];
}
}
if (![itemType isEqualTo:NSFileTypeDirectory] || isExe) {
NSString *displayName;
displayName = [[fileManager displayNameAtPath:itemPath]
copy];
if (isExe)
wasExecutable = YES;
if ([self fileVisible:itemPath] && ![displayName
hasPrefix:@"Icon"]) {
NSMenuItem *mi = [[NSMenuItem alloc]
initWithTitle:displayName action:@selector(selectItem:)
keyEquivalent:@""];
[mi setTarget:self];
[mi setTag:[filesArray count]];
[filesArray addObject:itemPath];
NSImage *icon = [[NSWorkspace sharedWorkspace]
iconForFile:itemPath];
if ([[[NSUserDefaults standardUserDefaults]
objectForKey:@"showIcons"] intValue] && icon) {
[icon setSize:NSMakeSize(16, 16)];
[mi setImage:icon];
}
[menu addItem:mi];
[mi release];
}
}
}
}
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.