mirror of
https://github.com/MacPass/MacPass.git
synced 2025-12-14 08:12:28 +00:00
Improved "Add Entry" workflow (issue #156)
- New entry is automatically scrolled to and selected - Title textfield is automatically focused - Pre-generate a password using the deault password creation settings
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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];
|
||||
|
||||
@@ -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];
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user