#import "AppController.h" @implementation DuncanDataRepresentation - (NSArray*) wordList { return wordList; } - (void) stemming { } - (id) initWithTarget:(id)t keyword:(NSString *)str { self = [super init]; keywords = [[NSMutableArray arrayWithObject:str] retain]; target = t; wordList = [[NSMutableArray alloc] init]; [self stemming]; return self; } - (void) release { [keywords release]; [wordList release]; return [super release]; } - (void) flush { [target receiveData:self]; } - (void) appendListFromArray:(NSArray *)newentries { [wordList addObjectsFromArray:newentries]; } - (NSString *)keyword { return [keywords objectAtIndex:0]; } - (NSArray *)keywords { return keywords; } - (void) log:(id)stringx { NSLog(@"by %@", stringx); NSLog(@"keyword : %@",[self keyword]); NSEnumerator *enumerator = [wordList objectEnumerator]; id anObject; int i = 0; while (anObject = [enumerator nextObject]) { i++; NSLog(@"%d) %@:%@",i,[anObject path],[anObject definition]); } } @end @implementation AppController /* - (void)registerThread { NSLog(@"registerThread"); threadCount ++; if (threadCount == 1) [progressBar startAnimation:self]; } */ /* - (void)resignThread { NSLog(@"resignThread"); threadCount --; if (threadCount == 0) [progressBar stopAnimation:self]; NSString *oldpath = [wordList path]; [oldpath retain]; [wordList validateVisibleColumns]; [wordList loadColumnZero]; [wordList setPath:@"/"]; [wordList setPath:oldpath]; [oldpath release]; } */ - (void)applicationDidFinishLaunching:(NSNotification *)notif { NSLog(@"launching %@",[[[NSString alloc] init] stem]); threadCount = 0; id zzz = [NSObject new]; //duncan = [[Duncan alloc] initWithTarget:self]; duncan = [[Duncan alloc] init]; // progressBar = [[NSProgressIndicator alloc] initWithFrame:NSMakeRect(12,18,14,14)]; // [progressBar setStyle:NSProgressIndicatorSpinningStyle]; // [[mainWindow contentView] addSubview:progressBar]; [wordList validateVisibleColumns]; // Gorm isn't cooperating [wordList setTarget: self]; [wordList setAction: @selector(browserChoose:)]; } - (void)controlTextDidChange:(NSNotification *)aNotification { NSLog(@"change %@",[wordField stringValue]); [[wordField cell]setSendsActionOnEndEditing:NO]; } - (void)controlTextDidEndEditing:(NSNotification *)aNotification { NSLog(@"control did end"); } // TextView Controller - (void)cleanTextView // Simply replace the empty view with GPL { // NSTextStorage *textstorage = [displayView textStorage]; // [textstorage setAttributedString:str]; } - (void)setTextViewTo:(NSAttributedString *)str { NSTextStorage *textstorage = [displayView textStorage]; [textstorage setAttributedString:str]; } // Bookmark Button - (IBAction)bookmark:(id)sender { //[bookmarkMan bookmark:[wordField stringValue]]; } - (IBAction)back:(id)sender { } - (IBAction)forward:(id)sender { } // TextField Controller - (id)addToList:(NSString *)aWord { [currentWords addObject:aWord]; } - (void) receiveData:(id)_data { // dont forget to make a thread connector here. if ([[_data keyword] isEqualToString:[wordField stringValue]]) { NSLog(@"match!"); [_data log:@"receiveData:"]; NSMutableAttributedString *fullpresentation = [NSMutableAttributedString new]; NSEnumerator *enumerator = [[_data wordList] objectEnumerator]; id word; int i = 0; [fullpresentation appendAttributedString: [[NSAttributedString alloc] initWithString: [NSString stringWithFormat:@"Definition for %@:\n\n",[_data keyword]] ]]; while (word = [enumerator nextObject]) { i++; [fullpresentation appendAttributedString: [[NSAttributedString alloc] initWithString: [NSString stringWithFormat:@"%d) %@ (%@)\n %@\n\n",i,[word string],[[word path] substringFromIndex:7],[word definition]] ]]; [wordList setPath:[[word path] substringFromIndex:7]]; } if (i == 0) { [fullpresentation appendAttributedString: [[NSAttributedString alloc] initWithString: [NSString stringWithFormat:@"No definition for %@.\n\n",[_data keyword]] ]]; } [self setTextViewTo:fullpresentation]; } else { NSLog(@"probably expired!"); [_data log:@"expired receiveData:"]; } } - (void) displayCurrentWords { if ([currentWords count] == 0) { //display the GPL rtf, nah Fuck the GPL!!! } } - (IBAction)wordFieldEnd:(id)sender { if( [[wordField stringValue] length] > 0 ){ // forming a DuncanDataRepresentation id aDataRep = [[DuncanDataRepresentation alloc] initWithTarget:self keyword:[wordField stringValue]]; // pass it to Duncan by query: [duncan query:aDataRep]; } } /* -----delegate---- */ // Browser Controller - (IBAction)browserChoose:(id)sender { int i = 0; WordContainer *object = duncan; int column = [sender selectedColumn]; while (i <= column) { object = [object wordAtIndex:[sender selectedRowInColumn:i]]; i++; } if (![object isKindOfClass:[WordContainer class]]) [wordField setStringValue:[object string]]; [self setTextViewTo:[object presentation]]; } - (int)browser:(NSBrowser *)sender numberOfRowsInColumn:(int)column { NSLog(@"access %d %d",column,[NSThread currentThread]); int i = 0; WordContainer *object = duncan; while (i < column) { object = [object wordAtIndex:[sender selectedRowInColumn:i]]; i++; } return [object count]; } - (void)browser:(NSBrowser *)sender willDisplayCell:(id)cell atRow:(int)row column:(int)column { int i = 0; WordContainer *object = duncan; while (i < column) { object = [object wordAtIndex:[sender selectedRowInColumn:i]]; i++; } object = [object wordAtIndex:row]; if ([object isMemberOfClass:[Word class]]) { [cell setLeaf:YES]; [cell setStringValue:[object string]]; } else { [cell setLeaf:NO]; [cell setStringValue:[object string]]; // [cell setStringValue:[NSString stringWithFormat:@"%@ (%@)",[object string],[object counter]]]; } } - (BOOL)browser:(NSBrowser *)sender selectRow:(int)row inColumn:(int)column { NSLog(@"asking"); return YES; } - (BOOL)browser:(NSBrowser *)sender isColumnValid:(int)column { NSLog(@"asking"); return NO; } // Window Controller - (BOOL)windowShouldClose:(id)sender { NSLog(@"Window Should Close"); [duncan setTarget:nil]; [duncan release]; [NSApp terminate:self]; return YES; } @end