Changeset 1521

Show
Ignore:
Timestamp:
08/21/04 18:08:12 (4 years ago)
Author:
morris
Message:

move common NSString methods to additions

only scroll when we're at the bottom

don't append a \n

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • WiredClient/trunk/NSStringAdditions.h

    r1360 r1521  
    1 /* $Id: NSStringAdditions.h,v 1.9 2004/06/10 10:43:54 morris Exp $ */ 
     1/* $Id: NSStringAdditions.h,v 1.10 2004/08/21 16:08:12 morris Exp $ */ 
    22 
    33/* 
     
    3838- (unsigned int)                        UTF8StringLength; 
    3939 
     40- (NSString *)                          stringByReplacingOccurencesOfString:(NSString *)target withString:(NSString *)replacement; 
     41- (NSString *)                          stringByReplacingOccurencesOfStrings:(NSArray *)targets withString:(NSString *)replacement; 
     42 
    4043@end 
    4144 
  • WiredClient/trunk/NSStringAdditions.m

    r1360 r1521  
    1 /* $Id: NSStringAdditions.m,v 1.12 2004/06/10 10:43:54 morris Exp $ */ 
     1/* $Id: NSStringAdditions.m,v 1.13 2004/08/21 16:08:12 morris Exp $ */ 
    22 
    33/* 
     
    6565} 
    6666 
     67 
     68 
     69- (NSString *)stringByReplacingOccurencesOfString:(NSString *)target withString:(NSString *)replacement { 
     70        NSMutableString         *string; 
     71        NSRange                         range; 
     72         
     73        string = [NSMutableString stringWithString:self]; 
     74        range = NSMakeRange(0, [string length]); 
     75         
     76        [string replaceOccurrencesOfString:target withString:replacement options:0 range:range]; 
     77         
     78        return [NSString stringWithString:string]; 
     79} 
     80 
     81 
     82 
     83- (NSString *)stringByReplacingOccurencesOfStrings:(NSArray *)targets withString:(NSString *)replacement { 
     84        NSMutableString         *string; 
     85        NSEnumerator            *enumerator; 
     86        NSString                        *target; 
     87        NSRange                         range; 
     88 
     89        string = [NSMutableString stringWithString:self]; 
     90        range = NSMakeRange(0, [string length]); 
     91        enumerator = [targets objectEnumerator]; 
     92         
     93        while((target = [enumerator nextObject])) 
     94                [string replaceOccurrencesOfString:target withString:replacement options:0 range:range]; 
     95                 
     96        return [NSString stringWithString:string]; 
     97} 
     98 
    6799@end 
    68100 
  • WiredClient/trunk/WCConsole.h

    r1514 r1521  
    1 /* $Id: WCConsole.h,v 1.2 2004/08/21 11:43:33 morris Exp $ */ 
     1/* $Id: WCConsole.h,v 1.3 2004/08/21 16:08:12 morris Exp $ */ 
    22 
    33/* 
     
    3333@interface WCConsole : WCWindowController { 
    3434        IBOutlet NSTextView                     *_consoleTextView; 
     35        IBOutlet NSScrollView           *_consoleScrollView; 
    3536} 
    3637 
     
    3839- (id)                                                  initWithConnection:(WCConnection *)connection; 
    3940 
    40 - (NSString *)                                  stringByReplacingSeparators:(NSString *)string; 
    4141- (void)                                                logInput:(NSString *)string; 
    4242- (void)                                                logOutput:(NSString *)string; 
  • WiredClient/trunk/WCConsole.m

    r1514 r1521  
    1 /* $Id: WCConsole.m,v 1.9 2004/08/21 11:43:33 morris Exp $ */ 
     1/* $Id: WCConsole.m,v 1.10 2004/08/21 16:08:12 morris Exp $ */ 
    22 
    33/* 
     
    2727 */ 
    2828 
     29#import "NSStringAdditions.h" 
    2930#import "WCConnection.h" 
    3031#import "WCConsole.h" 
     
    124125#pragma mark - 
    125126 
    126 - (NSString *)stringByReplacingSeparators:(NSString *)string { 
    127         NSMutableString *mutableString; 
    128         NSRange                 range; 
     127- (void)logInput:(NSString *)string { 
     128        NSString        *input; 
    129129         
    130         range = NSMakeRange(0, [string length]); 
    131         mutableString = [string mutableCopy]; 
     130        input = [string stringByReplacingOccurencesOfStrings:[NSArray arrayWithObjects: 
     131                WCFieldSeparator, WCGroupSeparator, WCRecordSeparator, NULL] 
     132                                                                                           withString:@"\t"]; 
    132133 
    133         [mutableString replaceOccurrencesOfString:WCFieldSeparator withString:@"\t" options:0 range:range]; 
    134         [mutableString replaceOccurrencesOfString:WCGroupSeparator withString:@"\t" options:0 range:range]; 
    135         [mutableString replaceOccurrencesOfString:WCRecordSeparator withString:@"\t" options:0 range:range]; 
    136         [mutableString appendString:@"\n"]; 
    137          
    138         return [mutableString autorelease]; 
    139 
    140  
    141  
    142  
    143 - (void)logInput:(NSString *)string { 
    144         [self log:[self stringByReplacingSeparators:string] color:[NSColor blueColor]]; 
     134        [self log:input color:[NSColor blueColor]]; 
    145135} 
    146136 
     
    148138 
    149139- (void)logOutput:(NSString *)string { 
    150         [self log:[self stringByReplacingSeparators:string] color:[NSColor blackColor]]; 
     140        NSString        *output; 
     141         
     142        output = [string stringByReplacingOccurencesOfStrings:[NSArray arrayWithObjects: 
     143                WCFieldSeparator, WCGroupSeparator, WCRecordSeparator, NULL] 
     144                                                                                           withString:@"\t"]; 
     145 
     146        [self log:output color:[NSColor blackColor]]; 
    151147} 
    152148 
     
    165161 
    166162        // --- print 
     163        if([[_consoleTextView textStorage] length] > 0) 
     164                [[[_consoleTextView textStorage] mutableString] appendString:@"\n"]; 
     165                 
    167166        [[_consoleTextView textStorage] appendAttributedString:attributedString]; 
    168167         
    169168        // --- scroll with it 
    170         [_consoleTextView scrollRangeToVisible:NSMakeRange([[_consoleTextView textStorage] length], 0)]; 
     169        if([[_consoleScrollView verticalScroller] floatValue] == 1.0) { 
     170                [_consoleTextView scrollRangeToVisible: 
     171                        NSMakeRange([[_consoleTextView textStorage] length], 0)]; 
     172    } 
    171173         
    172174        // --- release