aboutsummaryrefslogtreecommitdiffstats
path: root/TableDocument.m
diff options
context:
space:
mode:
authorabhibeckert <abhi@abhibeckert.com>2008-04-20 01:33:56 +0000
committerabhibeckert <abhi@abhibeckert.com>2008-04-20 01:33:56 +0000
commit385af2eacdcceb9160d787539380d921919f3d99 (patch)
tree03f64eba62f5b6494c052c694e65fc67d434bd53 /TableDocument.m
parent42f0345b621e534dcf87451bff703535eff44017 (diff)
downloadsequelpro-385af2eacdcceb9160d787539380d921919f3d99.tar.gz
sequelpro-385af2eacdcceb9160d787539380d921919f3d99.tar.bz2
sequelpro-385af2eacdcceb9160d787539380d921919f3d99.zip
refactor favorites
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