diff options
author | stuconnolly <stuart02@gmail.com> | 2011-02-02 23:10:06 +0000 |
---|---|---|
committer | stuconnolly <stuart02@gmail.com> | 2011-02-02 23:10:06 +0000 |
commit | c9338aee82e9b42a07e93625c3235977c3dbf1b4 (patch) | |
tree | 1264821eaa188b13e5dd964dc9c48ad13fc766dd /Source | |
parent | f1f5e84d38e29f2258aa958f55382ef70085843b (diff) | |
download | sequelpro-c9338aee82e9b42a07e93625c3235977c3dbf1b4.tar.gz sequelpro-c9338aee82e9b42a07e93625c3235977c3dbf1b4.tar.bz2 sequelpro-c9338aee82e9b42a07e93625c3235977c3dbf1b4.zip |
Fix favorites sorting.
Diffstat (limited to 'Source')
-rw-r--r-- | Source/SPArrayAdditions.h | 1 | ||||
-rw-r--r-- | Source/SPCategoryAdditions.h | 1 | ||||
-rw-r--r-- | Source/SPConnectionController.m | 25 | ||||
-rw-r--r-- | Source/SPMutableArrayAdditions.h | 37 | ||||
-rw-r--r-- | Source/SPMutableArrayAdditions.m | 48 |
5 files changed, 108 insertions, 4 deletions
diff --git a/Source/SPArrayAdditions.h b/Source/SPArrayAdditions.h index 206f15f8..5e22ac42 100644 --- a/Source/SPArrayAdditions.h +++ b/Source/SPArrayAdditions.h @@ -45,6 +45,7 @@ static inline void NSMutableArrayReplaceObject(NSArray *self, CFIndex idx, id an - (NSString *)componentsJoinedByPeriodAndBacktickQuoted; - (NSString *)componentsJoinedByPeriodAndBacktickQuotedAndIgnoreFirst; - (NSString *)componentsJoinedAsCSV; + - (NSArray *)subarrayWithIndexes:(NSIndexSet *)indexes; @end diff --git a/Source/SPCategoryAdditions.h b/Source/SPCategoryAdditions.h index 347dd957..daed3536 100644 --- a/Source/SPCategoryAdditions.h +++ b/Source/SPCategoryAdditions.h @@ -30,6 +30,7 @@ */ #import "SPArrayAdditions.h" +#import "SPMutableArrayAdditions.h" #import "SPStringAdditions.h" #import "SPTextViewAdditions.h" #import "SPWindowAdditions.h" 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]; diff --git a/Source/SPMutableArrayAdditions.h b/Source/SPMutableArrayAdditions.h new file mode 100644 index 00000000..c39e931a --- /dev/null +++ b/Source/SPMutableArrayAdditions.h @@ -0,0 +1,37 @@ +// +// $Id$ +// +// SPMutableArrayAdditions.h +// sequel-pro +// +// Created by Stuart Connolly (stuconnolly.com) on February 2, 2011 +// Copyright (c) 2011 Stuart Connolly. All rights reserved. +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// More info at <http://code.google.com/p/sequel-pro/> + +/** + * @category SPMutableArrayAdditionsTest SPMutableArrayAdditionsTest.h + * + * @author Stuart Connolly http://stuconnolly.com/ + * + * NSMutableArray additions category. + */ +@interface NSMutableArray (SPMutableArrayAdditions) + +- (void)reverse; + +@end diff --git a/Source/SPMutableArrayAdditions.m b/Source/SPMutableArrayAdditions.m new file mode 100644 index 00000000..529bf784 --- /dev/null +++ b/Source/SPMutableArrayAdditions.m @@ -0,0 +1,48 @@ +// +// $Id$ +// +// SPMutableArrayAdditions.m +// sequel-pro +// +// Created by Stuart Connolly (stuconnolly.com) on February 2, 2011 +// Copyright (c) 2011 Stuart Connolly. All rights reserved. +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// More info at <http://code.google.com/p/sequel-pro/> + +#import "SPMutableArrayAdditions.h" +#import "SPArrayAdditions.h" + +@implementation NSMutableArray (SPMutableArrayAdditions) + +- (void)reverse +{ + NSUInteger count = [self count]; + + for (NSUInteger i = 0; i < (count / 2); i++) + { + NSUInteger j = ((count - i) - 1); + + id obj = [NSArrayObjectAtIndex(self, i) retain]; + + [self replaceObjectAtIndex:i withObject:NSArrayObjectAtIndex(self, j)]; + [self replaceObjectAtIndex:j withObject:obj]; + + [obj release]; + } +} + +@end |