diff options
-rw-r--r-- | Interfaces/English.lproj/ConnectionView.xib | 18 | ||||
-rw-r--r-- | Source/SPConnectionController.m | 7 | ||||
-rw-r--r-- | Source/SPConnectionControllerDataSource.h | 37 | ||||
-rw-r--r-- | Source/SPConnectionControllerDataSource.m | 93 | ||||
-rw-r--r-- | Source/SPConnectionControllerDelegate.h | 2 | ||||
-rw-r--r-- | Source/SPConnectionControllerDelegate.m | 56 | ||||
-rw-r--r-- | Source/SPFavoriteNode.h | 2 | ||||
-rw-r--r-- | Source/SPFavoriteNode.m | 21 | ||||
-rw-r--r-- | Source/SPGroupNode.h | 2 | ||||
-rw-r--r-- | Source/SPGroupNode.m | 22 | ||||
-rw-r--r-- | Source/SPTreeNode.h | 2 | ||||
-rw-r--r-- | Source/SPTreeNode.m | 18 | ||||
-rw-r--r-- | sequel-pro.xcodeproj/project.pbxproj | 9 |
13 files changed, 223 insertions, 66 deletions
diff --git a/Interfaces/English.lproj/ConnectionView.xib b/Interfaces/English.lproj/ConnectionView.xib index 196cc9a9..7a3664ef 100644 --- a/Interfaces/English.lproj/ConnectionView.xib +++ b/Interfaces/English.lproj/ConnectionView.xib @@ -2,10 +2,10 @@ <archive type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="7.10"> <data> <int key="IBDocument.SystemTarget">1050</int> - <string key="IBDocument.SystemVersion">10H574</string> + <string key="IBDocument.SystemVersion">10J567</string> <string key="IBDocument.InterfaceBuilderVersion">823</string> <string key="IBDocument.AppKitVersion">1038.35</string> - <string key="IBDocument.HIToolboxVersion">461.00</string> + <string key="IBDocument.HIToolboxVersion">462.00</string> <object class="NSMutableDictionary" key="IBDocument.PluginVersions"> <bool key="EncodedWithXMLCoder">YES</bool> <object class="NSArray" key="dict.sortedKeys"> @@ -21,7 +21,7 @@ </object> <object class="NSMutableArray" key="IBDocument.EditedObjectIDs"> <bool key="EncodedWithXMLCoder">YES</bool> - <integer value="4915"/> + <integer value="4910"/> </object> <object class="NSArray" key="IBDocument.PluginDependencies"> <bool key="EncodedWithXMLCoder">YES</bool> @@ -155,9 +155,10 @@ </object> </object> <double key="NSRowHeight">17</double> - <int key="NSTvFlags">373293056</int> + <int key="NSTvFlags">390070272</int> <reference key="NSDelegate"/> <reference key="NSDataSource"/> + <string key="NSAutosaveName">ConnectionView</string> <int key="NSColumnAutoresizingStyle">5</int> <int key="NSDraggingSourceMaskForLocal">15</int> <int key="NSDraggingSourceMaskForNonLocal">0</int> @@ -7148,7 +7149,7 @@ <string>com.apple.InterfaceBuilder.CocoaPlugin</string> <string>com.apple.InterfaceBuilder.CocoaPlugin</string> <string>com.apple.InterfaceBuilder.CocoaPlugin</string> - <string>{{141, 131}, {882, 475}}</string> + <string>{{12, 131}, {882, 475}}</string> <string>com.apple.InterfaceBuilder.CocoaPlugin</string> <string>com.brandonwalkin.BWToolkit</string> <string>com.brandonwalkin.BWToolkit</string> @@ -7924,6 +7925,13 @@ <string key="className">SPConnectionController</string> <object class="IBClassDescriptionSource" key="sourceIdentifier"> <string key="majorKey">IBProjectSource</string> + <string key="minorKey">Source/SPConnectionControllerDataSource.h</string> + </object> + </object> + <object class="IBPartialClassDescription"> + <string key="className">SPConnectionController</string> + <object class="IBClassDescriptionSource" key="sourceIdentifier"> + <string key="majorKey">IBProjectSource</string> <string key="minorKey">Source/SPConnectionControllerDelegate.h</string> </object> </object> diff --git a/Source/SPConnectionController.m b/Source/SPConnectionController.m index 8424b427..49dcb542 100644 --- a/Source/SPConnectionController.m +++ b/Source/SPConnectionController.m @@ -167,9 +167,14 @@ static NSComparisonResult compareFavoritesUsingKey(id favorite1, id favorite2, v // Register double click action for the favorites outline view (double click favorite to connect) [favoritesOutlineView setTarget:self]; [favoritesOutlineView setDoubleAction:@selector(nodeDoubleClicked:)]; + + // Register drag types for the favorites outline view [favoritesOutlineView registerForDraggedTypes:[NSArray arrayWithObject:SPFavoritesPasteboardDragType]]; [favoritesOutlineView setDraggingSourceOperationMask:NSDragOperationMove forLocal:YES]; + // Preserve expanded group nodes + [favoritesOutlineView setAutosaveExpandedItems:YES]; + // Registered to be notified of changes to connection information [self addObserver:self forKeyPath:SPFavoriteNameKey options:(NSKeyValueObservingOptionOld | NSKeyValueObservingOptionNew) context:NULL]; [self addObserver:self forKeyPath:SPFavoriteHostKey options:(NSKeyValueObservingOptionOld | NSKeyValueObservingOptionNew) context:NULL]; @@ -1283,7 +1288,7 @@ static NSComparisonResult compareFavoritesUsingKey(id favorite1, id favorite2, v - (void)_reloadFavoritesViewData { [favoritesOutlineView reloadData]; - [favoritesOutlineView expandItem:[[favoritesRoot childNodes] objectAtIndex:0] expandChildren:YES]; + [favoritesOutlineView expandItem:[[favoritesRoot childNodes] objectAtIndex:0] expandChildren:NO]; [favoritesOutlineView scrollRowToVisible:[favoritesOutlineView selectedRow]]; } diff --git a/Source/SPConnectionControllerDataSource.h b/Source/SPConnectionControllerDataSource.h new file mode 100644 index 00000000..3f3aa7c0 --- /dev/null +++ b/Source/SPConnectionControllerDataSource.h @@ -0,0 +1,37 @@ +// +// $Id$ +// +// SPConnectionControllerDataSource.h +// sequel-pro +// +// Created by Stuart Connolly (stuconnolly.com) on February 20, 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 "SPConnectionController.h" + +/** + * @category SPConnectionControllerDelegate SPConnectionControllerDelegate.h + * + * @author Stuart Connolly http://stuconnolly.com/ + * + * Connection controller data source category. + */ +@interface SPConnectionController (SPConnectionControllerDataSource) + +@end diff --git a/Source/SPConnectionControllerDataSource.m b/Source/SPConnectionControllerDataSource.m new file mode 100644 index 00000000..9249d65d --- /dev/null +++ b/Source/SPConnectionControllerDataSource.m @@ -0,0 +1,93 @@ +// +// $Id$ +// +// SPConnectionControllerDataSource.m +// sequel-pro +// +// Created by Stuart Connolly (stuconnolly.com) on February 20, 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 "SPConnectionControllerDataSource.h" + +@implementation SPConnectionController (SPConnectionControllerDataSource) + +- (NSInteger)outlineView:(NSOutlineView *)outlineView numberOfChildrenOfItem:(id)item +{ + SPTreeNode *node = (item == nil ? favoritesRoot : (SPTreeNode *)item); + + return [[node childNodes] count]; +} + +- (id)outlineView:(NSOutlineView *)outlineView child:(NSInteger)index ofItem:(id)item +{ + SPTreeNode *node = (item == nil ? favoritesRoot : (SPTreeNode *)item); + + return NSArrayObjectAtIndex([node childNodes], index); +} + +- (BOOL)outlineView:(NSOutlineView *)outlineView isItemExpandable:(id)item +{ + return [(SPTreeNode *)item isGroup]; +} + +- (id)outlineView:(NSOutlineView *)outlineView objectValueForTableColumn:(NSTableColumn *)tableColumn byItem:(id)item +{ + SPTreeNode *node = (SPTreeNode *)item; + + return (![node isGroup]) ? [[[node representedObject] nodeFavorite] objectForKey:SPFavoriteNameKey] : [[node representedObject] nodeName]; +} + +- (void)outlineView:(NSOutlineView *)outlineView setObjectValue:(id)object forTableColumn:(NSTableColumn *)tableColumn byItem:(id)item +{ + // Trim whitespace + NSString *newName = [object stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]]; + + if ([newName length]) { + + // Get the node that was renamed + SPTreeNode *node = [self selectedFavoriteNode]; + + if (![node isGroup]) { + // Updating the name triggers a KVO update + [self setName:newName]; + + // Update associated Keychain items + [self _updateFavoritePasswordsFromField:nil]; + } + else { + [[node representedObject] setNodeName:newName]; + + [favoritesController saveFavorites]; + + [self _reloadFavoritesViewData]; + } + } +} + +- (id)outlineView:(NSOutlineView *)outlineView itemForPersistentObject:(id)object +{ + return [NSKeyedUnarchiver unarchiveObjectWithData:object]; +} + +- (id)outlineView:(NSOutlineView *)outlineView persistentObjectForItem:(id)item +{ + return [NSKeyedArchiver archivedDataWithRootObject:item]; +} + +@end diff --git a/Source/SPConnectionControllerDelegate.h b/Source/SPConnectionControllerDelegate.h index 03f13950..4936ee19 100644 --- a/Source/SPConnectionControllerDelegate.h +++ b/Source/SPConnectionControllerDelegate.h @@ -30,7 +30,7 @@ * * @author Stuart Connolly http://stuconnolly.com/ * - * Connection controller delegate/data source category. + * Connection controller delegate category. */ @interface SPConnectionController (SPConnectionControllerDelegate) diff --git a/Source/SPConnectionControllerDelegate.m b/Source/SPConnectionControllerDelegate.m index 3318958e..3aeb2da6 100644 --- a/Source/SPConnectionControllerDelegate.m +++ b/Source/SPConnectionControllerDelegate.m @@ -50,62 +50,6 @@ } #pragma mark - -#pragma mark Outline view datasource methods - -- (NSInteger)outlineView:(NSOutlineView *)outlineView numberOfChildrenOfItem:(id)item -{ - SPTreeNode *node = (item == nil ? favoritesRoot : (SPTreeNode *)item); - - return [[node childNodes] count]; -} - -- (id)outlineView:(NSOutlineView *)outlineView child:(NSInteger)index ofItem:(id)item -{ - SPTreeNode *node = (item == nil ? favoritesRoot : (SPTreeNode *)item); - - return NSArrayObjectAtIndex([node childNodes], index); -} - -- (BOOL)outlineView:(NSOutlineView *)outlineView isItemExpandable:(id)item -{ - return [(SPTreeNode *)item isGroup]; -} - -- (id)outlineView:(NSOutlineView *)outlineView objectValueForTableColumn:(NSTableColumn *)tableColumn byItem:(id)item -{ - SPTreeNode *node = (SPTreeNode *)item; - - return (![node isGroup]) ? [[[node representedObject] nodeFavorite] objectForKey:SPFavoriteNameKey] : [[node representedObject] nodeName]; -} - -- (void)outlineView:(NSOutlineView *)outlineView setObjectValue:(id)object forTableColumn:(NSTableColumn *)tableColumn byItem:(id)item -{ - // Trim whitespace - NSString *newName = [object stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]]; - - if ([newName length]) { - - // Get the node that was renamed - SPTreeNode *node = [self selectedFavoriteNode]; - - if (![node isGroup]) { - // Updating the name triggers a KVO update - [self setName:newName]; - - // Update associated Keychain items - [self _updateFavoritePasswordsFromField:nil]; - } - else { - [[node representedObject] setNodeName:newName]; - - [favoritesController saveFavorites]; - - [self _reloadFavoritesViewData]; - } - } -} - -#pragma mark - #pragma mark Outline view delegate methods - (BOOL)outlineView:(NSOutlineView *)outlineView isGroupItem:(id)item diff --git a/Source/SPFavoriteNode.h b/Source/SPFavoriteNode.h index 5387c137..a77e7dc0 100644 --- a/Source/SPFavoriteNode.h +++ b/Source/SPFavoriteNode.h @@ -30,7 +30,7 @@ * * Tree node the represents a connection favorite. */ -@interface SPFavoriteNode : NSObject <NSCopying> +@interface SPFavoriteNode : NSObject <NSCopying, NSCoding> { NSDictionary *nodeFavorite; } diff --git a/Source/SPFavoriteNode.m b/Source/SPFavoriteNode.m index 55a44653..ee40f61f 100644 --- a/Source/SPFavoriteNode.m +++ b/Source/SPFavoriteNode.m @@ -25,6 +25,9 @@ #import "SPFavoriteNode.h" +// Constants +static const NSString *SPFavoriteNodeKey = @"SPFavoriteNode"; + @implementation SPFavoriteNode @synthesize nodeFavorite; @@ -67,6 +70,24 @@ return node; } +#pragma mark - +#pragma mark Coding protocol methods + +- (id)initWithCoder:(NSCoder *)coder +{ + if ((self = [super initWithCoder:coder])) { + [self setNodeFavorite:[coder decodeObjectForKey:SPFavoriteNodeKey]]; + } + + return self; +} + +- (void)encodeWithCoder:(NSCoder *)coder +{ + [super encodeWithCoder:coder]; + + [coder encodeObject:[self nodeFavorite] forKey:SPFavoriteNodeKey]; +} #pragma mark - #pragma mark Other diff --git a/Source/SPGroupNode.h b/Source/SPGroupNode.h index e5dad641..8c4f2e84 100644 --- a/Source/SPGroupNode.h +++ b/Source/SPGroupNode.h @@ -30,7 +30,7 @@ * * Tree node that represents a group. */ -@interface SPGroupNode : NSObject <NSCopying> +@interface SPGroupNode : NSObject <NSCopying, NSCoding> { NSString *nodeName; } diff --git a/Source/SPGroupNode.m b/Source/SPGroupNode.m index 6687b29e..182a96f7 100644 --- a/Source/SPGroupNode.m +++ b/Source/SPGroupNode.m @@ -25,6 +25,9 @@ #import "SPGroupNode.h" +// Constants +static const NSString *SPGroupNodeNameKey = @"SPGroupNodeName"; + @implementation SPGroupNode @synthesize nodeName; @@ -68,6 +71,25 @@ } #pragma mark - +#pragma mark Coding protocol methods + +- (id)initWithCoder:(NSCoder *)coder +{ + if ((self = [super initWithCoder:coder])) { + [self setNodeName:[coder decodeObjectForKey:SPGroupNodeNameKey]]; + } + + return self; +} + +- (void)encodeWithCoder:(NSCoder *)coder +{ + [super encodeWithCoder:coder]; + + [coder encodeObject:[self nodeName] forKey:SPGroupNodeNameKey]; +} + +#pragma mark - #pragma mark Other - (NSString *)description diff --git a/Source/SPTreeNode.h b/Source/SPTreeNode.h index 62682af8..7e4290b4 100644 --- a/Source/SPTreeNode.h +++ b/Source/SPTreeNode.h @@ -30,7 +30,7 @@ * * NSTreeNode subclass which adds some convenience methods. */ -@interface SPTreeNode : NSTreeNode +@interface SPTreeNode : NSTreeNode <NSCoding> { BOOL isGroup; } diff --git a/Source/SPTreeNode.m b/Source/SPTreeNode.m index 7be4f09a..3d5f2ebc 100644 --- a/Source/SPTreeNode.m +++ b/Source/SPTreeNode.m @@ -27,6 +27,9 @@ #import "SPFavoriteNode.h" #import "SPGroupNode.h" +// Constants +static const NSString *SPTreeNodeIsGroupKey = @"SPTreeNodeIsGroup"; + @implementation SPTreeNode @synthesize isGroup; @@ -248,6 +251,21 @@ } #pragma mark - +#pragma mark Coding protocol methods + +- (id)initWithCoder:(NSCoder *)coder +{ + [self setIsGroup:[[coder decodeObjectForKey:SPTreeNodeIsGroupKey] boolValue]]; + + return self; +} + +- (void)encodeWithCoder:(NSCoder *)coder +{ + [coder encodeObject:[NSNumber numberWithBool:[self isGroup]] forKey:SPTreeNodeIsGroupKey]; +} + +#pragma mark - #pragma mark Other - (NSString *)description diff --git a/sequel-pro.xcodeproj/project.pbxproj b/sequel-pro.xcodeproj/project.pbxproj index 88d124a9..8d7db6c0 100644 --- a/sequel-pro.xcodeproj/project.pbxproj +++ b/sequel-pro.xcodeproj/project.pbxproj @@ -37,6 +37,7 @@ 11C211271180EC0400758039 /* SPDatabaseRename.m in Sources */ = {isa = PBXBuildFile; fileRef = 11C2109D1180E70800758039 /* SPDatabaseRename.m */; }; 11C211301180EC9A00758039 /* SPDatabaseRename.m in Sources */ = {isa = PBXBuildFile; fileRef = 11C2109D1180E70800758039 /* SPDatabaseRename.m */; }; 11D44DF0118F5887002AA43C /* OCMock.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 11D44DEF118F5887002AA43C /* OCMock.framework */; }; + 170EAA301311B7AA000AE5FE /* SPConnectionControllerDataSource.m in Sources */ = {isa = PBXBuildFile; fileRef = 170EAA2F1311B7AA000AE5FE /* SPConnectionControllerDataSource.m */; }; 171312CE109D23C700FB465F /* SPTableTextFieldCell.m in Sources */ = {isa = PBXBuildFile; fileRef = 171312CD109D23C700FB465F /* SPTableTextFieldCell.m */; }; 17148565125F5FF500321285 /* SPDatabaseCharacterSets.m in Sources */ = {isa = PBXBuildFile; fileRef = 17148564125F5FF500321285 /* SPDatabaseCharacterSets.m */; }; 1723F08B12F1F9350008253B /* SPWindow.m in Sources */ = {isa = PBXBuildFile; fileRef = 1723F08A12F1F9350008253B /* SPWindow.m */; }; @@ -569,6 +570,8 @@ 11C210DD1180E9B800758039 /* SPDatabaseRenameTest.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SPDatabaseRenameTest.h; sourceTree = "<group>"; }; 11C210DE1180E9B800758039 /* SPDatabaseRenameTest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SPDatabaseRenameTest.m; sourceTree = "<group>"; }; 11D44DEF118F5887002AA43C /* OCMock.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = OCMock.framework; path = Frameworks/OCMock.framework; sourceTree = "<group>"; }; + 170EAA2E1311B7AA000AE5FE /* SPConnectionControllerDataSource.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SPConnectionControllerDataSource.h; sourceTree = "<group>"; }; + 170EAA2F1311B7AA000AE5FE /* SPConnectionControllerDataSource.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SPConnectionControllerDataSource.m; sourceTree = "<group>"; }; 17128B8A0FE6E0210035DD75 /* QLPreviewPanel.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = QLPreviewPanel.h; sourceTree = "<group>"; }; 1713122F109C7DF600FB465F /* build.sh */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.script.sh; path = build.sh; sourceTree = "<group>"; }; 171312CC109D23C700FB465F /* SPTableTextFieldCell.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SPTableTextFieldCell.h; sourceTree = "<group>"; }; @@ -1778,6 +1781,8 @@ 5822C9B41000DB2400DCC3D6 /* SPConnectionController.m */, 17D3C6021289BF350047709F /* SPConnectionControllerDelegate.h */, 17D3C6031289BF350047709F /* SPConnectionControllerDelegate.m */, + 170EAA2E1311B7AA000AE5FE /* SPConnectionControllerDataSource.h */, + 170EAA2F1311B7AA000AE5FE /* SPConnectionControllerDataSource.m */, 17D38FC3127B0CFC00672B13 /* SPConnectionControllerDelegateProtocol.h */, ); name = "Connection View"; @@ -3226,6 +3231,7 @@ 17AF739D12AAABDD00C54D6A /* SPChooseMenuItemDialog.m in Sources */, 1723F08B12F1F9350008253B /* SPWindow.m in Sources */, 1791352712F9ED16000B27C1 /* SPMutableArrayAdditions.m in Sources */, + 170EAA301311B7AA000AE5FE /* SPConnectionControllerDataSource.m in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -3913,6 +3919,7 @@ PREBINDING = NO; SDKROOT = macosx10.5; VALID_ARCHS = "i386 ppc x86_64"; + WARNING_CFLAGS = ""; }; name = Distribution; }; @@ -4244,6 +4251,7 @@ SDKROOT = macosx10.5; STRIP_INSTALLED_PRODUCT = NO; VALID_ARCHS = "i386 ppc x86_64"; + WARNING_CFLAGS = ""; }; name = Debug; }; @@ -4289,6 +4297,7 @@ PREBINDING = NO; SDKROOT = macosx10.5; VALID_ARCHS = "i386 ppc x86_64"; + WARNING_CFLAGS = ""; }; name = Release; }; |