diff --git a/DODropletManager/AppDelegate.m b/DODropletManager/AppDelegate.m
index a5046bc..fe7085e 100644
--- a/DODropletManager/AppDelegate.m
+++ b/DODropletManager/AppDelegate.m
@@ -31,6 +31,11 @@ @implementation AppDelegate {
BOOL firstRun;
DropletManager *dropletManager;
+
+ NSUserDefaults *userdefaults;
+ NSMutableDictionary *sshUserDictionary;
+
+
}
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
@@ -56,6 +61,17 @@ - (void)applicationDidFinishLaunching:(NSNotification *)aNotification
name:@"dropletsFailed"
object:nil];
+
+ userdefaults = [NSUserDefaults standardUserDefaults];
+
+
+ // If dictionary exists, load it from userDefaults;
+ if ([userdefaults objectForKey:@"sshUserDictionary"] == nil) {
+ sshUserDictionary = [[NSMutableDictionary alloc] init];
+ } else {
+ sshUserDictionary = [[userdefaults objectForKey:@"sshUserDictionary"] mutableCopy];
+ }
+
}
- (BOOL)loadKeys {
@@ -312,8 +328,20 @@ - (void)viewDropletOnBrowser:(id)sender {
}
- (void)establishSSHConnectionToDroplet:(id)sender {
+
+
+
+
Droplet *currentDroplet = ((NSMenuItem*)sender).representedObject;
- [[NSWorkspace sharedWorkspace] openURL:[NSURL URLWithString:[NSString stringWithFormat:@"ssh://root@%@", currentDroplet.ip]]];
+
+
+ if ([sshUserDictionary objectForKey:currentDroplet.name] == nil) {
+ [sshUserDictionary setObject:@"root" forKey:currentDroplet.name];
+ }
+
+ NSString *dropletSSHUsername = [sshUserDictionary objectForKey:currentDroplet.name];
+
+ [[NSWorkspace sharedWorkspace] openURL:[NSURL URLWithString:[NSString stringWithFormat:@"ssh://%@@%@", dropletSSHUsername, currentDroplet.ip]]];
}
- (void)alertDidEnd:(NSAlert *)alert returnCode:(NSInteger)returnCode contextInfo:(void *)contextInfo
diff --git a/DODropletManager/DODropletManager-Info.plist b/DODropletManager/DODropletManager-Info.plist
index 2d15fbd..b500cd3 100644
--- a/DODropletManager/DODropletManager-Info.plist
+++ b/DODropletManager/DODropletManager-Info.plist
@@ -17,11 +17,11 @@
CFBundlePackageType
APPL
CFBundleShortVersionString
- 0.1
+ 0.4.1
CFBundleSignature
????
CFBundleVersion
- 1
+ 4
LSMinimumSystemVersion
${MACOSX_DEPLOYMENT_TARGET}
LSUIElement
diff --git a/DODropletManager/PreferencesWindow.xib b/DODropletManager/PreferencesWindow.xib
index eaafa36..89dbf21 100644
--- a/DODropletManager/PreferencesWindow.xib
+++ b/DODropletManager/PreferencesWindow.xib
@@ -11,6 +11,7 @@
+
@@ -31,11 +32,11 @@
-
+
-
+
@@ -44,7 +45,7 @@
-
+
@@ -53,7 +54,7 @@
-
+
@@ -73,7 +74,7 @@
-
+
@@ -82,7 +83,7 @@
-
+
@@ -91,7 +92,7 @@
-
+
@@ -114,14 +115,14 @@
-
+
-
+
@@ -133,21 +134,65 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
+
-
+
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -156,11 +201,11 @@
-
+
-
+
diff --git a/DODropletManager/PreferencesWindowController.h b/DODropletManager/PreferencesWindowController.h
index 0c7e461..e0b2c05 100644
--- a/DODropletManager/PreferencesWindowController.h
+++ b/DODropletManager/PreferencesWindowController.h
@@ -8,7 +8,9 @@
#import
-@interface PreferencesWindowController : NSWindowController {
+@interface PreferencesWindowController : NSWindowController {
+
+ IBOutlet NSTableView *sshUsersTableview;
}
@property (strong) IBOutlet NSTextField *ClientIDTF;
diff --git a/DODropletManager/PreferencesWindowController.m b/DODropletManager/PreferencesWindowController.m
index ae73806..86a8b1c 100644
--- a/DODropletManager/PreferencesWindowController.m
+++ b/DODropletManager/PreferencesWindowController.m
@@ -9,6 +9,7 @@
#import "PreferencesWindowController.h"
#import "KeychainAccess.h"
#import "LaunchAtLoginController.h"
+#import "DropletManager.h"
@interface PreferencesWindowController ()
@@ -18,6 +19,10 @@ @implementation PreferencesWindowController {
NSMutableData *responseData;
LaunchAtLoginController *launchController;
+
+ DropletManager *dropletManager;
+ NSUserDefaults *userdefaults;
+ NSMutableDictionary *sshUserDictionary;
}
#pragma mark -
@@ -51,6 +56,19 @@ - (void)windowDidLoad
launchController = [[LaunchAtLoginController alloc] init];
_launchAtLoginCB.state = [launchController launchAtLogin];
+ dropletManager = [DropletManager sharedManager];
+ userdefaults = [NSUserDefaults standardUserDefaults];
+
+
+ // If dictionary exists, load it from userDefaults;
+ if ([userdefaults objectForKey:@"sshUserDictionary"] == nil) {
+ sshUserDictionary = [[NSMutableDictionary alloc] init];
+ } else {
+ sshUserDictionary = [[userdefaults objectForKey:@"sshUserDictionary"] mutableCopy];
+ }
+
+
+
if([KeychainAccess getClientId: &clientId andAPIKey: &apiKey error: nil]) {
[_ClientIDTF setStringValue: clientId];
@@ -74,6 +92,7 @@ - (IBAction)savePreferences:(id)sender {
[self showAlert: error];
}
+
}
@@ -146,5 +165,85 @@ - (void) connectionDidFinishLoading:(NSURLConnection *)connection
}
+#pragma mark -
+#pragma mark NSTableview delegate methods
+
+- (NSInteger)numberOfRowsInTableView:(NSTableView *)tableView {
+ return dropletManager.droplets.count;
+}
+
+- (NSView *)tableView:(NSTableView *)tableView viewForTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)row {
+
+ // Get a new ViewCell
+ NSTableCellView *cellView = [tableView makeViewWithIdentifier:tableColumn.identifier owner:self];
+
+
+ Droplet *currentDroplet = [dropletManager.droplets objectAtIndex:row];
+
+
+ if( [tableColumn.identifier isEqualToString:@"dropletColumn"] )
+ {
+
+ [cellView.textField setStringValue:currentDroplet.name];
+
+
+ } else if ([tableColumn.identifier isEqualToString:@"usernameColumn"]) {
+
+ if ([sshUserDictionary objectForKey:currentDroplet.name] == nil) {
+ [sshUserDictionary setObject:@"root" forKey:currentDroplet.name];
+
+ }
+
+ NSString *currentDropletSSHUser = [sshUserDictionary objectForKey:currentDroplet.name];
+
+ [cellView.textField setStringValue: currentDropletSSHUser];
+ [cellView.textField setEditable:YES];
+ cellView.textField.delegate = self;
+
+ }
+
+ [userdefaults setObject:sshUserDictionary forKey:@"sshUserDictionary"];
+ [userdefaults synchronize];
+
+ return cellView;
+}
+
+- (BOOL)tableView:(NSTableView *)tableView shouldEditTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)row {
+ if ([tableColumn.identifier isEqualToString:@"usernameColumn"]) {
+ return YES;
+ }
+
+ return NO;
+}
+
+#pragma mark -
+#pragma mark NSTextfield delegate methods
+
+- (void)controlTextDidEndEditing:(NSNotification *)obj
+{
+ NSDictionary *userInfo = [obj userInfo];
+ NSTextView *aView = [userInfo valueForKey:@"NSFieldEditor"];
+ DLog(@"controlTextDidEndEditing %@", [aView string] );
+
+ Droplet *currentDroplet = [dropletManager.droplets objectAtIndex:sshUsersTableview.selectedRow];
+
+ [sshUserDictionary setObject:[aView string] forKey:currentDroplet.name];
+
+ [userdefaults setObject:sshUserDictionary forKey:@"sshUserDictionary"];
+ [userdefaults synchronize];
+}
+
+- (void)controlTextDidChange:(NSNotification *)aNotification
+{
+ NSDictionary *userInfo = [aNotification userInfo];
+ NSTextView *aView = [userInfo valueForKey:@"NSFieldEditor"];
+ DLog(@"controlTextDidChange >>%@<<", [aView string] );
+}
+
+- (BOOL)control:(NSControl *)control textShouldEndEditing:(NSText *)fieldEditor
+{
+ DLog(@"control: textShouldEndEditing >%@<", [fieldEditor string] );
+ return YES;
+}
@end