diff --git a/MacPass/MPDocument.h b/MacPass/MPDocument.h index 19d4a44a..e96731ae 100644 --- a/MacPass/MPDocument.h +++ b/MacPass/MPDocument.h @@ -30,6 +30,7 @@ APPKIT_EXTERN NSString *const MPDocumentDidLockDatabaseNotification; APPKIT_EXTERN NSString *const MPDocumentDidUnlockDatabaseNotification; FOUNDATION_EXTERN NSString *const MPDocumentCurrentItemChangedNotification; +FOUNDATION_EXTERN NSString *const MPDocumentItemAddedNotification; APPKIT_EXTERN NSString *const MPDocumentEntryKey; APPKIT_EXTERN NSString *const MPDocumentGroupKey; diff --git a/MacPass/MPDocument.m b/MacPass/MPDocument.m index 87b57ae3..dc8bc9c5 100644 --- a/MacPass/MPDocument.m +++ b/MacPass/MPDocument.m @@ -52,6 +52,7 @@ NSString *const MPDocumentDidLockDatabaseNotification = @"com.hicknhack.macp NSString *const MPDocumentDidUnlockDatabaseNotification = @"com.hicknhack.macpass.MPDocumentDidUnlockDatabaseNotification"; NSString *const MPDocumentCurrentItemChangedNotification = @"com.hicknhack.macpass.MPDocumentCurrentItemChangedNotification"; +NSString *const MPDocumentItemAddedNotification = @"com.hicknhack.macpass.MPDocumentItemAddedNotification"; NSString *const MPDocumentEntryKey = @"MPDocumentEntryKey"; NSString *const MPDocumentGroupKey = @"MPDocumentGroupKey"; @@ -444,6 +445,7 @@ NSString *const MPDocumentGroupKey = @"MPDocumentGroupKey } [parent addEntry:newEntry]; [parent.undoManager setActionName:NSLocalizedString(@"ADD_ENTRY", "")]; + [[NSNotificationCenter defaultCenter] postNotificationName:MPDocumentItemAddedNotification object:self]; return newEntry; } diff --git a/MacPass/MPEntryInspectorViewController.h b/MacPass/MPEntryInspectorViewController.h index 64282979..1485b446 100644 --- a/MacPass/MPEntryInspectorViewController.h +++ b/MacPass/MPEntryInspectorViewController.h @@ -48,6 +48,7 @@ @property (weak) IBOutlet NSTextField *associationSequenceTextField; - (void)setupBindings:(MPDocument *)document; +- (void)regsiterNotificationsForDocument:(MPDocument *)document; - (IBAction)saveAttachment:(id)sender; - (IBAction)addAttachment:(id)sender; diff --git a/MacPass/MPEntryInspectorViewController.m b/MacPass/MPEntryInspectorViewController.m index eb6e12c2..58655e02 100644 --- a/MacPass/MPEntryInspectorViewController.m +++ b/MacPass/MPEntryInspectorViewController.m @@ -13,6 +13,8 @@ #import "MPAttachmentTableDataSource.h" #import "MPWindowAssociationsTableViewDelegate.h" +#import "NSString+MPPasswordCreation.h" + #import "MPDocument.h" #import "MPIconHelper.h" #import "MPValueTransformerHelper.h" @@ -119,6 +121,17 @@ typedef NS_ENUM(NSUInteger, MPEntryTab) { } } +- (void)regsiterNotificationsForDocument:(MPDocument *)document { + [[NSNotificationCenter defaultCenter] addObserver:self + selector:@selector(_didAddItem:) + name:MPDocumentItemAddedNotification + object:document]; +} + +- (void)dealloc { + [[NSNotificationCenter defaultCenter] removeObserver:self]; +} + #pragma mark - #pragma mark Actions @@ -418,4 +431,28 @@ typedef NS_ENUM(NSUInteger, MPEntryTab) { } +#pragma mark - +#pragma mark MPDocument Notifications + +- (void)_didAddItem:(NSNotification *)notification { + [self.tabView selectTabViewItemAtIndex:MPEntryTabGeneral]; + + /* generate and pre-fill password using default password creation settings */ + NSUInteger passwordLength = [[NSUserDefaults standardUserDefaults] integerForKey:kMPSettingsKeyDefaultPasswordLength]; + MPPasswordCharacterFlags characterFlags = [[NSUserDefaults standardUserDefaults] integerForKey:kMPSettingsKeyPasswordCharacterFlags]; + BOOL useCustomString = [[NSUserDefaults standardUserDefaults] boolForKey:kMPSettingsKeyPasswordUseCustomString]; + NSString *customString = [[NSUserDefaults standardUserDefaults] stringForKey:kMPSettingsKeyPasswordCustomString]; + + if(useCustomString) { + if([customString length] > 0) { + [self.passwordTextField setStringValue:[customString passwordWithLength:passwordLength]]; + } + } + else { + [self.passwordTextField setStringValue:[NSString passwordWithCharactersets:characterFlags length:passwordLength]]; + } + + [self.titleTextField becomeFirstResponder]; +} + @end diff --git a/MacPass/MPEntryViewController.m b/MacPass/MPEntryViewController.m index bc2e6be2..d4a7b526 100644 --- a/MacPass/MPEntryViewController.m +++ b/MacPass/MPEntryViewController.m @@ -206,6 +206,11 @@ NSString *const _MPTAbleSecurCellView = @"PasswordCell"; name:MPDocumentCurrentItemChangedNotification object:document]; + [[NSNotificationCenter defaultCenter] addObserver:self + selector:@selector(_didAddItem:) + name:MPDocumentItemAddedNotification + object:document]; + [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(_didEnterSearch:) name:MPDocumentDidEnterSearchNotification @@ -221,7 +226,6 @@ NSString *const _MPTAbleSecurCellView = @"PasswordCell"; name:MPDocumentDidChangeSearchResults object:document]; - [self.contextBarViewController registerNotificationsForDocument:document]; /* Setup warning message at the bottom*/ @@ -371,6 +375,13 @@ NSString *const _MPTAbleSecurCellView = @"PasswordCell"; } } +- (void)_didAddItem:(NSNotification *)notification { + MPDocument *document = [[self windowController] document]; + NSInteger row = document.selectedGroup.entries.count - 1; + [self.entryTable scrollRowToVisible:row]; + [self.entryTable selectRowIndexes:[NSIndexSet indexSetWithIndex:row] byExtendingSelection:NO]; +} + - (void)_didUpdateSearchResults:(NSNotification *)notification { [self _showContextBar]; NSArray *result = [notification userInfo][kMPDocumentSearchResultsKey]; diff --git a/MacPass/MPInspectorViewController.m b/MacPass/MPInspectorViewController.m index f94ffc4c..b16987b9 100644 --- a/MacPass/MPInspectorViewController.m +++ b/MacPass/MPInspectorViewController.m @@ -113,6 +113,9 @@ typedef NS_ENUM(NSUInteger, MPContentTab) { selector:@selector(_didChangeCurrentItem:) name:MPDocumentCurrentItemChangedNotification object:document]; + + [self.entryViewController regsiterNotificationsForDocument:document]; + [self.entryViewController setupBindings:document]; [self.groupViewController setupBindings:document]; }