aboutsummaryrefslogtreecommitdiffstats
path: root/Source
diff options
context:
space:
mode:
authorstuconnolly <stuart02@gmail.com>2009-04-09 21:53:15 +0000
committerstuconnolly <stuart02@gmail.com>2009-04-09 21:53:15 +0000
commitb065a02186bd8497c503505a09ceb5a0905693cc (patch)
tree71c9d741c2ac17193c111afad9166257b7d21ce6 /Source
parent1ed9e77dff7bd74b04d6dc35849b6b644f11e2d5 (diff)
downloadsequelpro-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')
-rw-r--r--Source/TableDocument.h1
-rw-r--r--Source/TableDocument.m33
2 files changed, 33 insertions, 1 deletions
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];