diff options
| author | Matthias Andreas Benkard <matthias@benkard.de> | 2008-08-28 19:50:33 +0200 | 
|---|---|---|
| committer | Matthias Andreas Benkard <matthias@benkard.de> | 2008-08-28 19:50:33 +0200 | 
| commit | 48dcf5a5efeb9efa5ca84a72919941df3347bf4b (patch) | |
| tree | 6a64b7a459b7c9e5ff251e5804a202e8f83f977e | |
| parent | fc882679e23e507e0f14afc05a2e4e27fbf96844 (diff) | |
Listener: Keep the output view on the bottom by scrolling.
| -rw-r--r-- | MLKListenerController.m | 38 | 
1 files changed, 38 insertions, 0 deletions
diff --git a/MLKListenerController.m b/MLKListenerController.m index fb9fb5c..680365f 100644 --- a/MLKListenerController.m +++ b/MLKListenerController.m @@ -45,6 +45,9 @@    id object;    NSDictionary *attrs;    NSString *input = [inputField stringValue]; +  float originalScrollPosition = [[[outputTextView enclosingScrollView] +                                    verticalScroller] +                                   floatValue];    [submitButton setEnabled:NO]; @@ -92,6 +95,12 @@    [statusText setStringValue:@"Compiling and executing."]; +  if (originalScrollPosition == 1.0) +    { +      NSRange range = NSMakeRange ([text length], 0); +      [outputTextView scrollRangeToVisible:range]; +    } +    [NSThread detachNewThreadSelector:@selector(evalObject:)                             toTarget:self                           withObject:nullify(object)]; @@ -104,6 +113,9 @@    NSMutableAttributedString *text = [outputTextView textStorage];    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];    BOOL waitp = NO; +   float originalScrollPosition = [[[outputTextView enclosingScrollView] +                                     verticalScroller] +                                    floatValue];    object = denullify(object); @@ -196,6 +208,13 @@          withObject:self          waitUntilDone:NO]; +  if (originalScrollPosition == 1.0) +    { +      [self performSelectorOnMainThread:@selector(scrollDown:) +            withObject:self +            waitUntilDone:NO]; +    } +    [pool release];  } @@ -211,6 +230,10 @@  - (void)writeString:(NSString *)string  { +  float originalScrollPosition = [[[outputTextView enclosingScrollView] +                                    verticalScroller] +                                   floatValue]; +    NSDictionary *attrs = [NSDictionary dictionaryWithObjectsAndKeys:                                          [NSColor brownColor],                                          NSForegroundColorAttributeName, @@ -222,5 +245,20 @@      performSelectorOnMainThread:@selector(appendAttributedString:)      withObject:output      waitUntilDone:YES]; + +  if (originalScrollPosition == 1.0) +    { +      [self performSelectorOnMainThread:@selector(scrollDown:) +            withObject:self +            waitUntilDone:NO]; +    } +} + +- (void)scrollDown:(id)sender +{ +  // FIXME: This is slow.  Investigate NSClipView#-scrollToPoint as a +  // possible alternative. +  NSRange range = NSMakeRange ([[outputTextView textStorage] length], 0); +  [outputTextView scrollRangeToVisible:range];  }  @end  | 
