Button

From Unify Community Wiki
Revision as of 01:44, 1 December 2005 by Outcast (Talk | contribs)

Jump to: navigation, search

Obsessively create a hierarchical menu from a directory listing:

<c> - (void)addItemsFromPath:(NSString*)path toMenu:(NSMenu*)menu { NSArray *puzzles; NSString *puzz; NSMenuItem *item; BOOL dir; int i;

puzzles = [[NSFileManager defaultManager] directoryContentsAtPath:[puzzlePath stringByAppendingString:path]]; for(i = 0; i < [puzzles count]; i++) { puzz = [puzzles objectAtIndex:i]; if([[puzz substringFromIndex:[puzz length]-4] isEqualToString:@".tsu"]) { boardData = [NSString stringWithContentsOfFile:[puzzlePath stringByAppendingString:[path stringByAppendingString:puzz]]]; [self getBoardSize]; item = [[[NSMenuItem alloc] initWithTitle:[NSString stringWithFormat:@"%@ (%d, %d)", puzz, boardwidth, boardheight] action:@selector(loadLevelFromMenu:) keyEquivalent:@""] autorelease]; [item setTarget:self]; [item setRepresentedObject:[[path stringByAppendingString:@"/"] stringByAppendingString:puzz]]; [menu addItem:item]; } else { [[NSFileManager defaultManager] fileExistsAtPath:[[puzzlePath stringByAppendingString:path] stringByAppendingString:puzz] isDirectory:&dir]; if(dir) { NSMenu *submenu = [[NSMenu alloc] initWithTitle:@""]; item = [[[NSMenuItem alloc] initWithTitle:puzz action:NULL keyEquivalent:@""] autorelease]; [self addItemsFromPath:[[path stringByAppendingString:puzz] stringByAppendingString:@"/"] toMenu:submenu]; [item setSubmenu:submenu]; [menu addItem:item]; } } } } </c>

Personal tools
Namespaces

Variants
Actions
Navigation
Extras
Toolbox