diff options
-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 | ||||
-rw-r--r-- | UnitTests/SPMutableArrayAdditionsTest.h | 37 | ||||
-rw-r--r-- | UnitTests/SPMutableArrayAdditionsTest.m | 41 | ||||
-rw-r--r-- | sequel-pro.xcodeproj/project.pbxproj | 12 |
8 files changed, 198 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 diff --git a/UnitTests/SPMutableArrayAdditionsTest.h b/UnitTests/SPMutableArrayAdditionsTest.h new file mode 100644 index 00000000..a7665a27 --- /dev/null +++ b/UnitTests/SPMutableArrayAdditionsTest.h @@ -0,0 +1,37 @@ +// +// $Id$ +// +// SPMutableArrayAdditionsTest.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/> + +#import <SenTestingKit/SenTestingKit.h> + +/** + * @class SPMutableArrayAdditionsTest SPMutableArrayAdditionsTest.h + * + * @author Stuart Connolly http://stuconnolly.com/ + * + * SPMutableArrayAdditions tests class. + */ +@interface SPMutableArrayAdditionsTest : SenTestCase + +@end diff --git a/UnitTests/SPMutableArrayAdditionsTest.m b/UnitTests/SPMutableArrayAdditionsTest.m new file mode 100644 index 00000000..4f265b34 --- /dev/null +++ b/UnitTests/SPMutableArrayAdditionsTest.m @@ -0,0 +1,41 @@ +// +// $Id$ +// +// SPMutableArrayAdditionsTest.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 "SPMutableArrayAdditionsTest.h" +#import "SPMutableArrayAdditions.h" + +@implementation SPMutableArrayAdditionsTest + +- (void)testReverse +{ + NSMutableArray *testArray = [NSMutableArray arrayWithObjects:@"1", @"2", @"3", @"4", @"5", nil]; + NSMutableArray *expectedArray = [NSMutableArray arrayWithObjects:@"5", @"4", @"3", @"2", @"1", nil]; + + [testArray reverse]; + + STAssertEqualObjects(testArray, expectedArray, @"The reversed array should look like: %@", expectedArray); +} + +@end diff --git a/sequel-pro.xcodeproj/project.pbxproj b/sequel-pro.xcodeproj/project.pbxproj index fdd5ef86..88d124a9 100644 --- a/sequel-pro.xcodeproj/project.pbxproj +++ b/sequel-pro.xcodeproj/project.pbxproj @@ -77,6 +77,8 @@ 1785EB66127DD5EA00F468C8 /* SPNetworkPreferencePane.m in Sources */ = {isa = PBXBuildFile; fileRef = 1785EB65127DD5EA00F468C8 /* SPNetworkPreferencePane.m */; }; 1785EB6A127DD79300F468C8 /* SPEditorPreferencePane.m in Sources */ = {isa = PBXBuildFile; fileRef = 1785EB69127DD79300F468C8 /* SPEditorPreferencePane.m */; }; 1789343C0F30C1DD0097539A /* SPStringAdditions.m in Sources */ = {isa = PBXBuildFile; fileRef = 1789343B0F30C1DD0097539A /* SPStringAdditions.m */; }; + 1791352712F9ED16000B27C1 /* SPMutableArrayAdditions.m in Sources */ = {isa = PBXBuildFile; fileRef = 1791352612F9ED16000B27C1 /* SPMutableArrayAdditions.m */; }; + 1791353C12F9F052000B27C1 /* SPMutableArrayAdditionsTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 1791353B12F9F052000B27C1 /* SPMutableArrayAdditionsTest.m */; }; 1792C13210AD752100ABE758 /* DatabaseServerVariables.xib in Resources */ = {isa = PBXBuildFile; fileRef = 1792C13010AD752100ABE758 /* DatabaseServerVariables.xib */; }; 1792C13710AD75C800ABE758 /* SPServerVariablesController.m in Sources */ = {isa = PBXBuildFile; fileRef = 1792C13610AD75C800ABE758 /* SPServerVariablesController.m */; }; 1792C26110AE1A2D00ABE758 /* SPConnectionDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 1792C26010AE1A2D00ABE758 /* SPConnectionDelegate.m */; }; @@ -651,6 +653,10 @@ 1789343B0F30C1DD0097539A /* SPStringAdditions.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SPStringAdditions.m; sourceTree = "<group>"; }; 178934980F30CDA10097539A /* trim-application.sh */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.script.sh; path = "trim-application.sh"; sourceTree = "<group>"; }; 1791346512F75CC1000B27C1 /* README */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = README; sourceTree = "<group>"; }; + 1791352512F9ED16000B27C1 /* SPMutableArrayAdditions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SPMutableArrayAdditions.h; sourceTree = "<group>"; }; + 1791352612F9ED16000B27C1 /* SPMutableArrayAdditions.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SPMutableArrayAdditions.m; sourceTree = "<group>"; }; + 1791353A12F9F052000B27C1 /* SPMutableArrayAdditionsTest.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SPMutableArrayAdditionsTest.h; sourceTree = "<group>"; }; + 1791353B12F9F052000B27C1 /* SPMutableArrayAdditionsTest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SPMutableArrayAdditionsTest.m; sourceTree = "<group>"; }; 1792C13110AD752100ABE758 /* English */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = English; path = Interfaces/English.lproj/DatabaseServerVariables.xib; sourceTree = "<group>"; }; 1792C13510AD75C800ABE758 /* SPServerVariablesController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SPServerVariablesController.h; sourceTree = "<group>"; }; 1792C13610AD75C800ABE758 /* SPServerVariablesController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SPServerVariablesController.m; sourceTree = "<group>"; }; @@ -1887,6 +1893,8 @@ children = ( 380F4EF30FC0B68F00B0BFD7 /* SPStringAdditionsTest.h */, 380F4EF40FC0B68F00B0BFD7 /* SPStringAdditionsTest.m */, + 1791353A12F9F052000B27C1 /* SPMutableArrayAdditionsTest.h */, + 1791353B12F9F052000B27C1 /* SPMutableArrayAdditionsTest.m */, ); name = "Category Additions"; sourceTree = "<group>"; @@ -2507,6 +2515,8 @@ 175EC64C12733CDF009A7C0F /* SPCategoryAdditions.h */, B52460D30F8EF92300171639 /* SPArrayAdditions.h */, B52460D40F8EF92300171639 /* SPArrayAdditions.m */, + 1791352512F9ED16000B27C1 /* SPMutableArrayAdditions.h */, + 1791352612F9ED16000B27C1 /* SPMutableArrayAdditions.m */, 1789343A0F30C1DD0097539A /* SPStringAdditions.h */, 1789343B0F30C1DD0097539A /* SPStringAdditions.m */, 58DC10D112A1B8DF00B76DA5 /* SPMenuAdditions.h */, @@ -3010,6 +3020,7 @@ 380F4EF50FC0B68F00B0BFD7 /* SPStringAdditionsTest.m in Sources */, 1198F5C41174EF3F00670590 /* SPDatabaseCopyTest.m in Sources */, 17AF72DD12A88CBA00C54D6A /* MCPKitTest.m in Sources */, + 1791353C12F9F052000B27C1 /* SPMutableArrayAdditionsTest.m in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -3214,6 +3225,7 @@ 17AF713912A842DE00C54D6A /* SPFlippedView.m in Sources */, 17AF739D12AAABDD00C54D6A /* SPChooseMenuItemDialog.m in Sources */, 1723F08B12F1F9350008253B /* SPWindow.m in Sources */, + 1791352712F9ED16000B27C1 /* SPMutableArrayAdditions.m in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; |