From b739e72f0fe1bdf149403c7de4278da13cf254b7 Mon Sep 17 00:00:00 2001 From: Mitchell Livingston Date: Thu, 10 Dec 2009 04:49:57 +0000 Subject: [PATCH] on second thought, there's no need to store the index at all - it's just the number of messages we have --- macosx/MessageWindowController.h | 1 - macosx/MessageWindowController.m | 11 ++++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/macosx/MessageWindowController.h b/macosx/MessageWindowController.h index 7c5288dbd..b46c0a1a1 100644 --- a/macosx/MessageWindowController.h +++ b/macosx/MessageWindowController.h @@ -32,7 +32,6 @@ IBOutlet NSButton * fSaveButton, * fClearButton; NSMutableArray * fMessages, * fDisplayedMessages; - NSUInteger fCurrentIndex; NSDictionary * fAttributes; diff --git a/macosx/MessageWindowController.m b/macosx/MessageWindowController.m index 3c09d22cf..2c0480a0f 100644 --- a/macosx/MessageWindowController.m +++ b/macosx/MessageWindowController.m @@ -155,8 +155,10 @@ [fLock lock]; + NSUInteger currentCount = [fMessages count]; + NSScroller * scroller = [[fMessageTable enclosingScrollView] verticalScroller]; - const BOOL shouldScroll = fCurrentIndex == 0 || [scroller floatValue] == 1.0 || [scroller isHidden] + const BOOL shouldScroll = currentCount == 0 || [scroller floatValue] == 1.0 || [scroller isHidden] || [scroller knobProportion] == 1.0; const NSInteger maxLevel = [[NSUserDefaults standardUserDefaults] integerForKey: @"MessageLevel"]; @@ -173,7 +175,7 @@ NSDictionary * message = [NSDictionary dictionaryWithObjectsAndKeys: [NSString stringWithUTF8String: currentMessage->message], @"Message", [NSDate dateWithTimeIntervalSince1970: currentMessage->when], @"Date", - [NSNumber numberWithUnsignedInteger: fCurrentIndex++], @"Index", //more accurate when sorting by date + [NSNumber numberWithUnsignedInteger: currentCount++], @"Index", //more accurate when sorting by date [NSNumber numberWithInteger: currentMessage->level], @"Level", name, @"Name", file, @"File", nil]; @@ -187,9 +189,9 @@ } } - if ([fMessages count] > TR_MAX_MSG_LOG) + if (currentCount > TR_MAX_MSG_LOG) { - NSIndexSet * removeIndexes = [NSIndexSet indexSetWithIndexesInRange: NSMakeRange(0, [fMessages count]-TR_MAX_MSG_LOG)]; + NSIndexSet * removeIndexes = [NSIndexSet indexSetWithIndexesInRange: NSMakeRange(0, currentCount-TR_MAX_MSG_LOG)]; NSArray * itemsToRemove = [fMessages objectsAtIndexes: removeIndexes]; [fMessages removeObjectsAtIndexes: removeIndexes]; @@ -359,7 +361,6 @@ [fMessages removeAllObjects]; [fDisplayedMessages removeAllObjects]; [fMessageTable reloadData]; - fCurrentIndex = 0; [fLock unlock]; }