From fc882679e23e507e0f14afc05a2e4e27fbf96844 Mon Sep 17 00:00:00 2001 From: Matthias Andreas Benkard Date: Thu, 28 Aug 2008 19:24:12 +0200 Subject: Listener: Perform GUI manipulation on the main thread. --- MLKListenerController.m | 59 ++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 46 insertions(+), 13 deletions(-) (limited to 'MLKListenerController.m') diff --git a/MLKListenerController.m b/MLKListenerController.m index ef46ff8..fb9fb5c 100644 --- a/MLKListenerController.m +++ b/MLKListenerController.m @@ -90,6 +90,8 @@ [[text mutableString] appendString:@"\n"]; [text endEditing]; + [statusText setStringValue:@"Compiling and executing."]; + [NSThread detachNewThreadSelector:@selector(evalObject:) toTarget:self withObject:nullify(object)]; @@ -101,10 +103,10 @@ NSDictionary *attrs; NSMutableAttributedString *text = [outputTextView textStorage]; NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; - + BOOL waitp = NO; + object = denullify(object); - [statusText setStringValue:@"Compiling and executing."]; NS_DURING { int i; @@ -130,18 +132,27 @@ inLexicalContext:[MLKLexicalContext globalContext] withEnvironment:[MLKLexicalEnvironment globalEnvironment]]; + [text performSelectorOnMainThread:@selector(beginEditing) + withObject:nil + waitUntilDone:waitp]; + for (i = 0; i < [results count]; i++) { id result = denullify ([results objectAtIndex:i]); - [text beginEditing]; + //[text beginEditing]; attrs = [NSDictionary dictionaryWithObjectsAndKeys: [NSColor purpleColor], NSForegroundColorAttributeName, nil]; NSAttributedString *response = LAUTORELEASE ([[NSAttributedString alloc] initWithString:MLKPrintToString(result) attributes:attrs]); - [text appendAttributedString:response]; - [[text mutableString] appendString:@"\n"]; + [text performSelectorOnMainThread:@selector(appendAttributedString:) + withObject:response + waitUntilDone:waitp]; + [[text mutableString] + performSelectorOnMainThread:@selector(appendString:) + withObject:@"\n" + waitUntilDone:waitp]; } } NS_HANDLER @@ -151,29 +162,48 @@ [[localException name] UTF8String], [[localException reason] UTF8String]]; - [text beginEditing]; + [text performSelectorOnMainThread:@selector(beginEditing) + withObject:nil + waitUntilDone:waitp]; + attrs = [NSDictionary dictionaryWithObjectsAndKeys: [NSColor redColor], NSForegroundColorAttributeName, nil]; NSAttributedString *response = LAUTORELEASE ([[NSAttributedString alloc] initWithString:bare_msg attributes:attrs]); - [text appendAttributedString:response]; + [text performSelectorOnMainThread:@selector(appendAttributedString:) + withObject:response + waitUntilDone:waitp]; } NS_ENDHANDLER; [MLKDynamicContext popContext]; LDESTROY (newctx); - [statusText setStringValue:@"Ready."]; + [statusText performSelectorOnMainThread:@selector(setStringValue:) + withObject:@"Ready." + waitUntilDone:waitp]; - [[text mutableString] appendString:@"\n"]; + [[text mutableString] + performSelectorOnMainThread:@selector(appendString:) + withObject:@"\n" + waitUntilDone:waitp]; - [text endEditing]; + [text performSelectorOnMainThread:@selector(endEditing) + withObject:nil + waitUntilDone:waitp]; + + [self performSelectorOnMainThread:@selector(enableSubmitButton:) + withObject:self + waitUntilDone:NO]; - [submitButton setEnabled:YES]; - [pool release]; } +- (void)enableSubmitButton:(id)sender +{ + [submitButton setEnabled:YES]; +} + - (void)writeChar:(unichar)ch { [self writeString:[NSString stringWithFormat:@"%C", ch]]; @@ -188,6 +218,9 @@ NSAttributedString *output = LAUTORELEASE ([[NSAttributedString alloc] initWithString:string attributes:attrs]); - [[outputTextView textStorage] appendAttributedString:output]; + [[outputTextView textStorage] + performSelectorOnMainThread:@selector(appendAttributedString:) + withObject:output + waitUntilDone:YES]; } @end -- cgit v1.2.3