diff options
author | stuconnolly <stuart02@gmail.com> | 2009-04-09 21:53:15 +0000 |
---|---|---|
committer | stuconnolly <stuart02@gmail.com> | 2009-04-09 21:53:15 +0000 |
commit | b065a02186bd8497c503505a09ceb5a0905693cc (patch) | |
tree | 71c9d741c2ac17193c111afad9166257b7d21ce6 /Source/TableDocument.m | |
parent | 1ed9e77dff7bd74b04d6dc35849b6b644f11e2d5 (diff) | |
download | sequelpro-b065a02186bd8497c503505a09ceb5a0905693cc.tar.gz sequelpro-b065a02186bd8497c503505a09ceb5a0905693cc.tar.bz2 sequelpro-b065a02186bd8497c503505a09ceb5a0905693cc.zip |
Fix for issue #190. As the connection sheet tableview uses bindings, renaming a favourite wouldn't update the associated Keychain item. The item is now updated whenever the favourite name is changed.
Diffstat (limited to 'Source/TableDocument.m')
-rw-r--r-- | Source/TableDocument.m | 33 |
1 files changed, 32 insertions, 1 deletions
diff --git a/Source/TableDocument.m b/Source/TableDocument.m index 269af5e1..1f6f16bb 100644 --- a/Source/TableDocument.m +++ b/Source/TableDocument.m @@ -1814,7 +1814,7 @@ NSString *TableDocumentFavoritesControllerFavoritesDidChange = @"TableDocum } -// TableView datasource methods +#pragma mark TableView datasource methods - (int)numberOfRowsInTableView:(NSTableView *)aTableView { @@ -1837,6 +1837,37 @@ NSString *TableDocumentFavoritesControllerFavoritesDidChange = @"TableDocum return theValue; } +/** + * Although the connection sheet tableview uses bindings to display the favourites we implement this method in + * order to update the keychain associated with favourites that are renamed. Its not the best approach, but it works. + */ +- (void)tableView:(NSTableView *)tableView setObjectValue:(id)object forTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)rowIndex +{ + NSDictionary *favorite = [favorites objectAtIndex:rowIndex]; + + [keyChainInstance deletePasswordForName:[NSString stringWithFormat:@"Sequel Pro : %@", favoriteNamebBeingChanged] + account:[NSString stringWithFormat:@"%@@%@/%@", [favorite objectForKey:@"user"], [favorite objectForKey:@"host"], [favorite objectForKey:@"database"]]]; + + if ( ![[passwordField stringValue] isEqualToString:@""] ) + [keyChainInstance addPassword:[passwordField stringValue] + forName:[NSString stringWithFormat:@"Sequel Pro : %@", object] + account:[NSString stringWithFormat:@"%@@%@/%@", [favorite objectForKey:@"user"], [favorite objectForKey:@"host"], [favorite objectForKey:@"database"]]]; + + favoriteNamebBeingChanged = nil; +} + +/** + * We implement this method so we can get the name of the favourtie before its renamed. We need the name so we + * look it up in the keychain and update its name, which is done in the above method. This is obviously not the + * best approach to doing this as it means we need an ivar just to track the favourite that is about to be renamed. + */ +- (BOOL)tableView:(NSTableView *)tableView shouldEditTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)rowIndex +{ + favoriteNamebBeingChanged = [[favorites objectAtIndex:rowIndex] objectForKey:@"name"]; + + return YES; +} + - (IBAction)terminate:(id)sender { [[NSApp orderedDocuments] makeObjectsPerformSelector:@selector(cancelConnectSheet:) withObject:nil]; |