From 6771d68454dc06c5b7b20b65fcfba74e0f408298 Mon Sep 17 00:00:00 2001 From: michael starke Date: Thu, 8 Jun 2017 15:39:29 +0200 Subject: [PATCH] disabled more actions and controls in history view --- MacPass/Base.lproj/EntryInspectorView.xib | 11 +++-- MacPass/MPDocument.m | 5 ++ MacPass/MPEntryInspectorViewController.h | 1 + MacPass/MPEntryInspectorViewController.m | 60 +++++++++++++---------- 4 files changed, 47 insertions(+), 30 deletions(-) diff --git a/MacPass/Base.lproj/EntryInspectorView.xib b/MacPass/Base.lproj/EntryInspectorView.xib index 299e796b..e1319c88 100644 --- a/MacPass/Base.lproj/EntryInspectorView.xib +++ b/MacPass/Base.lproj/EntryInspectorView.xib @@ -24,6 +24,7 @@ + @@ -97,7 +98,7 @@ - + @@ -274,7 +275,7 @@ - + @@ -463,7 +464,7 @@ - + @@ -696,7 +697,7 @@ - + @@ -951,7 +952,7 @@ - + diff --git a/MacPass/MPDocument.m b/MacPass/MPDocument.m index 806da9b7..308f0a7e 100644 --- a/MacPass/MPDocument.m +++ b/MacPass/MPDocument.m @@ -743,11 +743,13 @@ NSString *const MPDocumentGroupKey = @"MPDocumentGrou valid &= (nil != targetGroup); valid &= !targetGroup.isTrash; valid &= !targetGroup.isTrashed; + valid &= !self.historyEntry; break; case MPActionAddEntry: valid &= (nil != targetGroup); valid &= !targetGroup.isTrash; valid &= !targetGroup.isTrashed; + valid &= !self.historyEntry; break; case MPActionDelete: valid &= targetNodes.count > 0; @@ -760,7 +762,9 @@ NSString *const MPDocumentGroupKey = @"MPDocumentGrou } break; case MPActionDuplicateEntry: + case MPActionDuplicateEntryWithOptions: valid &= targetEntries.count > 0; + valid &= !self.historyEntry; break; case MPActionEmptyTrash: valid &= (self.trash.groups.count + self.trash.entries.count) > 0; @@ -775,6 +779,7 @@ NSString *const MPDocumentGroupKey = @"MPDocumentGrou case MPActionShowEntryHistory: valid &= (nil != targetEntry); valid &= targetEntry.history.count > 0; + valid &= !self.historyEntry; break; /* Entry View Actions */ case MPActionCopyUsername: diff --git a/MacPass/MPEntryInspectorViewController.h b/MacPass/MPEntryInspectorViewController.h index 13544459..327e6ea4 100644 --- a/MacPass/MPEntryInspectorViewController.h +++ b/MacPass/MPEntryInspectorViewController.h @@ -55,6 +55,7 @@ @property (weak) IBOutlet NSTextField *associationSequenceTextField; @property (weak) IBOutlet NSButton *addWindowAssociationButton; +@property (weak) IBOutlet NSButton *removeWindowAssociationButton; - (void)registerNotificationsForDocument:(MPDocument *)document; diff --git a/MacPass/MPEntryInspectorViewController.m b/MacPass/MPEntryInspectorViewController.m index e956bac7..023e0356 100644 --- a/MacPass/MPEntryInspectorViewController.m +++ b/MacPass/MPEntryInspectorViewController.m @@ -109,7 +109,7 @@ typedef NS_ENUM(NSUInteger, MPEntryTab) { self.customFieldsTableView.backgroundColor = [NSColor clearColor]; [self.customFieldsTableView bind:NSContentBinding toObject:_customFieldsController withKeyPath:NSStringFromSelector(@selector(arrangedObjects)) options:nil]; self.customFieldsTableView.delegate = _customFieldTableDelegate; - + self.windowAssociationsTableView.backgroundColor = [NSColor clearColor]; self.windowAssociationsTableView.delegate = _windowAssociationsTableDelegate; [self.windowAssociationsTableView bind:NSContentBinding toObject:_windowAssociationsController withKeyPath:NSStringFromSelector(@selector(arrangedObjects)) options:nil]; @@ -355,13 +355,38 @@ typedef NS_ENUM(NSUInteger, MPEntryTab) { options:0 metrics:nil views:views]]; - + [[self view] layoutSubtreeIfNeeded]; } #pragma mark - #pragma mark Entry Selection - (void)_setupViewBindings { + /* Disable for history view */ + NSArray *inputs = @[self.titleTextField, + self.passwordTextField, + self.usernameTextField, + self.URLTextField, + self.expiresCheckButton, + self.tagsTokenField, + self.generatePasswordButton, + self.addAttachmentButton, + self.addCustomFieldButton, + self.addWindowAssociationButton, + self.removeWindowAssociationButton, + self.enableAutotypeCheckButton, + self.obfuscateAutotypeCheckButton, + self.customEntrySequenceTextField, + self.windowTitleComboBox, + self.associationSequenceTextField]; + + for(NSControl *control in inputs) { + [control bind:NSEnabledBinding + toObject:self + withKeyPath:[NSString stringWithFormat:@"%@.%@", NSStringFromSelector(@selector(representedObject)), NSStringFromSelector(@selector(isHistory))] + options:@{NSConditionallySetsEditableBindingOption: @NO, NSValueTransformerNameBindingOption: NSNegateBooleanTransformerName}]; + } + /* general */ [self.titleTextField bind:NSValueBinding toObject:self @@ -378,7 +403,7 @@ typedef NS_ENUM(NSUInteger, MPEntryTab) { [self.URLTextField bind:NSValueBinding toObject:self withKeyPath:[NSString stringWithFormat:@"%@.%@", NSStringFromSelector(@selector(representedObject)), NSStringFromSelector(@selector(url))] - options:@{ NSNullPlaceholderBindingOption: NSLocalizedString(@"NONE", "")}]; + options:@{ NSNullPlaceholderBindingOption: NSLocalizedString(@"NONE", "")}]; [self.expiresCheckButton bind:NSTitleBinding toObject:self withKeyPath:[NSString stringWithFormat:@"%@.%@.%@", NSStringFromSelector(@selector(representedObject)), NSStringFromSelector(@selector(timeInfo)), NSStringFromSelector(@selector(expirationDate))] @@ -398,13 +423,13 @@ typedef NS_ENUM(NSUInteger, MPEntryTab) { withKeyPath:[NSString stringWithFormat:@"%@.%@.%@", NSStringFromSelector(@selector(representedObject)), NSStringFromSelector(@selector(uuid)), NSStringFromSelector(@selector(UUIDString))] options:@{ NSConditionallySetsEditableBindingOption: @NO }]; self.uuidTextField.editable = NO; - + /* Attachments */ [_attachmentsController bind:NSContentArrayBinding toObject:self withKeyPath:[NSString stringWithFormat:@"%@.%@", NSStringFromSelector(@selector(representedObject)), NSStringFromSelector(@selector(binaries))] options:nil]; - + /* CustomField */ [_customFieldsController bind:NSContentArrayBinding toObject:self @@ -419,10 +444,14 @@ typedef NS_ENUM(NSUInteger, MPEntryTab) { toObject:self withKeyPath:[NSString stringWithFormat:@"%@.%@.%@", NSStringFromSelector(@selector(representedObject)), NSStringFromSelector(@selector(autotype)), NSStringFromSelector(@selector(obfuscateDataTransfer))] options:nil]; - [self.customEntrySequenceTextField bind:NSEnabledBinding + + /* Use enabled2 since NSEnabledBinding is already bound! */ + [self.customEntrySequenceTextField bind:@"enabled2" toObject:self withKeyPath:[NSString stringWithFormat:@"%@.%@.%@", NSStringFromSelector(@selector(representedObject)), NSStringFromSelector(@selector(autotype)), NSStringFromSelector(@selector(enabled))] options:nil]; + + [self.customEntrySequenceTextField bind:NSValueBinding toObject:self withKeyPath:[NSString stringWithFormat:@"%@.%@.%@", NSStringFromSelector(@selector(representedObject)), NSStringFromSelector(@selector(autotype)), NSStringFromSelector(@selector(defaultKeystrokeSequence))] @@ -441,26 +470,7 @@ typedef NS_ENUM(NSUInteger, MPEntryTab) { toObject:_windowAssociationsController withKeyPath:[NSString stringWithFormat:@"selection.%@", NSStringFromSelector(@selector(keystrokeSequence))] options:nil]; - - NSArray *inputs = @[self.titleTextField, - self.passwordTextField, - self.usernameTextField, - self.URLTextField, - self.expiresCheckButton, - self.tagsTokenField, - self.generatePasswordButton, - self.addAttachmentButton, - self.addCustomFieldButton, - self.addWindowAssociationButton]; - for(NSControl *control in inputs) { - NSString *keyPath = [NSString stringWithFormat:@"%@.%@", NSStringFromSelector(@selector(representedObject)), NSStringFromSelector(@selector(isHistory))]; - [control bind:NSEnabledBinding - toObject:self - withKeyPath:keyPath - options:@{NSConditionallySetsEditableBindingOption: @NO, NSValueTransformerNameBindingOption: NSNegateBooleanTransformerName}]; - } - }