Ignore case when sorting.

This commit is contained in:
Mitchell Livingston 2006-07-23 21:29:24 +00:00
parent 802345f5ed
commit e5fc3b555e
2 changed files with 11 additions and 11 deletions

View File

@ -945,10 +945,10 @@ static void sleepCallBack(void * controller, io_service_t y, natural_t messageTy
//doesn't remember selected rows //doesn't remember selected rows
- (void) sortTorrentsIgnoreSelected - (void) sortTorrentsIgnoreSelected
{ {
NSSortDescriptor * nameDescriptor = [[[NSSortDescriptor alloc] initWithKey: NSSortDescriptor * nameDescriptor = [[[NSSortDescriptor alloc] initWithKey: @"name"
@"name" ascending: YES] autorelease], ascending: YES selector: @selector(caseInsensitiveCompare:)] autorelease],
* orderDescriptor = [[[NSSortDescriptor alloc] initWithKey: * orderDescriptor = [[[NSSortDescriptor alloc] initWithKey: @"orderValue"
@"orderValue" ascending: YES] autorelease]; ascending: YES] autorelease];
NSArray * descriptors; NSArray * descriptors;
if ([fSortType isEqualToString: @"Name"]) if ([fSortType isEqualToString: @"Name"])
@ -972,8 +972,7 @@ static void sleepCallBack(void * controller, io_service_t y, natural_t messageTy
} }
else if ([fSortType isEqualToString: @"Date"]) else if ([fSortType isEqualToString: @"Date"])
{ {
NSSortDescriptor * dateDescriptor = [[[NSSortDescriptor alloc] initWithKey: NSSortDescriptor * dateDescriptor = [[[NSSortDescriptor alloc] initWithKey: @"date" ascending: YES] autorelease];
@"date" ascending: YES] autorelease];
descriptors = [[NSArray alloc] initWithObjects: dateDescriptor, orderDescriptor, nil]; descriptors = [[NSArray alloc] initWithObjects: dateDescriptor, orderDescriptor, nil];
} }

View File

@ -154,7 +154,9 @@
- (void) keyDown: (NSEvent *) event - (void) keyDown: (NSEvent *) event
{ {
unichar newChar = [[event characters] characterAtIndex: 0]; unichar newChar = [[event characters] characterAtIndex: 0];
if (newChar == ' ' || [[NSCharacterSet alphanumericCharacterSet] characterIsMember: newChar]) if (newChar == ' ' || [[NSCharacterSet alphanumericCharacterSet] characterIsMember: newChar]
|| [[NSCharacterSet symbolCharacterSet] characterIsMember: newChar]
|| [[NSCharacterSet punctuationCharacterSet] characterIsMember: newChar])
{ {
if ([fKeyStrokes count] > 0 && [event timestamp] - [[fKeyStrokes lastObject] timestamp] > 1.0) if ([fKeyStrokes count] > 0 && [event timestamp] - [[fKeyStrokes lastObject] timestamp] > 1.0)
[fKeyStrokes removeAllObjects]; [fKeyStrokes removeAllObjects];
@ -173,10 +175,9 @@
- (void) insertText: (NSString *) text - (void) insertText: (NSString *) text
{ {
NSLog(text);
//sort torrents by name before finding closest match //sort torrents by name before finding closest match
NSSortDescriptor * nameDescriptor = [[[NSSortDescriptor alloc] initWithKey: @"name" ascending: YES] autorelease]; NSSortDescriptor * nameDescriptor = [[[NSSortDescriptor alloc] initWithKey: @"name" ascending: YES
selector: @selector(caseInsensitiveCompare:)] autorelease];
NSArray * descriptors = [[NSArray alloc] initWithObjects: nameDescriptor, nil]; NSArray * descriptors = [[NSArray alloc] initWithObjects: nameDescriptor, nil];
NSArray * tempTorrents = [fTorrents sortedArrayUsingDescriptors: descriptors]; NSArray * tempTorrents = [fTorrents sortedArrayUsingDescriptors: descriptors];
@ -186,7 +187,7 @@
NSEnumerator * enumerator = [tempTorrents objectEnumerator]; NSEnumerator * enumerator = [tempTorrents objectEnumerator];
Torrent * torrent; Torrent * torrent;
while ((torrent = [enumerator nextObject])) while ((torrent = [enumerator nextObject]))
{ {NSLog([[torrent name] lowercaseString]);
if ([[torrent name] caseInsensitiveCompare: text] != NSOrderedAscending) if ([[torrent name] caseInsensitiveCompare: text] != NSOrderedAscending)
{ {
[self selectRow: [fTorrents indexOfObject: torrent] byExtendingSelection: NO]; [self selectRow: [fTorrents indexOfObject: torrent] byExtendingSelection: NO];