From 313885df00ca746ad4e6a2ae85568514b56d0515 Mon Sep 17 00:00:00 2001 From: Mitchell Livingston Date: Fri, 27 Jun 2008 05:15:50 +0000 Subject: [PATCH] add a comparison method for the transfer names to sort the exact same way the Finder does --- macosx/Controller.m | 8 ++++---- macosx/English.lproj/InfoWindow.xib | 6 ++++-- macosx/MessageWindow.xib | 2 +- macosx/NSStringAdditions.h | 1 + macosx/NSStringAdditions.m | 15 +++++++++++++-- 5 files changed, 23 insertions(+), 9 deletions(-) diff --git a/macosx/Controller.m b/macosx/Controller.m index 0893e0a90..ede019086 100644 --- a/macosx/Controller.m +++ b/macosx/Controller.m @@ -1820,14 +1820,14 @@ static void sleepCallback(void * controller, io_service_t y, natural_t messageTy else if ([sortType isEqualToString: SORT_NAME]) { NSSortDescriptor * nameDescriptor = [[[NSSortDescriptor alloc] initWithKey: @"name" ascending: asc - selector: @selector(localizedCaseInsensitiveCompare:)] autorelease]; + selector: @selector(compareFinder:)] autorelease]; descriptors = [[NSArray alloc] initWithObjects: nameDescriptor, orderDescriptor, nil]; } else if ([sortType isEqualToString: SORT_STATE]) { NSSortDescriptor * nameDescriptor = [[[NSSortDescriptor alloc] initWithKey: @"name" ascending: asc - selector: @selector(localizedCaseInsensitiveCompare:)] autorelease], + selector: @selector(compareFinder:)] autorelease], * stateDescriptor = [[[NSSortDescriptor alloc] initWithKey: @"stateSortKey" ascending: !asc] autorelease], * progressDescriptor = [[[NSSortDescriptor alloc] initWithKey: @"progress" ascending: !asc] autorelease], * ratioDescriptor = [[[NSSortDescriptor alloc] initWithKey: @"ratio" ascending: !asc] autorelease]; @@ -1838,7 +1838,7 @@ static void sleepCallback(void * controller, io_service_t y, natural_t messageTy else if ([sortType isEqualToString: SORT_PROGRESS]) { NSSortDescriptor * nameDescriptor = [[[NSSortDescriptor alloc] initWithKey: @"name" ascending: asc - selector: @selector(localizedCaseInsensitiveCompare:)] autorelease], + selector: @selector(compareFinder:)] autorelease], * progressDescriptor = [[[NSSortDescriptor alloc] initWithKey: @"progress" ascending: asc] autorelease], * ratioProgressDescriptor = [[[NSSortDescriptor alloc] initWithKey: @"progressStopRatio" ascending: asc] autorelease], @@ -1850,7 +1850,7 @@ static void sleepCallback(void * controller, io_service_t y, natural_t messageTy else if ([sortType isEqualToString: SORT_TRACKER]) { NSSortDescriptor * nameDescriptor = [[[NSSortDescriptor alloc] initWithKey: @"name" ascending: asc - selector: @selector(localizedCaseInsensitiveCompare:)] autorelease], + selector: @selector(compareFinder:)] autorelease], * trackerDescriptor = [[[NSSortDescriptor alloc] initWithKey: @"trackerAddressAnnounce" ascending: asc selector: @selector(localizedCaseInsensitiveCompare:)] autorelease]; diff --git a/macosx/English.lproj/InfoWindow.xib b/macosx/English.lproj/InfoWindow.xib index caa1e2783..a475babc6 100644 --- a/macosx/English.lproj/InfoWindow.xib +++ b/macosx/English.lproj/InfoWindow.xib @@ -2141,6 +2141,7 @@ AAB0ZXh0AAAAAENvcHlyaWdodCBBcHBsZSBDb21wdXRlciwgSW5jLiwgMjAwNQAAAAA {{1, 1}, {360, 143}} + 2 @@ -2169,6 +2170,7 @@ AAB0ZXh0AAAAAENvcHlyaWdodCBBcHBsZSBDb21wdXRlciwgSW5jLiwgMjAwNQAAAAA {{10, 202}, {362, 145}} + 530 @@ -2322,7 +2324,7 @@ AAB0ZXh0AAAAAENvcHlyaWdodCBBcHBsZSBDb21wdXRlciwgSW5jLiwgMjAwNQAAAAA Client YES - localizedCaseInsensitiveCompare: + compareFinder: @@ -8689,7 +8691,7 @@ zijOSc5pzorOqs66ztvO+88czzzPXc99z57Pvs/fz+/QANAg0EHQYdCC0KLQw9Dj0PPRFNE00VXRddGW com.apple.InterfaceBuilder.CocoaPlugin - {{634, 496}, {360, 342}} + {{440, 490}, {360, 342}} com.apple.InterfaceBuilder.CocoaPlugin {{63, 584}, {360, 342}} diff --git a/macosx/MessageWindow.xib b/macosx/MessageWindow.xib index 5f3805814..ccc73d772 100644 --- a/macosx/MessageWindow.xib +++ b/macosx/MessageWindow.xib @@ -1752,7 +1752,7 @@ zijOSc5pzorOqs66ztvO+88czzzPXc99z57Pvs/fz+/QANAg0EHQYdCC0KLQw9Dj0PPRFNE00VXRddGW Name YES - localizedCaseInsensitiveCompare: + compareFinder: diff --git a/macosx/NSStringAdditions.h b/macosx/NSStringAdditions.h index be695c89b..8e38c4240 100644 --- a/macosx/NSStringAdditions.h +++ b/macosx/NSStringAdditions.h @@ -38,6 +38,7 @@ + (NSString *) timeString: (uint64_t) seconds showSeconds: (BOOL) showSeconds; + (NSString *) timeString: (NSUInteger) seconds showSeconds: (BOOL) showSeconds maxFields: (NSUInteger) max; +- (NSComparisonResult) compareFinder: (NSString *) string; //how the Finder compares strings - (NSComparisonResult) compareIP: (NSString *) string; @end diff --git a/macosx/NSStringAdditions.m b/macosx/NSStringAdditions.m index feaed2afb..e03a10bdc 100644 --- a/macosx/NSStringAdditions.m +++ b/macosx/NSStringAdditions.m @@ -23,6 +23,7 @@ *****************************************************************************/ #import "NSStringAdditions.h" +#import "NSApplicationAdditions.h" #import @implementation NSString (NSStringAdditions) @@ -144,8 +145,16 @@ return [timeArray componentsJoinedByString: @" "]; } -- (NSComparisonResult) compareIP: (NSString *) string +- (NSComparisonResult) compareFinder: (NSString *) string { + int comparisonOptions = ![NSApp isOnLeopardOrBetter] ? (NSCaseInsensitiveSearch | NSNumericSearch) + : (NSCaseInsensitiveSearch | NSNumericSearch| NSWidthInsensitiveSearch | NSForcedOrderingSearch); + + return [self compare: string options: comparisonOptions range: NSMakeRange(0, [self length]) locale: [NSLocale currentLocale]]; +} + +- (NSComparisonResult) compareIP: (NSString *) string +{ NSArray * selfSections = [self componentsSeparatedByString: @"."], * newSections = [string componentsSeparatedByString: @"."]; @@ -154,9 +163,11 @@ NSEnumerator * selfSectionsEnum = [selfSections objectEnumerator], * newSectionsEnum = [newSections objectEnumerator]; NSString * selfString, * newString; + int comparisonOptions = [NSApp isOnLeopardOrBetter] ? (NSNumericSearch | NSForcedOrderingSearch) : NSNumericSearch; NSComparisonResult result; while ((selfString = [selfSectionsEnum nextObject]) && (newString = [newSectionsEnum nextObject])) - if ((result = [selfString compare: newString options: NSNumericSearch]) != NSOrderedSame) + if ((result = [selfString compare: newString options: comparisonOptions + range: NSMakeRange(0, [selfString length]) locale: [NSLocale currentLocale]]) != NSOrderedSame) return result; return NSOrderedSame;