aboutsummaryrefslogtreecommitdiffstats
path: root/Source/SPPreferenceController.m
diff options
context:
space:
mode:
authorrowanbeentje <rowan@beent.je>2010-09-08 21:36:11 +0000
committerrowanbeentje <rowan@beent.je>2010-09-08 21:36:11 +0000
commitf7a69e2454ca3dd1f1a62875522e9fb3dea572b3 (patch)
tree847d2a915dfd496382977fc64799222057a923e3 /Source/SPPreferenceController.m
parent3f6aa841dd77af2cf8f2818c91cd186aec2ca5e0 (diff)
downloadsequelpro-f7a69e2454ca3dd1f1a62875522e9fb3dea572b3.tar.gz
sequelpro-f7a69e2454ca3dd1f1a62875522e9fb3dea572b3.tar.bz2
sequelpro-f7a69e2454ca3dd1f1a62875522e9fb3dea572b3.zip
- Add support for SSH identity files (public keys) in custom locations
- Update localisable strings - Fix initial window position
Diffstat (limited to 'Source/SPPreferenceController.m')
-rw-r--r--Source/SPPreferenceController.m44
1 files changed, 42 insertions, 2 deletions
diff --git a/Source/SPPreferenceController.m b/Source/SPPreferenceController.m
index 9f09ac2c..42503649 100644
--- a/Source/SPPreferenceController.m
+++ b/Source/SPPreferenceController.m
@@ -409,8 +409,8 @@
NSNumber *favoriteid = [NSNumber numberWithInteger:[[NSString stringWithFormat:@"%f", [[NSDate date] timeIntervalSince1970]] hash]];
// Create default favorite
- NSMutableDictionary *favorite = [NSMutableDictionary dictionaryWithObjects:[NSArray arrayWithObjects:@"New Favorite", [NSNumber numberWithInteger:0], @"", @"", @"", @"", @"", @"", @"", @"", favoriteid, nil]
- forKeys:[NSArray arrayWithObjects:@"name", @"type", @"host", @"socket", @"user", @"port", @"database", @"sshHost", @"sshUser", @"sshPort", @"id", nil]];
+ NSMutableDictionary *favorite = [NSMutableDictionary dictionaryWithObjects:[NSArray arrayWithObjects:@"New Favorite", [NSNumber numberWithInteger:0], @"", @"", @"", @"", @"", @"", @"", [NSNumber numberWithInt:NSOffState], @"", @"", favoriteid, nil]
+ forKeys:[NSArray arrayWithObjects:@"name", @"type", @"host", @"socket", @"user", @"port", @"database", @"sshHost", @"sshUser", @"sshKeyLocationEnabled", @"sshKeyLocation", @"sshPort", @"id", nil]];
[favoritesController addObject:favorite];
[favoritesController setSelectedObjects:[NSArray arrayWithObject:favorite]];
@@ -685,6 +685,46 @@
[[sender window] orderOut:self];
}
+/**
+ * Opens the SSH key selection window, ready to select a SSH key.
+ */
+- (IBAction)chooseSSHKey:(id)sender
+{
+ NSString *directoryPath = nil;
+ NSString *filePath = nil;
+
+ // If the custom key location is currently disabled - after the button
+ // action - leave it disabled and return without showing the sheet.
+ if (![[favoritesController valueForKeyPath:@"selection.sshKeyLocationEnabled"] intValue]) {
+ return;
+ }
+
+ // Otherwise open a panel at the last or default location
+ if ([favoritesController valueForKeyPath:@"selection.sshKeyLocation"] && [[favoritesController valueForKeyPath:@"selection.sshKeyLocation"] length]) {
+ filePath = [[favoritesController valueForKeyPath:@"selection.sshKeyLocation"] lastPathComponent];
+ directoryPath = [[favoritesController valueForKeyPath:@"selection.sshKeyLocation"] stringByDeletingLastPathComponent];
+ }
+ [[NSOpenPanel openPanel] beginSheetForDirectory:directoryPath
+ file:filePath
+ types:[NSArray arrayWithObjects:@"pem", @"", nil]
+ modalForWindow:preferencesWindow
+ modalDelegate:self
+ didEndSelector:@selector(chooseSSHKeySheetDidEnd:returnCode:contextInfo:)
+ contextInfo:nil];
+}
+
+/**
+ * Called after closing the SSH key selection sheet.
+ */
+- (void)chooseSSHKeySheetDidEnd:(NSOpenPanel *)openPanel returnCode:(NSInteger)returnCode contextInfo:(void *)contextInfo
+{
+ if (returnCode == NSCancelButton) {
+ [favoritesController setValue:[NSNumber numberWithInt:NSOffState] forKeyPath:@"selection.sshKeyLocationEnabled"];
+ return;
+ }
+ [favoritesController setValue:[[openPanel filename] stringByAbbreviatingWithTildeInPath] forKeyPath:@"selection.sshKeyLocation"];
+}
+
#pragma mark -
#pragma mark Toolbar item IBAction methods