From 0902703ee12abaee879eb40ebddecae23d609e7c Mon Sep 17 00:00:00 2001 From: Christopher Snowhill Date: Thu, 17 Feb 2022 17:07:37 -0800 Subject: [PATCH] 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 --- Playlist/PlaylistController.m | 27 +++++++++++++++++++++------ 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/Playlist/PlaylistController.m b/Playlist/PlaylistController.m index 7d9afd1e8..7048855e0 100644 --- a/Playlist/PlaylistController.m +++ b/Playlist/PlaylistController.m @@ -18,6 +18,8 @@ #import "StatusImageTransformer.h" #import "ToggleQueueTitleTransformer.h" +#import "NSString+CogSort.h" + #import "Logging.h" #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); // Cheap hack so the index column isn't sorted - if(([sortDescriptors count] != 0) && [[sortDescriptors[0] key] - caseInsensitiveCompare:@"index"] == NSOrderedSame) { - // Remove the sort descriptors - [super setSortDescriptors:@[]]; - [self rearrangeObjects]; + if([sortDescriptors count] != 0) { + if([[sortDescriptors[0] key] caseInsensitiveCompare:@"index"] == NSOrderedSame) { + // Remove the sort descriptors + [super setSortDescriptors:@[]]; + [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];