diff options
author | rowanbeentje <rowan@beent.je> | 2012-10-09 22:19:26 +0000 |
---|---|---|
committer | rowanbeentje <rowan@beent.je> | 2012-10-09 22:19:26 +0000 |
commit | 7d7fdfc8b675ac827fb29577ef491ff075589b59 (patch) | |
tree | bef7e216f691694ec1c9efa293b5ee4dd22e6312 /Source | |
parent | bab9704df5bf5fa2412ff6fd47cb71f5ddd6c23c (diff) | |
download | sequelpro-7d7fdfc8b675ac827fb29577ef491ff075589b59.tar.gz sequelpro-7d7fdfc8b675ac827fb29577ef491ff075589b59.tar.bz2 sequelpro-7d7fdfc8b675ac827fb29577ef491ff075589b59.zip |
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)
Diffstat (limited to 'Source')
-rw-r--r-- | Source/SPConnectionController.m | 94 | ||||
-rw-r--r-- | Source/SPConnectionControllerDataSource.m | 2 |
2 files changed, 58 insertions, 38 deletions
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]; @@ -1618,6 +1592,52 @@ static NSComparisonResult _compareFavoritesUsingKey(id favorite1, id favorite2, } /** + * 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. */ - (NSNumber *)_createNewFavoriteID @@ -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]; |