Changeset 829


Ignore:
Timestamp:
Aug 24, 2006, 1:55:09 AM (17 years ago)
Author:
livings124
Message:

Limit message log to 1000 lines.

Location:
trunk/macosx
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/macosx/MessageWindowController.h

    r828 r829  
    3434    NSTimer * fTimer;
    3535    NSDictionary * fAttributes;
     36   
     37    int fLines;
    3638}
    3739
  • trunk/macosx/MessageWindowController.m

    r828 r829  
    3030#define LEVEL_DEBUG 2
    3131
    32 #define UPDATE_SECONDS 0.35
     32#define UPDATE_SECONDS  0.35
     33#define MAX_LINES       1000
    3334
    3435@implementation MessageWindowController
     
    3839    if ((self = [super initWithWindowNibName: name]))
    3940    {
    40         fTimer = [NSTimer scheduledTimerWithTimeInterval: UPDATE_SECONDS target: self
    41                     selector: @selector(updateLog:) userInfo: nil repeats: YES];
    42        
    4341        NSMutableParagraphStyle * paragraph = [[NSMutableParagraphStyle defaultParagraphStyle] mutableCopy];
    4442        [paragraph setHeadIndent: 20.0];
     
    4846                        paragraph, NSParagraphStyleAttributeName, nil];
    4947        [paragraph release];
     48       
     49        fLines = 0;
     50       
     51        fTimer = [NSTimer scheduledTimerWithTimeInterval: UPDATE_SECONDS target: self
     52                    selector: @selector(updateLog:) userInfo: nil repeats: YES];
    5053       
    5154        [[self window] update]; //make sure nib is loaded right away
     
    9295    BOOL shouldScroll = [scroller floatValue] == 1.0 || [scroller isHidden] || [scroller knobProportion] == 1.0;
    9396   
    94     NSAttributedString * messageString;
    95     NSString * levelString, * dateString;
     97    NSString * levelString, * dateString, * messageString;
    9698    for (currentMessage = messages; currentMessage != NULL; currentMessage = currentMessage->next)
    9799    {
    98         //new line if text view is not empty
    99         if (currentMessage != messages || ![[fTextView string] isEqualToString: @""])
    100             [[fTextView textStorage] appendAttributedString: [[[NSAttributedString alloc]
    101                                         initWithString: @"\n" attributes: fAttributes] autorelease]];
    102        
    103100        int level = currentMessage->level;
    104101        if (level == TR_MSG_ERR)
     
    113110        dateString = [[NSDate dateWithTimeIntervalSince1970: currentMessage->when]
    114111                            descriptionWithCalendarFormat: @"%1m/%d %H:%M:%S" timeZone: nil locale: nil];
    115         messageString = [[[NSAttributedString alloc] initWithString: [NSString stringWithFormat: @"%@ %@ %s",
    116                             dateString, levelString, currentMessage->message] attributes: fAttributes] autorelease];
     112        messageString = [NSString stringWithFormat: @"%s%@ %@ %s",
     113                            fLines > 0 ? "\n" : "", dateString, levelString, currentMessage->message];
    117114       
    118         [[fTextView textStorage] appendAttributedString: messageString];
     115        //remove the first line if at max number of lines
     116        if (fLines == MAX_LINES)
     117        {
     118            NSString * text = [fTextView string];
     119            unsigned int loc = [text rangeOfString: @"\n"].location;
     120            if (loc != NSNotFound)
     121                [fTextView setString: [[text substringFromIndex: loc + 1] stringByAppendingString: messageString]];
     122        }
     123        else
     124        {
     125            [[fTextView textStorage] appendAttributedString: [[[NSAttributedString alloc] initWithString:
     126                                        messageString attributes: fAttributes] autorelease]];
     127            fLines++;
     128        }
    119129    }
    120130   
     
    144154{
    145155    [fTextView setString: @""];
     156    fLines = 0;
    146157}
    147158
Note: See TracChangeset for help on using the changeset viewer.