summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--MLKListenerController.h1
-rw-r--r--MLKListenerController.m59
2 files changed, 47 insertions, 13 deletions
diff --git a/MLKListenerController.h b/MLKListenerController.h
index ce206ac..8c02541 100644
--- a/MLKListenerController.h
+++ b/MLKListenerController.h
@@ -37,6 +37,7 @@
- (void)writeString:(NSString *)string;
- (void)evalObject:(id)object;
+- (void)enableSubmitButton:(id)sender;
- (IBAction)submit:(id)sender;
@end
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