diff options
author | Max <post@wickenrode.com> | 2015-06-20 22:54:35 +0200 |
---|---|---|
committer | Max <post@wickenrode.com> | 2015-06-20 22:54:35 +0200 |
commit | 0c39d230884d5d65dcfa758e13780ebe6c1c057b (patch) | |
tree | 2e2afe146674e65be02f7519b43ba05cf838776a | |
parent | 2b52f76ed2103bc6d458767906753814ee8ba9e1 (diff) | |
download | sequelpro-0c39d230884d5d65dcfa758e13780ebe6c1c057b.tar.gz sequelpro-0c39d230884d5d65dcfa758e13780ebe6c1c057b.tar.bz2 sequelpro-0c39d230884d5d65dcfa758e13780ebe6c1c057b.zip |
Fix an issue where sorting favorites by "host" or "type" would cause an exception if groups are present (fixes #2151)
Groups are now placed at the top when not sorting by "name".
-rw-r--r-- | Source/SPConnectionController.m | 19 |
1 files changed, 15 insertions, 4 deletions
diff --git a/Source/SPConnectionController.m b/Source/SPConnectionController.m index dcdaec93..aca3e982 100644 --- a/Source/SPConnectionController.m +++ b/Source/SPConnectionController.m @@ -1513,26 +1513,37 @@ static NSComparisonResult _compareFavoritesUsingKey(id favorite1, id favorite2, { NSString *dictKey = (NSString *)key; id value1, value2; + + BOOL isNamedComparison = [dictKey isEqualToString:SPFavoriteNameKey]; + // Group nodes can only be compared using their names. + // If this is a named comparison or both nodes are group nodes use their + // names. Otherwise let the group nodes win (ie. they will be placed at the + // top ordered alphabetically for all other comparison keys) if ([favorite1 isGroup]) { - if ([dictKey isEqualToString:SPFavoriteNameKey] || [favorite2 isGroup]) { + if (isNamedComparison || [favorite2 isGroup]) { value1 = [[favorite1 representedObject] nodeName]; } else { - value1 = nil; + return NSOrderedAscending; // the left object is a group, the right is not -> left wins } } else { value1 = [[(SPFavoriteNode *)[(SPTreeNode *)favorite1 representedObject] nodeFavorite] objectForKey:dictKey]; } if ([favorite2 isGroup]) { - if ([dictKey isEqualToString:SPFavoriteNameKey] || [favorite1 isGroup]) { + if (isNamedComparison || [favorite1 isGroup]) { value2 = [[favorite2 representedObject] nodeName]; } else { - value2 = nil; + return NSOrderedDescending; // the left object is not a group, the right is -> left loses } } else { value2 = [[(SPFavoriteNode *)[(SPTreeNode *)favorite2 representedObject] nodeFavorite] objectForKey:dictKey]; } + + //if a value is undefined count it as "loser" + if(!value1 && value2) return NSOrderedDescending; + if(value1 && !value2) return NSOrderedAscending; + if(!value1 && !value2) return NSOrderedSame; if ([value1 isKindOfClass:[NSString class]]) { return [value1 caseInsensitiveCompare:value2]; |