From 7d7fdfc8b675ac827fb29577ef491ff075589b59 Mon Sep 17 00:00:00 2001 From: rowanbeentje Date: Tue, 9 Oct 2012 22:19:26 +0000 Subject: Connection interface tweaks: - When adding a new connection and name editing is entered, accept name changes without validating hostnames etc - When deleting groups of nodes, ensure that passwords for child nodes are correctly removed from the Keychain - Add remove item, rename item, and duplicate item entries to the connection interface gear menu (matching the contextual menu) --- Interfaces/English.lproj/ConnectionView.xib | 156 +++++++++++++++++++++++++++- Source/SPConnectionController.m | 94 ++++++++++------- Source/SPConnectionControllerDataSource.m | 2 +- 3 files changed, 209 insertions(+), 43 deletions(-) diff --git a/Interfaces/English.lproj/ConnectionView.xib b/Interfaces/English.lproj/ConnectionView.xib index f657096a..168081e7 100644 --- a/Interfaces/English.lproj/ConnectionView.xib +++ b/Interfaces/English.lproj/ConnectionView.xib @@ -13,6 +13,7 @@ YES + YES @@ -188,6 +189,60 @@ YES + + + Rename + + 2147483647 + + + _popUpItemAction: + + + + + Remove + + 2147483647 + + + _popUpItemAction: + + + + + YES + YES + + + 2147483647 + + + _popUpItemAction: + + + + + Duplicate + + 2147483647 + + + _popUpItemAction: + + + + + YES + YES + + + 2147483647 + + + _popUpItemAction: + + Import... @@ -220,6 +275,16 @@ _popUpItemAction: + + + Make Default + + 2147483647 + + + _popUpItemAction: + + Sort By @@ -292,6 +357,7 @@ + 9 YES 1 YES @@ -4995,6 +5061,38 @@ 5882 + + + duplicateFavorite: + + + + 5888 + + + + makeSelectedFavoriteDefault: + + + + 5889 + + + + renameNode: + + + + 5890 + + + + removeNode: + + + + 5891 + @@ -6623,6 +6721,12 @@ + + + + + + @@ -6788,6 +6892,36 @@ + + 5883 + + + + + 5884 + + + + + 5885 + + + + + 5886 + + + + + 5887 + + + + + 5892 + + + @@ -7108,6 +7242,12 @@ 5866.IBPluginDependency 5869.IBPluginDependency 5870.IBPluginDependency + 5883.IBPluginDependency + 5884.IBPluginDependency + 5885.IBPluginDependency + 5886.IBPluginDependency + 5887.IBPluginDependency + 5892.IBPluginDependency YES @@ -7605,7 +7745,7 @@ P4AAAL+AAABDGQAAwgAAAA com.apple.InterfaceBuilder.CocoaPlugin - {{461, 362}, {142, 123}} + {{64, 53}, {142, 123}} com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin @@ -7631,7 +7771,7 @@ P4AAAL+AAABB8AAAwbAAAA com.apple.InterfaceBuilder.CocoaPlugin - {{146, 300}, {116, 89}} + {{146, 175}, {131, 177}} com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin @@ -7690,6 +7830,12 @@ com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin @@ -7708,7 +7854,7 @@ - 5882 + 5892 @@ -9338,8 +9484,8 @@ {32, 23} {15, 23} {10, 23} - {16, 8} - {16, 8} + {16, 9} + {16, 9} diff --git a/Source/SPConnectionController.m b/Source/SPConnectionController.m index 12ead317..15e68f41 100644 --- a/Source/SPConnectionController.m +++ b/Source/SPConnectionController.m @@ -71,7 +71,7 @@ static NSString *SPExportFavoritesFilename = @"SequelProFavorites.plist"; // Privately redeclare as read/write to get the synthesized setter @property (readwrite, assign) BOOL isEditingConnection; -- (void)_saveCurrentDetailsCreatingNewFavorite:(BOOL)createNewFavorite; +- (void)_saveCurrentDetailsCreatingNewFavorite:(BOOL)createNewFavorite validateDetails:(BOOL)validateDetails; - (BOOL)_checkHost; #ifndef SP_REFACTOR - (void)_sortFavorites; @@ -83,6 +83,7 @@ static NSString *SPExportFavoritesFilename = @"SequelProFavorites.plist"; - (void)_selectNode:(SPTreeNode *)node; - (void)_scrollToSelectedNode; - (void)_removeNode:(SPTreeNode *)node; +- (void)_removeAllPasswordsForNode:(SPTreeNode *)node; - (NSNumber *)_createNewFavoriteID; - (SPTreeNode *)_favoriteNodeForFavoriteID:(NSInteger)favoriteID; @@ -676,7 +677,7 @@ static NSComparisonResult _compareFavoritesUsingKey(id favorite1, id favorite2, */ - (IBAction)saveFavorite:(id)sender { - [self _saveCurrentDetailsCreatingNewFavorite:NO]; + [self _saveCurrentDetailsCreatingNewFavorite:NO validateDetails:YES]; } /** @@ -742,7 +743,7 @@ static NSComparisonResult _compareFavoritesUsingKey(id favorite1, id favorite2, */ - (IBAction)addFavoriteUsingCurrentDetails:(id)sender { - [self _saveCurrentDetailsCreatingNewFavorite:YES]; + [self _saveCurrentDetailsCreatingNewFavorite:YES validateDetails:YES]; } /** @@ -1073,7 +1074,7 @@ static NSComparisonResult _compareFavoritesUsingKey(id favorite1, id favorite2, * If creating a new favourite, also select it and ensure the selected * favourite is visible. */ -- (void)_saveCurrentDetailsCreatingNewFavorite:(BOOL)createNewFavorite +- (void)_saveCurrentDetailsCreatingNewFavorite:(BOOL)createNewFavorite validateDetails:(BOOL)validateDetails { // Complete any active editing @@ -1083,7 +1084,7 @@ static NSComparisonResult _compareFavoritesUsingKey(id favorite1, id favorite2, // Ensure that host is not empty if this is a TCP/IP or SSH connection - if (([self type] == SPTCPIPConnection || [self type] == SPSSHTunnelConnection) && ![[self host] length]) { + if (validateDetails && ([self type] == SPTCPIPConnection || [self type] == SPSSHTunnelConnection) && ![[self host] length]) { SPBeginAlertSheet(NSLocalizedString(@"Insufficient connection details", @"insufficient details message"), NSLocalizedString(@"OK", @"OK button"), nil, nil, [dbDocument parentWindow], nil, nil, nil, NSLocalizedString(@"Insufficient details provided to establish a connection. Please provide at least a host.", @"insufficient details informative message")); @@ -1091,7 +1092,7 @@ static NSComparisonResult _compareFavoritesUsingKey(id favorite1, id favorite2, } // If SSH is enabled, ensure that the SSH host is not nil - if ([self type] == SPSSHTunnelConnection && ![[self sshHost] length]) { + if (validateDetails && [self type] == SPSSHTunnelConnection && ![[self sshHost] length]) { SPBeginAlertSheet(NSLocalizedString(@"Insufficient connection details", @"insufficient details message"), NSLocalizedString(@"OK", @"OK button"), nil, nil, [dbDocument parentWindow], nil, nil, nil, NSLocalizedString(@"Please enter the hostname for the SSH Tunnel, or disable the SSH Tunnel.", @"message of panel when ssh details are incomplete")); @@ -1574,35 +1575,8 @@ static NSComparisonResult _compareFavoritesUsingKey(id favorite1, id favorite2, */ - (void)_removeNode:(SPTreeNode *)node { - if (![node isGroup]) { - NSDictionary *favorite = [[node representedObject] nodeFavorite]; - - // Get selected favorite's details - NSString *favoriteName = [favorite objectForKey:SPFavoriteNameKey]; - NSString *favoriteUser = [favorite objectForKey:SPFavoriteUserKey]; - NSString *favoriteHost = [favorite objectForKey:SPFavoriteHostKey]; - NSString *favoriteDatabase = [favorite objectForKey:SPFavoriteDatabaseKey]; - NSString *favoriteSSHUser = [favorite objectForKey:SPFavoriteSSHUserKey]; - NSString *favoriteSSHHost = [favorite objectForKey:SPFavoriteSSHHostKey]; - NSString *favoriteID = [favorite objectForKey:SPFavoriteIDKey]; - - // Remove passwords from the Keychain - [keychain deletePasswordForName:[keychain nameForFavoriteName:favoriteName id:favoriteID] - account:[keychain accountForUser:favoriteUser host:((type == SPSocketConnection) ? @"localhost" : favoriteHost) database:favoriteDatabase]]; - [keychain deletePasswordForName:[keychain nameForSSHForFavoriteName:favoriteName id:favoriteID] - account:[keychain accountForSSHUser:favoriteSSHUser sshHost:favoriteSSHHost]]; - - // Reset last used favorite - if ([[favorite objectForKey:SPFavoriteIDKey] integerValue] == [prefs integerForKey:SPLastFavoriteID]) { - [prefs setInteger:0 forKey:SPLastFavoriteID]; - } - - // If required, reset the default favorite - if ([[favorite objectForKey:SPFavoriteIDKey] integerValue] == [prefs integerForKey:SPDefaultFavorite]) { - [prefs setInteger:[prefs integerForKey:SPLastFavoriteID] forKey:SPDefaultFavorite]; - } - } - + [self _removeAllPasswordsForNode:node]; + [favoritesController removeFavoriteNode:node]; [self _reloadFavoritesViewData]; @@ -1617,6 +1591,52 @@ static NSComparisonResult _compareFavoritesUsingKey(id favorite1, id favorite2, [[(SPPreferenceController *)[[NSApp delegate] preferenceController] generalPreferencePane] updateDefaultFavoritePopup]; } +/** + * Removes all passwords for the supplied tree node and any child nodes. + * + * @param node The node to remove all passwords within and for. + */ +- (void)_removeAllPasswordsForNode:(SPTreeNode *)node +{ + + // If the supplied node is a group node, remove all passwords for any children + if ([node isGroup]) { + for (SPTreeNode *childNode in [node childNodes]) { + [self _removeAllPasswordsForNode:childNode]; + } + return; + } + + // Otherwise, remove details for the supplied node. + + NSDictionary *favorite = [[node representedObject] nodeFavorite]; + + // Get selected favorite's details + NSString *favoriteName = [favorite objectForKey:SPFavoriteNameKey]; + NSString *favoriteUser = [favorite objectForKey:SPFavoriteUserKey]; + NSString *favoriteHost = [favorite objectForKey:SPFavoriteHostKey]; + NSString *favoriteDatabase = [favorite objectForKey:SPFavoriteDatabaseKey]; + NSString *favoriteSSHUser = [favorite objectForKey:SPFavoriteSSHUserKey]; + NSString *favoriteSSHHost = [favorite objectForKey:SPFavoriteSSHHostKey]; + NSString *favoriteID = [favorite objectForKey:SPFavoriteIDKey]; + + // Remove passwords from the Keychain + [keychain deletePasswordForName:[keychain nameForFavoriteName:favoriteName id:favoriteID] + account:[keychain accountForUser:favoriteUser host:((type == SPSocketConnection) ? @"localhost" : favoriteHost) database:favoriteDatabase]]; + [keychain deletePasswordForName:[keychain nameForSSHForFavoriteName:favoriteName id:favoriteID] + account:[keychain accountForSSHUser:favoriteSSHUser sshHost:favoriteSSHHost]]; + + // Reset last used favorite + if ([[favorite objectForKey:SPFavoriteIDKey] integerValue] == [prefs integerForKey:SPLastFavoriteID]) { + [prefs setInteger:0 forKey:SPLastFavoriteID]; + } + + // If required, reset the default favorite + if ([[favorite objectForKey:SPFavoriteIDKey] integerValue] == [prefs integerForKey:SPDefaultFavorite]) { + [prefs setInteger:[prefs integerForKey:SPLastFavoriteID] forKey:SPDefaultFavorite]; + } +} + /** * Creates a new favorite ID based on the UNIX epoch time. */ @@ -1698,8 +1718,8 @@ static NSComparisonResult _compareFavoritesUsingKey(id favorite1, id favorite2, // Fade and move the edit button area in [editButtonsView setAlphaValue:0.0]; [editButtonsView setHidden:NO]; - [editButtonsView setFrameOrigin:NSMakePoint([editButtonsView frame].origin.x, [editButtonsView frame].origin.y - 40)]; - [[editButtonsView animator] setFrameOrigin:NSMakePoint([editButtonsView frame].origin.x, [editButtonsView frame].origin.y + 40)]; + [editButtonsView setFrameOrigin:NSMakePoint([editButtonsView frame].origin.x, [editButtonsView frame].origin.y - 30)]; + [[editButtonsView animator] setFrameOrigin:NSMakePoint([editButtonsView frame].origin.x, [editButtonsView frame].origin.y + 30)]; [[editButtonsView animator] setAlphaValue:1.0]; // Update the "Save" button state as appropriate diff --git a/Source/SPConnectionControllerDataSource.m b/Source/SPConnectionControllerDataSource.m index d7f3d235..a318db85 100644 --- a/Source/SPConnectionControllerDataSource.m +++ b/Source/SPConnectionControllerDataSource.m @@ -111,7 +111,7 @@ // Updating the name triggers a KVO update [self setName:newName]; - [self saveFavorite:self]; + [self _saveCurrentDetailsCreatingNewFavorite:NO validateDetails:NO]; } else { [[node representedObject] setNodeName:newName]; -- cgit v1.2.3