Playlist: Fix sorting by the track number column

Should now properly sort by album artist, album, then disc/track number.

Signed-off-by: Christopher Snowhill <kode54@gmail.com>
CQTexperiment
Christopher Snowhill 2022-02-17 17:07:37 -08:00
parent 5c3050c0d3
commit 0902703ee1
1 changed files with 21 additions and 6 deletions

View File

@ -18,6 +18,8 @@
#import "StatusImageTransformer.h" #import "StatusImageTransformer.h"
#import "ToggleQueueTitleTransformer.h" #import "ToggleQueueTitleTransformer.h"
#import "NSString+CogSort.h"
#import "Logging.h" #import "Logging.h"
#define UNDO_STACK_LIMIT 0 #define UNDO_STACK_LIMIT 0
@ -768,13 +770,26 @@ static inline void dispatch_sync_reentrant(dispatch_queue_t queue, dispatch_bloc
DLog(@"Current: %@, setting: %@", [self sortDescriptors], sortDescriptors); DLog(@"Current: %@, setting: %@", [self sortDescriptors], sortDescriptors);
// Cheap hack so the index column isn't sorted // Cheap hack so the index column isn't sorted
if(([sortDescriptors count] != 0) && [[sortDescriptors[0] key] if([sortDescriptors count] != 0) {
caseInsensitiveCompare:@"index"] == NSOrderedSame) { if([[sortDescriptors[0] key] caseInsensitiveCompare:@"index"] == NSOrderedSame) {
// Remove the sort descriptors // Remove the sort descriptors
[super setSortDescriptors:@[]]; [super setSortDescriptors:@[]];
[self rearrangeObjects]; [self rearrangeObjects];
return; return;
} else if([[sortDescriptors[0] key] caseInsensitiveCompare:@"track"] == NSOrderedSame) {
sortDescriptors = @[
[[NSSortDescriptor alloc] initWithKey:@"albumartist"
ascending:YES
selector:@selector(caseInsensitiveCompare:)],
[[NSSortDescriptor alloc] initWithKey:@"album"
ascending:YES
selector:@selector(caseInsensitiveCompare:)],
[[NSSortDescriptor alloc] initWithKey:@"track"
ascending:YES
selector:@selector(compareTrackNumbers:)]
];
}
} }
[super setSortDescriptors:sortDescriptors]; [super setSortDescriptors:sortDescriptors];