summaryrefslogtreecommitdiff
path: root/MLKListenerController.m
diff options
context:
space:
mode:
authorMatthias Andreas Benkard <matthias@benkard.de>2008-08-28 19:24:12 +0200
committerMatthias Andreas Benkard <matthias@benkard.de>2008-08-28 19:24:12 +0200
commitfc882679e23e507e0f14afc05a2e4e27fbf96844 (patch)
tree60de6e7050fa0d2cb746bf3037eb5f5e35ec5d71 /MLKListenerController.m
parent8bae5884d857cb7c762f7859b68d36758c1200ac (diff)
Listener: Perform GUI manipulation on the main thread.
Diffstat (limited to 'MLKListenerController.m')
-rw-r--r--MLKListenerController.m59
1 files changed, 46 insertions, 13 deletions
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