Merge pull request #210 from jamesrhurst/add-entry-fixes

Improved "Add Entry" workflow (issue #156)
This commit is contained in:
Michael Starke
2014-08-06 17:40:43 +02:00
6 changed files with 57 additions and 1 deletions

View File

@@ -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;

View File

@@ -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;
}

View File

@@ -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;

View File

@@ -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

View File

@@ -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,14 @@ NSString *const _MPTAbleSecurCellView = @"PasswordCell";
}
}
- (void)_didAddItem:(NSNotification *)notification {
MPDocument *document = [[self windowController] document];
KPKEntry *entry = document.selectedGroup.entries.lastObject;
NSUInteger row = [self.entryArrayController.arrangedObjects indexOfObject:entry];
[self.entryTable scrollRowToVisible:row];
[self.entryTable selectRowIndexes:[NSIndexSet indexSetWithIndex:row] byExtendingSelection:NO];
}
- (void)_didUpdateSearchResults:(NSNotification *)notification {
[self _showContextBar];
NSArray *result = [notification userInfo][kMPDocumentSearchResultsKey];

View File

@@ -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];
}