aboutsummaryrefslogtreecommitdiffstats
path: root/TableDocument.m
diff options
context:
space:
mode:
Diffstat (limited to 'TableDocument.m')
-rw-r--r--TableDocument.m56
1 files changed, 38 insertions, 18 deletions
diff --git a/TableDocument.m b/TableDocument.m
index 686bf8a0..9623bdb2 100644
--- a/TableDocument.m
+++ b/TableDocument.m
@@ -198,25 +198,15 @@ reused when user hits the close button of the variablseSheet or of the createTab
*/
- (IBAction)chooseFavorite:(id)sender
{
- if ([[prefs objectForKey:@"favorites"] count] == 0)
- return;
+ if (![self selectedFavorite])
+ return;
- NSDictionary *favorite = [[prefs objectForKey:@"favorites"] objectAtIndex:[favoritesController selectionIndex]];
- NSString *name = [favorite objectForKey:@"name"];
- NSString *host = [favorite objectForKey:@"host"];
- NSString *socket = [favorite objectForKey:@"socket"];
- NSString *user = [favorite objectForKey:@"user"];
- NSString *port = [favorite objectForKey:@"port"];
- NSString *database = [favorite objectForKey:@"database"];
-
- [hostField setStringValue:host];
- [socketField setStringValue:socket];
- [userField setStringValue:user];
- [portField setStringValue:port];
- [databaseField setStringValue:database];
- [passwordField setStringValue:[keyChainInstance
- getPasswordForName:[NSString stringWithFormat:@"Sequel Pro : %@", name]
- account:[NSString stringWithFormat:@"%@@%@/%@", user, host, database]]];
+ [hostField setStringValue:[self valueForKeyPath:@"selectedFavorite.host"]];
+ [socketField setStringValue:[self valueForKeyPath:@"selectedFavorite.socket"]];
+ [userField setStringValue:[self valueForKeyPath:@"selectedFavorite.user"]];
+ [portField setStringValue:[self valueForKeyPath:@"selectedFavorite.port"]];
+ [databaseField setStringValue:[self valueForKeyPath:@"selectedFavorite.database"]];
+ [passwordField setStringValue:[self selectedFavoritePassword]];
[selectedFavorite release];
selectedFavorite = [[favoritesButton titleOfSelectedItem] retain];
@@ -237,6 +227,36 @@ reused when user hits the close button of the variablseSheet or of the createTab
}
/**
+ * returns a KVC-compliant proxy to the currently selected favorite, or nil if nothing selected.
+ *
+ * see [NSObjectController selection]
+ */
+- (id)selectedFavorite
+{
+ if ([favoritesController selectionIndex] == NSNotFound)
+ return nil;
+
+ return [favoritesController selection];
+}
+
+/**
+ * fetches the password [self selectedFavorite] from the keychain, returns nil if no selection.
+ */
+- (NSString *)selectedFavoritePassword
+{
+ if (![self selectedFavorite])
+ return nil;
+
+ NSString *keychainName = [NSString stringWithFormat:@"Sequel Pro : %@", [self valueForKeyPath:@"selectedFavorite.name"]];
+ NSString *keychainAccount = [NSString stringWithFormat:@"%@@%@/%@",
+ [self valueForKeyPath:@"selectedFavorite.user"],
+ [self valueForKeyPath:@"selectedFavorite.host"],
+ [self valueForKeyPath:@"selectedFavorite.database"]];
+
+ return [keyChainInstance getPasswordForName:keychainName account:keychainAccount];
+}
+
+/**
* add actual connection to favorites
*/
- (void)addToFavoritesHost:(NSString *)host socket:(NSString *)socket