diff --git a/MacPass/MPEntryInspectorViewController.m b/MacPass/MPEntryInspectorViewController.m index 02693082..b8ac3ef0 100644 --- a/MacPass/MPEntryInspectorViewController.m +++ b/MacPass/MPEntryInspectorViewController.m @@ -235,6 +235,7 @@ typedef NS_ENUM(NSUInteger, MPEntryTab) { [self.URLTextField bind:NSValueBinding toObject:self.entry withKeyPath:@"url" options:nil]; [self.notesTextView bind:NSValueBinding toObject:self.entry withKeyPath:@"notes" options:nil]; [self.expiresCheckButton bind:NSValueBinding toObject:self.entry.timeInfo withKeyPath:@"expires" options:nil]; + [self.tagsTokenField bind:NSValueBinding toObject:self.entry withKeyPath:@"tags" options:nil]; } else { [self.titleTextField unbind:NSValueBinding]; diff --git a/MacPass/MPPasswordInputController.m b/MacPass/MPPasswordInputController.m index 1d1593cf..672b36bd 100644 --- a/MacPass/MPPasswordInputController.m +++ b/MacPass/MPPasswordInputController.m @@ -24,7 +24,7 @@ @property (weak) IBOutlet NSTextField *errorInfoTextField; @property (weak) IBOutlet NSButton *togglePasswordButton; -@property (nonatomic, assign) BOOL shouldSelectKeyFile; +@property (nonatomic, assign) BOOL shouldRememberKeyURL; @property (assign) BOOL showPassword; - (IBAction)_decrypt:(id)sender; @@ -43,20 +43,20 @@ self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; if(self) { _showLastUsedKeyFile = NO; - _shouldSelectKeyFile = NO; + _shouldRememberKeyURL = NO; + NSUserDefaultsController *defaultsController = [NSUserDefaultsController sharedUserDefaultsController]; + [self bind:@"shouldRememberKeyURL" toObject:defaultsController withKeyPath:[MPSettingsHelper defaultControllerPathForKey:kMPSettingsKeyRememberKeyFilesForDatabases ] options:nil]; + } return self; } - (void)didLoadView { - NSUserDefaultsController *defaultsController = [NSUserDefaultsController sharedUserDefaultsController]; - [self bind:@"shouldSelectKeyFile" toObject:defaultsController withKeyPath:[MPSettingsHelper defaultControllerPathForKey:kMPSettingsKeyRememberKeyFilesForDatabases ] options:nil]; - [self.keyPathControl setDelegate:self.pathControlDelegate]; [self.errorImageView setImage:[NSImage imageNamed:NSImageNameCaution]]; [self.passwordTextField bind:@"showPassword" toObject:self withKeyPath:@"showPassword" options:nil]; [self.togglePasswordButton bind:NSValueBinding toObject:self withKeyPath:@"showPassword" options:nil]; - + [self _reset]; } @@ -73,22 +73,27 @@ } #pragma mark Properties -- (void)setShouldSelectKeyFile:(BOOL)shouldSelectKeyFile { - if(_shouldSelectKeyFile != shouldSelectKeyFile) { - _shouldSelectKeyFile = shouldSelectKeyFile; +- (void)setShouldRememberKeyURL:(BOOL)shouldSelectKeyFile { + if(_shouldRememberKeyURL != shouldSelectKeyFile) { + _shouldRememberKeyURL = shouldSelectKeyFile; + if(!self.shouldRememberKeyURL) { + /* Remove any old settings to clean them up */ + [[NSUserDefaults standardUserDefaults] removeObjectForKey:kMPSettingsKeyRememeberdKeysForDatabases]; + } } } #pragma mark - #pragma mark Private - (IBAction)_decrypt:(id)sender { - id windowController = [[[self view] window] windowController]; - MPDocument *document = [windowController document]; + MPDocument *document = [[self windowController] document]; if(document) { NSError *error = nil; - if(![document unlockWithPassword:[self.passwordTextField stringValue] - keyFileURL:[self.keyPathControl URL] - error:&error]) { + NSURL *keyURL = [self.keyPathControl URL]; + if([document unlockWithPassword:[self.passwordTextField stringValue] keyFileURL:keyURL error:&error]) { + [self _setUsedKeyURL:keyURL forDocument:document]; + } + else { [self _showError:error]; } } @@ -107,11 +112,30 @@ } - (void)_selectRecentKeyFile { - if(!self.shouldSelectKeyFile) { + if(!self.shouldRememberKeyURL) { [self.keyPathControl setURL:nil]; return; // If we aren't supposed to preselect paths, clear them! } + NSDictionary *keysForFiles = [[NSUserDefaults standardUserDefaults] dictionaryForKey:kMPSettingsKeyRememeberdKeysForDatabases]; + MPDocument *document = [[self windowController] document]; + if(document) { + NSString *keyPath = keysForFiles[[[document fileURL] path]]; + NSURL *keyURL = keyPath != nil ? [NSURL fileURLWithPath:keyPath] : nil; + [self.keyPathControl setURL:keyURL]; + } +} +- (void)_setUsedKeyURL:(NSURL *)keyURL forDocument:(NSDocument *)document { + if(!self.shouldRememberKeyURL) { + return; + } + NSMutableDictionary *keysForFiles = [[[NSUserDefaults standardUserDefaults] dictionaryForKey:kMPSettingsKeyRememeberdKeysForDatabases] mutableCopy]; + if(nil == keysForFiles) { + keysForFiles = [[NSMutableDictionary alloc] initWithCapacity:1]; + } + NSLog(@"remembering keyfile %@ for document %@ at URL %@", keyURL, [document displayName], [document fileURL]); + keysForFiles[[[document fileURL] path]] = [keyURL path]; + [[NSUserDefaults standardUserDefaults] setObject:keysForFiles forKey:kMPSettingsKeyRememeberdKeysForDatabases]; } - (void)_showError:(NSError *)error { diff --git a/MacPass/MPSettingsHelper.h b/MacPass/MPSettingsHelper.h index e44ae93b..5e0dc9d5 100644 --- a/MacPass/MPSettingsHelper.h +++ b/MacPass/MPSettingsHelper.h @@ -39,7 +39,7 @@ APPKIT_EXTERN NSString *const kMPSettingsKeyLegacyHideURL; /* Document/Key Location store */ APPKIT_EXTERN NSString *const kMPSettingsKeyLastDatabasePath; -APPKIT_EXTERN NSString *const kMPSettingsKeyFilesForDatabases; +APPKIT_EXTERN NSString *const kMPSettingsKeyRememeberdKeysForDatabases; APPKIT_EXTERN NSString *const kMPSettingsKeyRememberKeyFilesForDatabases; /* APPKIT_EXTERN NSString *const kMPSettingsKeyLastKeyURL; diff --git a/MacPass/MPSettingsHelper.m b/MacPass/MPSettingsHelper.m index ed96da0b..7c6f2184 100644 --- a/MacPass/MPSettingsHelper.m +++ b/MacPass/MPSettingsHelper.m @@ -26,9 +26,9 @@ NSString *const kMPSettingsKeyLegacyHidePassword = @"LegacyHidePassword"; NSString *const kMPSettingsKeyLegacyHideNotes = @"LegacyHideNotes"; NSString *const kMPSettingsKeyLegacyHideURL = @"LegacyHideURL"; -NSString *const kMPSettingsKeyLastDatabasePath = @"MPLastDatabasePath"; -NSString *const kMPSettingsKeyFilesForDatabases = @"MPKeyFilesForDatabases"; -NSString *const kMPSettingsKeyRememberKeyFilesForDatabases = @"kMPSettingsKeyRememberKeyFilesForDatabases"; +NSString *const kMPSettingsKeyLastDatabasePath = @"LastDatabasePath"; +NSString *const kMPSettingsKeyRememeberdKeysForDatabases = @"RememeberdKeysForDatabases"; +NSString *const kMPSettingsKeyRememberKeyFilesForDatabases = @"RememberKeyFilesForDatabases"; @implementation MPSettingsHelper