aboutsummaryrefslogtreecommitdiffstats
path: root/Source/SPConnectionController.m
diff options
context:
space:
mode:
authorstuconnolly <stuart02@gmail.com>2011-02-02 23:10:06 +0000
committerstuconnolly <stuart02@gmail.com>2011-02-02 23:10:06 +0000
commitc9338aee82e9b42a07e93625c3235977c3dbf1b4 (patch)
tree1264821eaa188b13e5dd964dc9c48ad13fc766dd /Source/SPConnectionController.m
parentf1f5e84d38e29f2258aa958f55382ef70085843b (diff)
downloadsequelpro-c9338aee82e9b42a07e93625c3235977c3dbf1b4.tar.gz
sequelpro-c9338aee82e9b42a07e93625c3235977c3dbf1b4.tar.bz2
sequelpro-c9338aee82e9b42a07e93625c3235977c3dbf1b4.zip
Fix favorites sorting.
Diffstat (limited to 'Source/SPConnectionController.m')
-rw-r--r--Source/SPConnectionController.m25
1 files changed, 21 insertions, 4 deletions
diff --git a/Source/SPConnectionController.m b/Source/SPConnectionController.m
index 9f542cec..8424b427 100644
--- a/Source/SPConnectionController.m
+++ b/Source/SPConnectionController.m
@@ -1193,6 +1193,9 @@ static NSComparisonResult compareFavoritesUsingKey(id favorite1, id favorite2, v
{
NSMutableArray *nodes = [[node mutableChildNodes] mutableCopy];
+ // If this node only has one child and it's not another group node, don't bother proceeding
+ if (([nodes count] == 1) && (![[nodes objectAtIndex:0] isGroup])) return;
+
for (SPTreeNode *node in nodes)
{
if ([node isGroup]) {
@@ -1200,20 +1203,34 @@ static NSComparisonResult compareFavoritesUsingKey(id favorite1, id favorite2, v
}
}
+ NSMutableIndexSet *indexes = [[NSMutableIndexSet alloc] init];
NSMutableArray *groupNodes = [[NSMutableArray alloc] init];
- for (node in nodes)
+ for (SPTreeNode *innerNode in nodes)
{
- if ([node isGroup]) {
- [groupNodes addObject:node];
- [nodes removeObject:node];
+ if ([innerNode isGroup]) {
+ [groupNodes addObject:innerNode];
+ [indexes addIndex:[nodes indexOfObject:innerNode]];
}
}
+ NSUInteger i = [indexes firstIndex];
+
+ while (i != NSNotFound)
+ {
+ [nodes removeObjectAtIndex:i];
+
+ i = [indexes indexGreaterThanIndex:i];
+ }
+
+ [indexes release];
+
[nodes sortUsingFunction:compareFavoritesUsingKey context:key];
[nodes addObjectsFromArray:groupNodes];
+ if (reverseFavoritesSort) [nodes reverse];
+
[[node mutableChildNodes] setArray:nodes];
[groupNodes release];