// // AppDelegate.m // LeanCalc // // Created by Marc Liyanage on 08.02.05. // Copyright 2005 __MyCompanyName__. All rights reserved. // #import "AppDelegate.h" @implementation AppDelegate - (id)init { self = [super init]; if (!self) return nil; [self initFunctionReference]; return self; } - (void)initFunctionReference { functionReference = [[NSMutableArray alloc] init]; NSString *helpBasedir = [NSString stringWithFormat:@"%@/help", [[NSBundle mainBundle] resourcePath]]; NSArray *helpFiles = [[NSFileManager defaultManager] directoryContentsAtPath:helpBasedir]; NSEnumerator *enumerator = [helpFiles objectEnumerator]; id filename; while (filename = [enumerator nextObject]) { NSString *fullPath = [NSString stringWithFormat:@"%@/%@", helpBasedir, filename]; NSString *fileContents = [NSString stringWithContentsOfFile:fullPath]; NSDictionary *newEntry = [NSDictionary dictionaryWithObjectsAndKeys:filename, @"name", fileContents, @"text", nil]; [functionReference addObject:newEntry]; } } - (NSArray *)completionsForPartialWord:(NSString *)partialWord { NSEnumerator *enumerator = [functionReference objectEnumerator]; NSMutableArray *completions = [NSMutableArray array]; id entry; while (entry = [enumerator nextObject]) { NSString *name = [NSString stringWithFormat:@"%@()", [entry valueForKey:@"name"]]; if ([name hasPrefix:partialWord]) { [completions addObject:name]; } } return completions; } - (void)dealloc { [functionReference release]; [super dealloc]; } @end