Initial revision
[LeanCalc.git] / Sources / AppDelegate.m
1 //
2 //  AppDelegate.m
3 //  LeanCalc
4 //
5 //  Created by Marc Liyanage on 08.02.05.
6 //  Copyright 2005 __MyCompanyName__. All rights reserved.
7 //
8
9 #import "AppDelegate.h"
10
11 @implementation AppDelegate
12
13 - (id)init {
14         
15         self = [super init];
16         if (!self) return nil;
17         
18         [self initFunctionReference];
19         
20         return self;
21         
22 }
23
24
25 - (void)initFunctionReference {
26
27
28         NSLog(@"start");
29         functionReference = [[NSMutableArray alloc] init];
30
31         NSString *helpBasedir = [NSString stringWithFormat:@"%@/help", [[NSBundle mainBundle] resourcePath]];
32         NSArray *helpFiles = [[NSFileManager defaultManager] directoryContentsAtPath:helpBasedir];
33
34         NSEnumerator *enumerator = [helpFiles objectEnumerator];
35         id filename;
36         while (filename = [enumerator nextObject]) {
37                 NSString *fullPath = [NSString stringWithFormat:@"%@/%@", helpBasedir, filename];
38                 NSString *fileContents = [NSString stringWithContentsOfFile:fullPath];
39                 NSDictionary *newEntry = [NSDictionary dictionaryWithObjectsAndKeys:filename, @"name", fileContents, @"text", nil];
40                 [functionReference addObject:newEntry];
41         }
42         NSLog(@"stop");
43         
44 }
45
46
47
48 - (NSArray *)completionsForPartialWord:(NSString *)partialWord {
49
50         NSEnumerator *enumerator = [functionReference objectEnumerator];
51         NSMutableArray *completions = [NSMutableArray array];
52
53         id entry;
54         while (entry = [enumerator nextObject]) {
55                 NSString *name = [NSString stringWithFormat:@"%@()", [entry valueForKey:@"name"]];
56                 if ([name hasPrefix:partialWord]) {
57                         [completions addObject:name];
58                 }
59         }
60         
61         return completions;
62
63 }
64
65
66
67 - (void)dealloc {
68
69         [functionReference release];
70         
71 }
72
73
74
75 @end