From b065a02186bd8497c503505a09ceb5a0905693cc Mon Sep 17 00:00:00 2001 From: stuconnolly Date: Thu, 9 Apr 2009 21:53:15 +0000 Subject: 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. --- Source/TableDocument.h | 1 + Source/TableDocument.m | 33 ++++++++++++++++++++++++++++++++- 2 files changed, 33 insertions(+), 1 deletion(-) (limited to 'Source') diff --git a/Source/TableDocument.h b/Source/TableDocument.h index 299e5430..b9426e31 100644 --- a/Source/TableDocument.h +++ b/Source/TableDocument.h @@ -85,6 +85,7 @@ NSString *selectedDatabase; NSString *mySQLVersion; NSUserDefaults *prefs; + NSString *favoriteNamebBeingChanged; NSMenu *selectEncodingMenu; BOOL _supportsEncoding; 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]; -- cgit v1.2.3