From: Mitchell Livingston Date: Sat, 23 Oct 2010 20:20:31 +0000 (+0000) Subject: #3661 sort the file list alphabetically X-Git-Tag: 2.12~63 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=7b343c4ba06036f788aaa119496bd20aaa3e387c;p=transmission #3661 sort the file list alphabetically --- diff --git a/macosx/FileListNode.h b/macosx/FileListNode.h index fd1ef05bd..e36f90fa2 100644 --- a/macosx/FileListNode.h +++ b/macosx/FileListNode.h @@ -50,6 +50,6 @@ - (uint64_t) size; - (NSImage *) icon; -- (NSArray *) children; +- (NSMutableArray *) children; @end diff --git a/macosx/FileListNode.m b/macosx/FileListNode.m index cb7be5798..0f39886f9 100644 --- a/macosx/FileListNode.m +++ b/macosx/FileListNode.m @@ -121,7 +121,7 @@ return fIcon; } -- (NSArray *) children +- (NSMutableArray *) children { NSAssert(fIsFolder, @"method can only be invoked on folders"); diff --git a/macosx/Torrent.m b/macosx/Torrent.m index 80307ded8..013794c74 100644 --- a/macosx/Torrent.m +++ b/macosx/Torrent.m @@ -44,6 +44,7 @@ - (void) createFileList; - (void) insertPath: (NSMutableArray *) components forParent: (FileListNode *) parent fileSize: (uint64_t) size index: (NSInteger) index flatList: (NSMutableArray *) flatFileList; +- (void) sortFileList: (NSMutableArray *) fileNodes; - (void) completenessChange: (NSDictionary *) statusInfo; - (void) ratioLimitHit; @@ -1710,6 +1711,9 @@ int trashDataFile(const char * filename) } } + [self sortFileList: fileList]; + [self sortFileList: flatFileList]; + fFileList = [[NSArray alloc] initWithArray: fileList]; fFlatFileList = [[NSArray alloc] initWithArray: flatFileList]; } @@ -1761,6 +1765,17 @@ int trashDataFile(const char * filename) } } +- (void) sortFileList: (NSMutableArray *) fileNodes +{ + NSSortDescriptor * descriptor = [[[NSSortDescriptor alloc] initWithKey: @"name" ascending: YES + selector: @selector(compareFinder:)] autorelease]; + [fileNodes sortUsingDescriptors: [NSArray arrayWithObject: descriptor]]; + + for (FileListNode * node in fileNodes) + if ([node isFolder]) + [self sortFileList: [node children]]; +} + //status has been retained - (void) completenessChange: (NSDictionary *) statusInfo {