diff options
author | stuconnolly <stuart02@gmail.com> | 2010-12-08 20:58:57 +0000 |
---|---|---|
committer | stuconnolly <stuart02@gmail.com> | 2010-12-08 20:58:57 +0000 |
commit | cecdee329489a304d94630662a24a6d0145eaa1a (patch) | |
tree | f485cdd52c5ec294e2f430c2a8228317eb77b675 | |
parent | 05f91b6778fecc28add3cc2218867cf9134599e7 (diff) | |
download | sequelpro-cecdee329489a304d94630662a24a6d0145eaa1a.tar.gz sequelpro-cecdee329489a304d94630662a24a6d0145eaa1a.tar.bz2 sequelpro-cecdee329489a304d94630662a24a6d0145eaa1a.zip |
Update a connection favorite's name accordingly if it's type is changed.
-rw-r--r-- | Source/SPConnectionController.m | 11 | ||||
-rw-r--r-- | Source/SPConnectionControllerDelegate.m | 108 |
2 files changed, 58 insertions, 61 deletions
diff --git a/Source/SPConnectionController.m b/Source/SPConnectionController.m index f7a09471..f48cdc06 100644 --- a/Source/SPConnectionController.m +++ b/Source/SPConnectionController.m @@ -1199,13 +1199,11 @@ static const NSString *SPExportFavoritesFilename = @"SequelProFavorites.plist"; * Updates the favorite's host when the type changes. */ - (void)_favoriteTypeDidChange -{ - // TODO: Handle changing favorite connection types - - /*NSDictionary *favorite = [[[self selectedFavoriteNode] representedObject] nodeFavorite]; +{ + NSDictionary *favorite = [[[self selectedFavoriteNode] representedObject] nodeFavorite]; // If either socket or host is localhost, clear. - if ((selectedTabView != SPSocketConnection) && [[favorite objectForKey:SPFavoriteHostKey] isEqualToString:@"localhost"]) { + if ((previousType != SPSocketConnection) && [[favorite objectForKey:SPFavoriteHostKey] isEqualToString:@"localhost"]) { [self setHost:@""]; } @@ -1217,9 +1215,6 @@ static const NSString *SPExportFavoritesFilename = @"SequelProFavorites.plist"; (([favorite objectForKey:SPFavoriteHostKey]) ? [favorite valueForKeyPath:SPFavoriteHostKey] : @"")) ]]; } - - // Request a password refresh to keep keychain references in synch with the favorites - [self _updateFavoritePasswordsFromField:nil];*/ } /** diff --git a/Source/SPConnectionControllerDelegate.m b/Source/SPConnectionControllerDelegate.m index ee218ba3..922d2405 100644 --- a/Source/SPConnectionControllerDelegate.m +++ b/Source/SPConnectionControllerDelegate.m @@ -311,63 +311,64 @@ - (void)controlTextDidChange:(NSNotification *)notification { id field = [notification object]; - - NSMutableDictionary *favorite = [self selectedFavorite]; - - BOOL nameFieldIsEmpty = [[favorite objectForKey:SPFavoriteNameKey] isEqualToString:@""]; - - switch (previousType) - { - case SPTCPIPConnection: - - nameFieldIsEmpty = (nameFieldIsEmpty || [[standardNameField stringValue] isEqualToString:@""]); - - if (nameFieldIsEmpty || (!favoriteNameFieldWasTouched && (field == standardUserField || field == standardSQLHostField))) { - [standardNameField setStringValue:[NSString stringWithFormat:@"%@@%@", [standardUserField stringValue], [standardSQLHostField stringValue]]]; - // Trigger KVO update - [self setName:[standardNameField stringValue]]; - - // If name field is empty enable user@host update - if (nameFieldIsEmpty) favoriteNameFieldWasTouched = NO; - } - - break; - case SPSocketConnection: - - nameFieldIsEmpty = (nameFieldIsEmpty || [[socketNameField stringValue] isEqualToString:@""]); - - if (nameFieldIsEmpty || (!favoriteNameFieldWasTouched && field == socketUserField)) { - [socketNameField setStringValue:[NSString stringWithFormat:@"%@@localhost", [socketUserField stringValue]]]; + if ([self selectedFavoriteNode]) { + + BOOL nameFieldIsEmpty = [[field stringValue] isEqualToString:@""]; + + switch (previousType) + { + case SPTCPIPConnection: - // Trigger KVO update - [self setName:[socketNameField stringValue]]; + nameFieldIsEmpty = (nameFieldIsEmpty || [[standardNameField stringValue] isEqualToString:@""]); - // If name field is empty enable user@host update - if (nameFieldIsEmpty) favoriteNameFieldWasTouched = NO; - } - - break; - case SPSSHTunnelConnection: - - nameFieldIsEmpty = (nameFieldIsEmpty || [[sshNameField stringValue] isEqualToString:@""]); - - if (nameFieldIsEmpty || (!favoriteNameFieldWasTouched && (field == sshUserField || field == sshSQLHostField))) { - [sshNameField setStringValue:[NSString stringWithFormat:@"%@@%@", [sshUserField stringValue], [sshSQLHostField stringValue]]]; + if (nameFieldIsEmpty || (!favoriteNameFieldWasTouched && (field == standardUserField || field == standardSQLHostField))) { + [standardNameField setStringValue:[NSString stringWithFormat:@"%@@%@", [standardUserField stringValue], [standardSQLHostField stringValue]]]; + + // Trigger KVO update + [self setName:[standardNameField stringValue]]; + + // If name field is empty enable user@host update + if (nameFieldIsEmpty) favoriteNameFieldWasTouched = NO; + } - // Trigger KVO update - [self setName:[sshNameField stringValue]]; + break; + case SPSocketConnection: - // If name field is empty enable user@host update - if (nameFieldIsEmpty) favoriteNameFieldWasTouched = NO; - } - - break; - default: - break; + nameFieldIsEmpty = (nameFieldIsEmpty || [[socketNameField stringValue] isEqualToString:@""]); + + if (nameFieldIsEmpty || (!favoriteNameFieldWasTouched && field == socketUserField)) { + [socketNameField setStringValue:[NSString stringWithFormat:@"%@@localhost", [socketUserField stringValue]]]; + + // Trigger KVO update + [self setName:[socketNameField stringValue]]; + + // If name field is empty enable user@host update + if (nameFieldIsEmpty) favoriteNameFieldWasTouched = NO; + } + + break; + case SPSSHTunnelConnection: + + nameFieldIsEmpty = (nameFieldIsEmpty || [[sshNameField stringValue] isEqualToString:@""]); + + if (nameFieldIsEmpty || (!favoriteNameFieldWasTouched && (field == sshUserField || field == sshSQLHostField))) { + [sshNameField setStringValue:[NSString stringWithFormat:@"%@@%@", [sshUserField stringValue], [sshSQLHostField stringValue]]]; + + // Trigger KVO update + [self setName:[sshNameField stringValue]]; + + // If name field is empty enable user@host update + if (nameFieldIsEmpty) favoriteNameFieldWasTouched = NO; + } + + break; + default: + break; + } + + if ((field == standardNameField) || (field == socketNameField) || (field == sshNameField)) favoriteNameFieldWasTouched = YES; } - - if ((field == standardNameField) || (field == socketNameField) || (field == sshNameField)) favoriteNameFieldWasTouched = YES; } /** @@ -387,8 +388,9 @@ */ - (BOOL)control:(NSControl *)control textShouldEndEditing:(NSText *)fieldEditor { - if (control != favoritesOutlineView) { - // Request a password refresh to keep keychain references in synch with favorites + // Request a password refresh to keep keychain references in synch with favorites, but only if a favorite + // is selected, meaning we're editing an existing one, not a new one. + if ((control != favoritesOutlineView) && ([self selectedFavoriteNode])) { [self _updateFavoritePasswordsFromField:control]; } |