diff --git a/MacPass/Base.lproj/InspectorView.xib b/MacPass/Base.lproj/InspectorView.xib index 245d5b55..14404bb7 100644 --- a/MacPass/Base.lproj/InspectorView.xib +++ b/MacPass/Base.lproj/InspectorView.xib @@ -1,5 +1,5 @@ - + @@ -52,6 +52,17 @@ + @@ -74,7 +85,7 @@ - + diff --git a/MacPass/ContextBar.xib b/MacPass/ContextBar.xib index ca6cec9b..04dffb30 100644 --- a/MacPass/ContextBar.xib +++ b/MacPass/ContextBar.xib @@ -1,8 +1,8 @@ - + - + @@ -202,6 +202,9 @@ + + + diff --git a/MacPass/MPDocument+HistoryBrowsing.m b/MacPass/MPDocument+HistoryBrowsing.m index a42b14c9..c4af067f 100644 --- a/MacPass/MPDocument+HistoryBrowsing.m +++ b/MacPass/MPDocument+HistoryBrowsing.m @@ -14,6 +14,7 @@ NSString *const MPDocumentDidExitHistoryNotification = @"MPDocumentDidExitHisto @implementation MPDocument (HistoryBrowsing) - (void)showHistory:(id)sender { + NSAssert(self.selectedEntry && self.selectedItem == (id)self.selectedEntry, @"Entry needs to be selected for history browsing!"); [[NSNotificationCenter defaultCenter] postNotificationName:MPDocumentDidEnterHistoryNotification object:self]; } diff --git a/MacPass/MPDocument.m b/MacPass/MPDocument.m index 5ab30290..1cca672a 100644 --- a/MacPass/MPDocument.m +++ b/MacPass/MPDocument.m @@ -594,7 +594,7 @@ NSString *const MPDocumentGroupKey = @"MPDocumentGroupKey - (BOOL)validateUserInterfaceItem:(id)anItem { if(self.encrypted || self.isReadOnly) { return NO; } - BOOL valid = YES; + BOOL valid = self.selectedItem ? self.selectedItem.isEditable : YES; switch([MPActionHelper typeForAction:[anItem action]]) { case MPActionAddGroup: valid &= (nil != self.selectedGroup); @@ -627,8 +627,10 @@ NSString *const MPDocumentGroupKey = @"MPDocumentGroupKey case MPActionLock: valid &= self.compositeKey.hasPasswordOrKeyFile; break; + case MPActionShowHistory: + valid &= (self.selectedEntry && (self.selectedItem == (id)self.selectedEntry)); default: - valid = YES; + break; } return (valid && [super validateUserInterfaceItem:anItem]); } diff --git a/MacPass/MPEntryInspectorViewController.m b/MacPass/MPEntryInspectorViewController.m index 682b2e82..a5f25b69 100644 --- a/MacPass/MPEntryInspectorViewController.m +++ b/MacPass/MPEntryInspectorViewController.m @@ -357,6 +357,15 @@ typedef NS_ENUM(NSUInteger, MPEntryTab) { } - (void)_bindEntry { + static NSArray *items; + if(!items) { + items = @[ self.titleTextField, + self.passwordTextField, + self.usernameTextField, + self.URLTextField, + self.expiresCheckButton, + self.tagsTokenField ]; + } if(self.entry) { [self.titleTextField bind:NSValueBinding toObject:self.entry withKeyPath:NSStringFromSelector(@selector(title)) options:nil]; [self.passwordTextField bind:NSValueBinding toObject:self.entry withKeyPath:NSStringFromSelector(@selector(password)) options:nil]; @@ -368,13 +377,17 @@ typedef NS_ENUM(NSUInteger, MPEntryTab) { options:@{ NSValueTransformerNameBindingOption:MPExpiryDateValueTransformer }]; [self.expiresCheckButton bind:NSValueBinding toObject:self.entry.timeInfo withKeyPath:NSStringFromSelector(@selector(expires)) options:nil]; [self.tagsTokenField bind:NSValueBinding toObject:self.entry withKeyPath:NSStringFromSelector(@selector(tags)) options:nil]; + + /* Setup enable/disable */ + for(id item in items) { + [item bind:NSEnabledBinding toObject:self.entry withKeyPath:NSStringFromSelector(@selector(isEditable)) options:nil]; + } } else { - [self.titleTextField unbind:NSValueBinding]; - [self.passwordTextField unbind:NSValueBinding]; - [self.usernameTextField unbind:NSValueBinding]; - [self.URLTextField unbind:NSValueBinding]; - [self.expiresCheckButton unbind:NSValueBinding]; + for(id item in items) { + [item unbind:NSValueBinding]; + [item unbind:NSEnabledBinding]; + } [self.expiresCheckButton unbind:NSTitleBinding]; } } diff --git a/MacPass/MPEntryViewController.m b/MacPass/MPEntryViewController.m index 0c41e22f..d0c6987a 100644 --- a/MacPass/MPEntryViewController.m +++ b/MacPass/MPEntryViewController.m @@ -13,6 +13,7 @@ #import "MPDocument.h" #import "MPDocument+Search.h" #import "MPDocument+Autotype.h" +#import "MPDocument+HistoryBrowsing.h" #import "MPDocumentWindowController.h" #import "MPPasteBoardController.h" @@ -235,6 +236,9 @@ NSString *const _MPTAbleSecurCellView = @"PasswordCell"; selector:@selector(_didUnlockDatabase:) name:MPDocumentDidUnlockDatabaseNotification object:document]; + [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(_didEnterHistory:) name:MPDocumentDidEnterHistoryNotification object:document]; + [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(_didExitHistory:) name:MPDocumentDidExitHistoryNotification object:document]; + [self.contextBarViewController registerNotificationsForDocument:document]; } @@ -413,6 +417,20 @@ NSString *const _MPTAbleSecurCellView = @"PasswordCell"; } } +- (void)_didEnterHistory:(NSNotification *)notification { + [self _showContextBar]; + /* TODO: Show modification date column if not present? */ + MPDocument *document = [[self windowController] document]; + [self.entryArrayController bind:NSContentArrayBinding toObject:document.selectedEntry withKeyPath:NSStringFromSelector(@selector(history)) options:nil]; +} + +- (void)_didExitHistory:(NSNotification *)notification { + [self _hideContextBar]; + MPDocument *document = [[self windowController] document]; + document.selectedItem = document.selectedEntry; +} + + #pragma mark ContextBar - (void)_updateContextBar { MPDocument *document = [[self windowController] document]; diff --git a/MacPass/MPInspectorViewController.m b/MacPass/MPInspectorViewController.m index fbfc2ad0..557bdf32 100644 --- a/MacPass/MPInspectorViewController.m +++ b/MacPass/MPInspectorViewController.m @@ -170,7 +170,7 @@ typedef NS_ENUM(NSUInteger, MPContentTab) { MPDocument *document = [[self windowController] document]; if(document.selectedItem) { - + /* TODO UndoManager handling */ [self.editButton setTitle:NSLocalizedString(@"EDIT_ITEM", "")]; [self.cancelEditButton setHidden:YES]; @@ -267,14 +267,24 @@ typedef NS_ENUM(NSUInteger, MPContentTab) { - (void)_updateBindings:(id)item { if(!item) { [self.itemNameTextField unbind:NSValueBinding]; + [self.itemNameTextField unbind:NSEnabledBinding]; [self.itemNameTextField setHidden:YES]; [self.itemImageView unbind:NSValueBinding]; + [self.itemImageView unbind:NSEnabledBinding]; [self.itemImageView setHidden:YES]; [[self.notesTextView enclosingScrollView] setHidden:YES]; [self.notesTextView unbind:NSValueBinding]; + [self.notesTextView unbind:NSEditableBinding]; [self.notesTextView setString:@""]; return; } + + /* Disable if item is not editable */ + NSLog(@"%@ isEditable: %i", item, [item isEditable]); + [self.itemNameTextField bind:NSEnabledBinding toObject:item withKeyPath:NSStringFromSelector(@selector(isEditable)) options:nil]; + [self.itemImageView bind:NSEnabledBinding toObject:item withKeyPath:NSStringFromSelector(@selector(isEditable)) options:nil]; + [self.notesTextView bind:NSEditableBinding toObject:item withKeyPath:NSStringFromSelector(@selector(isEditable)) options:nil]; + [self.itemImageView bind:NSValueBinding toObject:item withKeyPath:NSStringFromSelector(@selector(iconImage)) options:nil]; [[self.notesTextView enclosingScrollView] setHidden:NO]; [self.notesTextView bind:NSValueBinding toObject:item withKeyPath:NSStringFromSelector(@selector(notes)) options:nil];