mirror of
https://github.com/transmission/transmission
synced 2024-12-25 09:13:06 +00:00
#4375 Lion: animate filtering message window
This commit is contained in:
parent
4fde6035fd
commit
73b5bfbf5d
1 changed files with 108 additions and 52 deletions
|
@ -24,6 +24,7 @@
|
||||||
|
|
||||||
#import "MessageWindowController.h"
|
#import "MessageWindowController.h"
|
||||||
#import "NSApplicationAdditions.h"
|
#import "NSApplicationAdditions.h"
|
||||||
|
#import "NSMutableArrayAdditions.h"
|
||||||
#import "NSStringAdditions.h"
|
#import "NSStringAdditions.h"
|
||||||
#import <transmission.h>
|
#import <transmission.h>
|
||||||
#import <utils.h>
|
#import <utils.h>
|
||||||
|
@ -38,6 +39,7 @@
|
||||||
|
|
||||||
- (void) resizeColumn;
|
- (void) resizeColumn;
|
||||||
- (BOOL) shouldIncludeMessageForFilter: (NSString *) filterString message: (NSDictionary *) message;
|
- (BOOL) shouldIncludeMessageForFilter: (NSString *) filterString message: (NSDictionary *) message;
|
||||||
|
- (void) updateListForFilter;
|
||||||
- (NSString *) stringForMessage: (NSDictionary *) message;
|
- (NSString *) stringForMessage: (NSDictionary *) message;
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
@ -49,21 +51,6 @@
|
||||||
return [super initWithWindowNibName: @"MessageWindow"];
|
return [super initWithWindowNibName: @"MessageWindow"];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void) dealloc
|
|
||||||
{
|
|
||||||
[[NSNotificationCenter defaultCenter] removeObserver: self];
|
|
||||||
|
|
||||||
[fTimer invalidate];
|
|
||||||
[fLock release];
|
|
||||||
|
|
||||||
[fMessages release];
|
|
||||||
[fDisplayedMessages release];
|
|
||||||
|
|
||||||
[fAttributes release];
|
|
||||||
|
|
||||||
[super dealloc];
|
|
||||||
}
|
|
||||||
|
|
||||||
- (void) awakeFromNib
|
- (void) awakeFromNib
|
||||||
{
|
{
|
||||||
NSWindow * window = [self window];
|
NSWindow * window = [self window];
|
||||||
|
@ -143,6 +130,21 @@
|
||||||
fLock = [[NSLock alloc] init];
|
fLock = [[NSLock alloc] init];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (void) dealloc
|
||||||
|
{
|
||||||
|
[[NSNotificationCenter defaultCenter] removeObserver: self];
|
||||||
|
|
||||||
|
[fTimer invalidate];
|
||||||
|
[fLock release];
|
||||||
|
|
||||||
|
[fMessages release];
|
||||||
|
[fDisplayedMessages release];
|
||||||
|
|
||||||
|
[fAttributes release];
|
||||||
|
|
||||||
|
[super dealloc];
|
||||||
|
}
|
||||||
|
|
||||||
- (void) windowDidBecomeKey: (NSNotification *) notification
|
- (void) windowDidBecomeKey: (NSNotification *) notification
|
||||||
{
|
{
|
||||||
if (!fTimer)
|
if (!fTimer)
|
||||||
|
@ -341,27 +343,11 @@
|
||||||
if ([[NSUserDefaults standardUserDefaults] integerForKey: @"MessageLevel"] == level)
|
if ([[NSUserDefaults standardUserDefaults] integerForKey: @"MessageLevel"] == level)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
[fLock lock];
|
|
||||||
|
|
||||||
[[NSUserDefaults standardUserDefaults] setInteger: level forKey: @"MessageLevel"];
|
[[NSUserDefaults standardUserDefaults] setInteger: level forKey: @"MessageLevel"];
|
||||||
|
|
||||||
NSString * filterString = [fFilterField stringValue];
|
[fLock lock];
|
||||||
|
|
||||||
[fDisplayedMessages removeAllObjects];
|
[self updateListForFilter];
|
||||||
for (NSDictionary * message in fMessages)
|
|
||||||
if ([[message objectForKey: @"Level"] integerValue] <= level
|
|
||||||
&& [self shouldIncludeMessageForFilter: filterString message: message])
|
|
||||||
[fDisplayedMessages addObject: message];
|
|
||||||
|
|
||||||
[fDisplayedMessages sortUsingDescriptors: [fMessageTable sortDescriptors]];
|
|
||||||
|
|
||||||
[fMessageTable reloadData];
|
|
||||||
|
|
||||||
if ([fDisplayedMessages count] > 0)
|
|
||||||
{
|
|
||||||
[fMessageTable deselectAll: self];
|
|
||||||
[fMessageTable scrollRowToVisible: [fMessageTable numberOfRows]-1];
|
|
||||||
}
|
|
||||||
|
|
||||||
[fLock unlock];
|
[fLock unlock];
|
||||||
}
|
}
|
||||||
|
@ -370,24 +356,7 @@
|
||||||
{
|
{
|
||||||
[fLock lock];
|
[fLock lock];
|
||||||
|
|
||||||
const NSInteger level = [[NSUserDefaults standardUserDefaults] integerForKey: @"MessageLevel"];
|
[self updateListForFilter];
|
||||||
NSString * filterString = [fFilterField stringValue];
|
|
||||||
|
|
||||||
[fDisplayedMessages removeAllObjects];
|
|
||||||
for (NSDictionary * message in fMessages)
|
|
||||||
if ([[message objectForKey: @"Level"] integerValue] <= level
|
|
||||||
&& [self shouldIncludeMessageForFilter: filterString message: message])
|
|
||||||
[fDisplayedMessages addObject: message];
|
|
||||||
|
|
||||||
[fDisplayedMessages sortUsingDescriptors: [fMessageTable sortDescriptors]];
|
|
||||||
|
|
||||||
[fMessageTable reloadData];
|
|
||||||
|
|
||||||
if ([fDisplayedMessages count] > 0)
|
|
||||||
{
|
|
||||||
[fMessageTable deselectAll: self];
|
|
||||||
[fMessageTable scrollRowToVisible: [fMessageTable numberOfRows]-1];
|
|
||||||
}
|
|
||||||
|
|
||||||
[fLock unlock];
|
[fLock unlock];
|
||||||
}
|
}
|
||||||
|
@ -397,7 +366,19 @@
|
||||||
[fLock lock];
|
[fLock lock];
|
||||||
|
|
||||||
[fMessages removeAllObjects];
|
[fMessages removeAllObjects];
|
||||||
|
|
||||||
|
const BOOL onLion = [NSApp isOnLionOrBetter];
|
||||||
|
|
||||||
|
if (onLion)
|
||||||
|
[fMessageTable beginUpdates];
|
||||||
|
|
||||||
|
if (onLion)
|
||||||
|
[fMessageTable removeRowsAtIndexes: [NSIndexSet indexSetWithIndexesInRange: NSMakeRange(0, [fDisplayedMessages count])] withAnimation: NSTableViewAnimationSlideLeft];
|
||||||
[fDisplayedMessages removeAllObjects];
|
[fDisplayedMessages removeAllObjects];
|
||||||
|
|
||||||
|
if (onLion)
|
||||||
|
[fMessageTable endUpdates];
|
||||||
|
else
|
||||||
[fMessageTable reloadData];
|
[fMessageTable reloadData];
|
||||||
|
|
||||||
[fLock unlock];
|
[fLock unlock];
|
||||||
|
@ -469,6 +450,81 @@
|
||||||
|| [[message objectForKey: @"Message"] rangeOfString: filterString options: searchOptions].location != NSNotFound;
|
|| [[message objectForKey: @"Message"] rangeOfString: filterString options: searchOptions].location != NSNotFound;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (void) updateListForFilter
|
||||||
|
{
|
||||||
|
const NSInteger level = [[NSUserDefaults standardUserDefaults] integerForKey: @"MessageLevel"];
|
||||||
|
NSString * filterString = [fFilterField stringValue];
|
||||||
|
|
||||||
|
NSMutableArray * tempMessages = [NSMutableArray arrayWithCapacity: [fMessages count]]; //rough guess
|
||||||
|
|
||||||
|
for (NSDictionary * message in fMessages)
|
||||||
|
{
|
||||||
|
if ([[message objectForKey: @"Level"] integerValue] <= level
|
||||||
|
&& [self shouldIncludeMessageForFilter: filterString message: message])
|
||||||
|
[tempMessages addObject: message];
|
||||||
|
}
|
||||||
|
|
||||||
|
[tempMessages sortUsingDescriptors: [fMessageTable sortDescriptors]];
|
||||||
|
|
||||||
|
const BOOL onLion = [NSApp isOnLionOrBetter];
|
||||||
|
|
||||||
|
if (onLion)
|
||||||
|
[fMessageTable beginUpdates];
|
||||||
|
|
||||||
|
//figure out which rows were added/moved
|
||||||
|
NSUInteger currentIndex = 0, totalCount = 0;
|
||||||
|
NSMutableArray * itemsToAdd = [NSMutableArray array];
|
||||||
|
NSMutableIndexSet * itemsToAddIndexes = [NSMutableIndexSet indexSet];
|
||||||
|
|
||||||
|
for (NSDictionary * message in tempMessages)
|
||||||
|
{
|
||||||
|
const NSUInteger previousIndex = [fDisplayedMessages indexOfObject: message inRange: NSMakeRange(currentIndex, [fDisplayedMessages count]-currentIndex)];
|
||||||
|
if (previousIndex == NSNotFound)
|
||||||
|
{
|
||||||
|
[itemsToAdd addObject: message];
|
||||||
|
[itemsToAddIndexes addIndex: totalCount];
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (previousIndex != currentIndex)
|
||||||
|
{
|
||||||
|
[fDisplayedMessages moveObjectAtIndex: previousIndex toIndex: currentIndex];
|
||||||
|
if (onLion)
|
||||||
|
[fMessageTable moveRowAtIndex: previousIndex toIndex: currentIndex];
|
||||||
|
}
|
||||||
|
++currentIndex;
|
||||||
|
}
|
||||||
|
|
||||||
|
++totalCount;
|
||||||
|
}
|
||||||
|
|
||||||
|
//remove trailing items - those are the unused
|
||||||
|
if (currentIndex < [fDisplayedMessages count])
|
||||||
|
{
|
||||||
|
const NSRange removeRange = NSMakeRange(currentIndex, [fDisplayedMessages count]-currentIndex);
|
||||||
|
[fDisplayedMessages removeObjectsInRange: removeRange];
|
||||||
|
if (onLion)
|
||||||
|
[fMessageTable removeRowsAtIndexes: [NSIndexSet indexSetWithIndexesInRange: removeRange] withAnimation: NSTableViewAnimationSlideDown];
|
||||||
|
}
|
||||||
|
|
||||||
|
//add new items
|
||||||
|
[fDisplayedMessages insertObjects: itemsToAdd atIndexes: itemsToAddIndexes];
|
||||||
|
if (onLion)
|
||||||
|
[fMessageTable insertRowsAtIndexes: itemsToAddIndexes withAnimation: NSTableViewAnimationSlideUp];
|
||||||
|
|
||||||
|
if (onLion)
|
||||||
|
[fMessageTable endUpdates];
|
||||||
|
else
|
||||||
|
{
|
||||||
|
[fMessageTable reloadData];
|
||||||
|
|
||||||
|
if ([fDisplayedMessages count] > 0)
|
||||||
|
[fMessageTable deselectAll: self];
|
||||||
|
}
|
||||||
|
|
||||||
|
NSAssert([fDisplayedMessages isEqualToArray: tempMessages], @"Inconsistency between message arrays! %@ %@", fDisplayedMessages, tempMessages);
|
||||||
|
}
|
||||||
|
|
||||||
- (NSString *) stringForMessage: (NSDictionary *) message
|
- (NSString *) stringForMessage: (NSDictionary *) message
|
||||||
{
|
{
|
||||||
NSString * levelString;
|
NSString * levelString;
|
||||||
|
|
Loading…
Reference in a new issue