focus expression text field at startup -> version 1.2
[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         functionReference = [[NSMutableArray alloc] init];
28
29         NSString *helpBasedir = [NSString stringWithFormat:@"%@/help", [[NSBundle mainBundle] resourcePath]];
30         NSArray *helpFiles = [[NSFileManager defaultManager] directoryContentsAtPath:helpBasedir];
31
32         NSEnumerator *enumerator = [helpFiles objectEnumerator];
33         id filename;
34         while (filename = [enumerator nextObject]) {
35                 NSString *fullPath = [NSString stringWithFormat:@"%@/%@", helpBasedir, filename];
36                 NSString *fileContents = [NSString stringWithContentsOfFile:fullPath];
37                 NSDictionary *newEntry = [NSDictionary dictionaryWithObjectsAndKeys:filename, @"name", fileContents, @"text", nil];
38                 [functionReference addObject:newEntry];
39         }
40         
41 }
42
43
44
45 - (NSArray *)completionsForPartialWord:(NSString *)partialWord {
46
47         NSEnumerator *enumerator = [functionReference objectEnumerator];
48         NSMutableArray *completions = [NSMutableArray array];
49
50         id entry;
51         while (entry = [enumerator nextObject]) {
52                 NSString *name = [NSString stringWithFormat:@"%@()", [entry valueForKey:@"name"]];
53                 if ([name hasPrefix:partialWord]) {
54                         [completions addObject:name];
55                 }
56         }
57         
58         return completions;
59
60 }
61
62
63
64 - (void)dealloc {
65
66         [functionReference release];
67         [super dealloc];
68         
69 }
70
71
72
73 @end