aboutsummaryrefslogtreecommitdiffstats
path: root/Source/SPConnectionController.m
diff options
context:
space:
mode:
authorMax <post@wickenrode.com>2015-06-20 22:54:35 +0200
committerMax <post@wickenrode.com>2015-06-29 21:55:04 +0200
commitae0d7a32efdfec92436151db8c5cfb634c4706c6 (patch)
tree64c6280e4ea8977f6d09508bc290435dfc2c9b99 /Source/SPConnectionController.m
parentf46198dd03614404702475a1ac99facbb389e826 (diff)
downloadsequelpro-ae0d7a32efdfec92436151db8c5cfb634c4706c6.tar.gz
sequelpro-ae0d7a32efdfec92436151db8c5cfb634c4706c6.tar.bz2
sequelpro-ae0d7a32efdfec92436151db8c5cfb634c4706c6.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".
Diffstat (limited to 'Source/SPConnectionController.m')
-rw-r--r--Source/SPConnectionController.m19
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];