only update and sort by group when filtering, not during normal sorting

This commit is contained in:
Mitchell Livingston
2008-01-23 20:31:04 +00:00
parent 920811c894
commit 549521c602
5 changed files with 120 additions and 32 deletions

View File

@@ -86,6 +86,7 @@
A2265F420B5EF5F40093DDA5 /* FileNameCell.m in Sources */ = {isa = PBXBuildFile; fileRef = A2265F400B5EF5F40093DDA5 /* FileNameCell.m */; }; A2265F420B5EF5F40093DDA5 /* FileNameCell.m in Sources */ = {isa = PBXBuildFile; fileRef = A2265F400B5EF5F40093DDA5 /* FileNameCell.m */; };
A226FDAC0D0CDF20005A7F71 /* libnatpmp.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 3C7A118D0D0B2EB800B5701F /* libnatpmp.a */; }; A226FDAC0D0CDF20005A7F71 /* libnatpmp.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 3C7A118D0D0B2EB800B5701F /* libnatpmp.a */; };
A22A8D560AEEAFA5007E9CB9 /* Localizable.strings in Resources */ = {isa = PBXBuildFile; fileRef = A22A8D540AEEAFA5007E9CB9 /* Localizable.strings */; }; A22A8D560AEEAFA5007E9CB9 /* Localizable.strings in Resources */ = {isa = PBXBuildFile; fileRef = A22A8D540AEEAFA5007E9CB9 /* Localizable.strings */; };
A22B862D0D47D91300F9BAD9 /* NSMutableArrayAdditions.m in Sources */ = {isa = PBXBuildFile; fileRef = A22B862C0D47D91300F9BAD9 /* NSMutableArrayAdditions.m */; };
A22D3AA60D00D1790079CFED /* Turtle.png in Resources */ = {isa = PBXBuildFile; fileRef = A22D3AA30D00D1790079CFED /* Turtle.png */; }; A22D3AA60D00D1790079CFED /* Turtle.png in Resources */ = {isa = PBXBuildFile; fileRef = A22D3AA30D00D1790079CFED /* Turtle.png */; };
A22D3AA70D00D1790079CFED /* TurtleBlue.png in Resources */ = {isa = PBXBuildFile; fileRef = A22D3AA40D00D1790079CFED /* TurtleBlue.png */; }; A22D3AA70D00D1790079CFED /* TurtleBlue.png in Resources */ = {isa = PBXBuildFile; fileRef = A22D3AA40D00D1790079CFED /* TurtleBlue.png */; };
A231274C0D11D0B7003F9AFF /* AboutWindow.xib in Resources */ = {isa = PBXBuildFile; fileRef = A231274B0D11D0B7003F9AFF /* AboutWindow.xib */; }; A231274C0D11D0B7003F9AFF /* AboutWindow.xib in Resources */ = {isa = PBXBuildFile; fileRef = A231274B0D11D0B7003F9AFF /* AboutWindow.xib */; };
@@ -459,6 +460,8 @@
A223AABB0D22ECE800840069 /* it */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = it; path = macosx/it.lproj/StatsWindow.xib; sourceTree = "<group>"; }; A223AABB0D22ECE800840069 /* it */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = it; path = macosx/it.lproj/StatsWindow.xib; sourceTree = "<group>"; };
A2265F3F0B5EF5F40093DDA5 /* FileNameCell.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; name = FileNameCell.h; path = macosx/FileNameCell.h; sourceTree = "<group>"; }; A2265F3F0B5EF5F40093DDA5 /* FileNameCell.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; name = FileNameCell.h; path = macosx/FileNameCell.h; sourceTree = "<group>"; };
A2265F400B5EF5F40093DDA5 /* FileNameCell.m */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.objc; name = FileNameCell.m; path = macosx/FileNameCell.m; sourceTree = "<group>"; }; A2265F400B5EF5F40093DDA5 /* FileNameCell.m */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.objc; name = FileNameCell.m; path = macosx/FileNameCell.m; sourceTree = "<group>"; };
A22B862B0D47D91300F9BAD9 /* NSMutableArrayAdditions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = NSMutableArrayAdditions.h; path = macosx/NSMutableArrayAdditions.h; sourceTree = "<group>"; };
A22B862C0D47D91300F9BAD9 /* NSMutableArrayAdditions.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = NSMutableArrayAdditions.m; path = macosx/NSMutableArrayAdditions.m; sourceTree = "<group>"; };
A22D3AA30D00D1790079CFED /* Turtle.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = Turtle.png; path = macosx/Images/Turtle.png; sourceTree = "<group>"; }; A22D3AA30D00D1790079CFED /* Turtle.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = Turtle.png; path = macosx/Images/Turtle.png; sourceTree = "<group>"; };
A22D3AA40D00D1790079CFED /* TurtleBlue.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = TurtleBlue.png; path = macosx/Images/TurtleBlue.png; sourceTree = "<group>"; }; A22D3AA40D00D1790079CFED /* TurtleBlue.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = TurtleBlue.png; path = macosx/Images/TurtleBlue.png; sourceTree = "<group>"; };
A231274B0D11D0B7003F9AFF /* AboutWindow.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = AboutWindow.xib; path = macosx/AboutWindow.xib; sourceTree = "<group>"; }; A231274B0D11D0B7003F9AFF /* AboutWindow.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = AboutWindow.xib; path = macosx/AboutWindow.xib; sourceTree = "<group>"; };
@@ -1111,6 +1114,8 @@
A21576090C0D449A0057A26A /* NSBezierPathAdditions.m */, A21576090C0D449A0057A26A /* NSBezierPathAdditions.m */,
A234D0CF0C79FB3600A82373 /* NSMenuAdditions.h */, A234D0CF0C79FB3600A82373 /* NSMenuAdditions.h */,
A234D0D00C79FB3600A82373 /* NSMenuAdditions.m */, A234D0D00C79FB3600A82373 /* NSMenuAdditions.m */,
A22B862B0D47D91300F9BAD9 /* NSMutableArrayAdditions.h */,
A22B862C0D47D91300F9BAD9 /* NSMutableArrayAdditions.m */,
); );
name = Additions; name = Additions;
sourceTree = "<group>"; sourceTree = "<group>";
@@ -1793,6 +1798,7 @@
A22180980D148A71007D09ED /* GroupsWindowController.m in Sources */, A22180980D148A71007D09ED /* GroupsWindowController.m in Sources */,
A26AF21A0D2DA35A00FF7140 /* FileOutlineController.m in Sources */, A26AF21A0D2DA35A00FF7140 /* FileOutlineController.m in Sources */,
A26AF2840D2DC27C00FF7140 /* AddWindowController.m in Sources */, A26AF2840D2DC27C00FF7140 /* AddWindowController.m in Sources */,
A22B862D0D47D91300F9BAD9 /* NSMutableArrayAdditions.m in Sources */,
); );
runOnlyForDeploymentPostprocessing = 0; runOnlyForDeploymentPostprocessing = 0;
}; };

View File

@@ -38,6 +38,7 @@
#import "NSApplicationAdditions.h" #import "NSApplicationAdditions.h"
#import "NSStringAdditions.h" #import "NSStringAdditions.h"
#import "NSMenuAdditions.h" #import "NSMenuAdditions.h"
#import "NSMutableArrayAdditions.h"
#import "UKKQueue.h" #import "UKKQueue.h"
#import "ExpandedPathToPathTransformer.h" #import "ExpandedPathToPathTransformer.h"
#import "ExpandedPathToIconTransformer.h" #import "ExpandedPathToIconTransformer.h"
@@ -1645,6 +1646,7 @@ void sleepCallBack(void * controller, io_service_t y, natural_t messageType, voi
[self updateDisplay: nil]; [self updateDisplay: nil];
} }
#warning rename sortIgnoringSelected
- (void) prepareForDisplay - (void) prepareForDisplay
{ {
NSString * sortType = [fDefaults stringForKey: @"Sort"]; NSString * sortType = [fDefaults stringForKey: @"Sort"];
@@ -1655,8 +1657,6 @@ void sleepCallBack(void * controller, io_service_t y, natural_t messageType, voi
* orderDescriptor = [[[NSSortDescriptor alloc] initWithKey: @"orderValue" * orderDescriptor = [[[NSSortDescriptor alloc] initWithKey: @"orderValue"
ascending: asc] autorelease]; ascending: asc] autorelease];
BOOL group = NO;
NSArray * descriptors; NSArray * descriptors;
if ([sortType isEqualToString: SORT_ORDER]) if ([sortType isEqualToString: SORT_ORDER])
descriptors = [[NSArray alloc] initWithObjects: orderDescriptor, nil]; descriptors = [[NSArray alloc] initWithObjects: orderDescriptor, nil];
@@ -1711,8 +1711,7 @@ void sleepCallBack(void * controller, io_service_t y, natural_t messageType, voi
descriptors = [[NSArray alloc] initWithObjects: dateDescriptor, orderDescriptor, nil]; descriptors = [[NSArray alloc] initWithObjects: dateDescriptor, orderDescriptor, nil];
} }
group = [fDefaults boolForKey: @"SortByGroup"]; if (![NSApp isOnLeopardOrBetter] && [fDefaults boolForKey: @"SortByGroup"])
if (group)
{ {
NSSortDescriptor * groupDescriptor = [[[NSSortDescriptor alloc] initWithKey: @"groupOrderValue" NSSortDescriptor * groupDescriptor = [[[NSSortDescriptor alloc] initWithKey: @"groupOrderValue"
ascending: asc] autorelease]; ascending: asc] autorelease];
@@ -1726,40 +1725,28 @@ void sleepCallBack(void * controller, io_service_t y, natural_t messageType, voi
} }
} }
[fDisplayedTorrents sortUsingDescriptors: descriptors]; //actually sort
[descriptors release]; if ([fDefaults boolForKey: @"SortByGroup"] && [NSApp isOnLeopardOrBetter])
//add group divider if necessary
int total = [fDisplayedTorrents count];
[fDisplayedGroupIndexes removeAllIndexes];
if (group && total > 0 && [NSApp isOnLeopardOrBetter])
{ {
int i, groupValue = [[fDisplayedTorrents objectAtIndex: 0] groupValue], newGroupValue, count = 1, start = 0; NSUInteger i, nextGroup;
for (i = 0; i < [fDisplayedTorrents count]; i++) for (i = [fDisplayedGroupIndexes firstIndex]; i != NSNotFound; i = nextGroup)
{ {
BOOL last = i == [fDisplayedTorrents count]-1; nextGroup = [fDisplayedGroupIndexes indexGreaterThanIndex: i];
if (!last) NSUInteger count = (nextGroup != NSNotFound ? nextGroup : [fDisplayedTorrents count]) - i - 1;
newGroupValue = [[fDisplayedTorrents objectAtIndex: i+1] groupValue];
if (groupValue != newGroupValue || last) [fDisplayedTorrents sortIndexes: [NSIndexSet indexSetWithIndexesInRange: NSMakeRange(i+1, count)]
{ usingDescriptors: descriptors];
[fDisplayedTorrents insertObject: [NSNumber numberWithInt: groupValue] atIndex: start];
[fDisplayedGroupIndexes addIndex: start];
groupValue = newGroupValue;
count = 1;
start = i+2;
i++;
}
else
count++;
} }
} }
else
[fDisplayedTorrents sortUsingDescriptors: descriptors];
[descriptors release];
[fTableView reloadData]; [fTableView reloadData];
} }
#warning rename applyFilter
- (void) updateDisplay: (id) sender - (void) updateDisplay: (id) sender
{ {
NSMutableArray * previousTorrents = [fDisplayedTorrents mutableCopy]; NSMutableArray * previousTorrents = [fDisplayedTorrents mutableCopy];
@@ -1886,6 +1873,36 @@ void sleepCallBack(void * controller, io_service_t y, natural_t messageType, voi
[previousTorrents release]; [previousTorrents release];
#warning
//add group items
[fDisplayedGroupIndexes removeAllIndexes];
if ([fDefaults boolForKey: @"SortByGroup"] && [NSApp isOnLeopardOrBetter])
{
NSSortDescriptor * groupDescriptor = [[[NSSortDescriptor alloc] initWithKey: @"groupOrderValue" ascending: YES] autorelease];
[fDisplayedTorrents sortUsingDescriptors: [NSArray arrayWithObject: groupDescriptor]];
int i, groupValue = [[fDisplayedTorrents objectAtIndex: 0] groupValue], newGroupValue, count = 1, start = 0;
for (i = 0; i < [fDisplayedTorrents count]; i++)
{
BOOL last = i == [fDisplayedTorrents count]-1;
if (!last)
newGroupValue = [[fDisplayedTorrents objectAtIndex: i+1] groupValue];
if (groupValue != newGroupValue || last)
{
[fDisplayedTorrents insertObject: [NSNumber numberWithInt: groupValue] atIndex: start];
[fDisplayedGroupIndexes addIndex: start];
groupValue = newGroupValue;
count = 1;
start = i+2;
i++;
}
else
count++;
}
}
//sort, add groups, and reset selected //sort, add groups, and reset selected
[self prepareForDisplay]; [self prepareForDisplay];
[fTableView selectValues: selectedValues]; [fTableView selectValues: selectedValues];

View File

@@ -0,0 +1,29 @@
/******************************************************************************
* $Id$
*
* Copyright (c) 2008 Transmission authors and contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*****************************************************************************/
@interface NSMutableArray (NSMutableArrayAdditions)
- (void) sortIndexes: (NSIndexSet *) indexes usingDescriptors: (NSArray *) sortDescriptors;
@end

View File

@@ -0,0 +1,36 @@
/******************************************************************************
* $Id$
*
* Copyright (c) 2008 Transmission authors and contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*****************************************************************************/
#import "NSMutableArrayAdditions.h"
@implementation NSMutableArray (NSMutableArrayAdditions)
- (void) sortIndexes: (NSIndexSet *) indexes usingDescriptors: (NSArray *) sortDescriptors
{
NSArray * items = [self objectsAtIndexes: indexes];
items = [items sortedArrayUsingDescriptors: sortDescriptors];
[self replaceObjectsAtIndexes: indexes withObjects: items];
}
@end

View File

@@ -316,8 +316,8 @@
[indexSet addIndex: i]; [indexSet addIndex: i];
else else
{ {
unsigned nextGroup = [fGroupIndexes indexGreaterThanIndex: i], NSUInteger nextGroup = [fGroupIndexes indexGreaterThanIndex: i],
count = (nextGroup != NSNotFound ? nextGroup : [fTorrents count]) - i - 1 ; count = (nextGroup != NSNotFound ? nextGroup : [fTorrents count]) - i - 1;
[indexSet addIndexesInRange: NSMakeRange(i+1, count)]; [indexSet addIndexesInRange: NSMakeRange(i+1, count)];
i = nextGroup-1; i = nextGroup-1;
} }