aboutsummaryrefslogtreecommitdiffstats
path: root/Source/SPPreferenceController.m
diff options
context:
space:
mode:
authorrowanbeentje <rowan@beent.je>2009-04-13 00:42:54 +0000
committerrowanbeentje <rowan@beent.je>2009-04-13 00:42:54 +0000
commit8df357943f349909e7c835dba7ac081d84dc4d86 (patch)
tree9af7bdcf8b3b4ede93e017379635ab5eed53871a /Source/SPPreferenceController.m
parent28d6a391d760b4acbac219d11b6ae8abf97e7ccf (diff)
downloadsequelpro-8df357943f349909e7c835dba7ac081d84dc4d86.tar.gz
sequelpro-8df357943f349909e7c835dba7ac081d84dc4d86.tar.bz2
sequelpro-8df357943f349909e7c835dba7ac081d84dc4d86.zip
- Save password changes when making changes in favorites tab in the preferences window
- Remove the now unnecessary (and never implemented) "Save" button below the favorites editor - Hook up the Remove and Duplicate favorite buttons to the correct Enable binding
Diffstat (limited to 'Source/SPPreferenceController.m')
-rw-r--r--Source/SPPreferenceController.m78
1 files changed, 78 insertions, 0 deletions
diff --git a/Source/SPPreferenceController.m b/Source/SPPreferenceController.m
index d287fcef..5daf7f37 100644
--- a/Source/SPPreferenceController.m
+++ b/Source/SPPreferenceController.m
@@ -547,8 +547,86 @@
[super dealloc];
}
+
+#pragma mark -
+#pragma mark TextField delegate methods
+
+// -------------------------------------------------------------------------------
+// control:textShouldEndEditing:
+// Trap editing end notifications and use them to update the keychain password
+// appropriately when name, host, user, password or database changes.
+// -------------------------------------------------------------------------------
+- (BOOL)control:(NSControl *)control textShouldEndEditing:(NSText *)fieldEditor
+{
+ NSString *oldKeychainName, *newKeychainName;
+ NSString *oldKeychainAccount, *newKeychainAccount;
+ NSString *oldPassword;
+
+ // Only proceed for name, host, user or database changes
+ if (control != nameField && control != hostField && control != userField && control != passwordField && control != databaseField)
+ return YES;
+
+ // Set the current keychain name and account strings
+ oldKeychainName = [NSString stringWithFormat:@"Sequel Pro : %@", [favoritesController valueForKeyPath:@"selection.name"]];
+ oldKeychainAccount = [NSString stringWithFormat:@"%@@%@/%@",
+ [favoritesController valueForKeyPath:@"selection.user"],
+ [favoritesController valueForKeyPath:@"selection.host"],
+ [favoritesController valueForKeyPath:@"selection.database"]];
+
+ // Retrieve the old password
+ oldPassword = [keychain getPasswordForName:oldKeychainName account:oldKeychainAccount];
+
+ // If no details have changed, skip processing
+ if ([nameField stringValue] == [favoritesController valueForKeyPath:@"selection.name"]
+ && [hostField stringValue] == [favoritesController valueForKeyPath:@"selection.host"]
+ && [userField stringValue] == [favoritesController valueForKeyPath:@"selection.user"]
+ && [databaseField stringValue] == [favoritesController valueForKeyPath:@"selection.database"]
+ && [passwordField stringValue] == oldPassword) {
+ oldPassword = nil;
+ return YES;
+ }
+ oldPassword = nil;
+
+ // Set up the new keychain name and account strings
+ newKeychainName = [NSString stringWithFormat:@"Sequel Pro : %@", [nameField stringValue]];
+ newKeychainAccount = [NSString stringWithFormat:@"%@@%@/%@",
+ [userField stringValue],
+ [hostField stringValue],
+ [databaseField stringValue]];
+
+ // Delete the old keychain item
+ [keychain deletePasswordForName:oldKeychainName account:oldKeychainAccount];
+
+ // Add the new keychain item if the password field has a value
+ if ([passwordField stringValue])
+ [keychain addPassword:[passwordField stringValue] forName:newKeychainName account:newKeychainAccount];
+
+ // Proceed with editing
+ return YES;
+}
+
+
+#pragma mark -
+#pragma mark Window delegate methods
+
+// -------------------------------------------------------------------------------
+// windowWillClose:
+// Trap window close notifications and use them to ensure changes are saved.
+// -------------------------------------------------------------------------------
+- (void)windowWillClose:(NSNotification *)notification
+{
+
+ // Mark the currently selected field in the window as having finished editing, to trigger saves.
+ if ([preferencesWindow firstResponder])
+ [preferencesWindow endEditingFor:[preferencesWindow firstResponder]];
+}
+
+
+
@end
+
+
#pragma mark -
@implementation SPPreferenceController (PrivateAPI)