From 7755bc9b939aba885a85d7b13c0350ff536cf818 Mon Sep 17 00:00:00 2001 From: michael starke Date: Tue, 23 Aug 2016 18:43:13 +0200 Subject: [PATCH] More transitions to representedObject for ViewController --- MacPass.xcodeproj/project.pbxproj | 6 ++ .../xcshareddata/xcschemes/MacPass.xcscheme | 4 ++ MacPass/Base.lproj/EntryInspectorView.xib | 2 +- MacPass/Base.lproj/InspectorView.xib | 19 ++++- MacPass/EntryView.xib | 2 +- MacPass/MPEntryInspectorViewController.m | 69 +++++++++---------- MacPass/MPGroupInspectorViewController.m | 6 +- MacPass/MPObjectController.h | 2 + MacPass/MPObjectController.m | 30 ++++++++ MacPass/MPPasswordCreatorViewController.m | 4 +- 10 files changed, 101 insertions(+), 43 deletions(-) diff --git a/MacPass.xcodeproj/project.pbxproj b/MacPass.xcodeproj/project.pbxproj index 970d139b..a3efbc8a 100644 --- a/MacPass.xcodeproj/project.pbxproj +++ b/MacPass.xcodeproj/project.pbxproj @@ -219,6 +219,7 @@ 4CD78AC016D155FF00768A1D /* 11_CameraTemplate.pdf in Resources */ = {isa = PBXBuildFile; fileRef = 4CD78ABB16D155FF00768A1D /* 11_CameraTemplate.pdf */; }; 4CD820211A32173100399DBB /* ReferenceBuilderView.xib in Resources */ = {isa = PBXBuildFile; fileRef = 4CD820231A32173100399DBB /* ReferenceBuilderView.xib */; }; 4CD884B715BD47080042BBF8 /* DocumentWindow.xib in Resources */ = {isa = PBXBuildFile; fileRef = 4CD884B615BD47080042BBF8 /* DocumentWindow.xib */; }; + 4CDE7B161D660983008C4160 /* MPObjectController.m in Sources */ = {isa = PBXBuildFile; fileRef = 4CDE7B151D660983008C4160 /* MPObjectController.m */; }; 4CDF01A316D1B76700D0AC08 /* MPEntryViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 4CDF01A216D1B76700D0AC08 /* MPEntryViewController.m */; }; 4CE2961518429AA5005F01CE /* MPAutotypeKeyPress.m in Sources */ = {isa = PBXBuildFile; fileRef = 4CE2961418429AA5005F01CE /* MPAutotypeKeyPress.m */; }; 4CE296191842A166005F01CE /* MPAutotypePaste.m in Sources */ = {isa = PBXBuildFile; fileRef = 4CE296181842A166005F01CE /* MPAutotypePaste.m */; }; @@ -624,6 +625,8 @@ 4CD78ABB16D155FF00768A1D /* 11_CameraTemplate.pdf */ = {isa = PBXFileReference; lastKnownFileType = image.pdf; path = 11_CameraTemplate.pdf; sourceTree = ""; }; 4CD820221A32173100399DBB /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = Base; path = Base.lproj/ReferenceBuilderView.xib; sourceTree = ""; }; 4CD884B615BD47080042BBF8 /* DocumentWindow.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = DocumentWindow.xib; sourceTree = ""; }; + 4CDE7B141D660983008C4160 /* MPObjectController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MPObjectController.h; sourceTree = ""; }; + 4CDE7B151D660983008C4160 /* MPObjectController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MPObjectController.m; sourceTree = ""; }; 4CDF01A116D1B76700D0AC08 /* MPEntryViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MPEntryViewController.h; sourceTree = ""; }; 4CDF01A216D1B76700D0AC08 /* MPEntryViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MPEntryViewController.m; sourceTree = ""; }; 4CE2961318429AA5005F01CE /* MPAutotypeKeyPress.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MPAutotypeKeyPress.h; sourceTree = ""; }; @@ -1354,6 +1357,8 @@ 4C431BCC16E2A82700700A81 /* MPPasteBoardController.m */, 4C6AEEF71A043E2B00CA2420 /* MPDocumentController.h */, 4C6AEEF81A043E2B00CA2420 /* MPDocumentController.m */, + 4CDE7B141D660983008C4160 /* MPObjectController.h */, + 4CDE7B151D660983008C4160 /* MPObjectController.m */, ); name = "Data Controller"; sourceTree = ""; @@ -1714,6 +1719,7 @@ 4CE296191842A166005F01CE /* MPAutotypePaste.m in Sources */, 4C569D9E17652B0600595B62 /* MPConstants.m in Sources */, 4C569DA117652BFE00595B62 /* MPEntryTableDataSource.m in Sources */, + 4CDE7B161D660983008C4160 /* MPObjectController.m in Sources */, 4C7B63711C0CB51F00D7038C /* NSValueTransformer+TransformerKit.m in Sources */, 4CD034AA1BFE113B003C002C /* MPPlugin.m in Sources */, 4CA2335A176DBFE100F0B6AC /* MPLockDaemon.m in Sources */, diff --git a/MacPass.xcodeproj/xcshareddata/xcschemes/MacPass.xcscheme b/MacPass.xcodeproj/xcshareddata/xcschemes/MacPass.xcscheme index 889b1fd3..7b4cc510 100644 --- a/MacPass.xcodeproj/xcshareddata/xcschemes/MacPass.xcscheme +++ b/MacPass.xcodeproj/xcshareddata/xcschemes/MacPass.xcscheme @@ -85,6 +85,10 @@ argument = "-NSConstraintBasedLayoutVisualizeMutuallyExclusiveConstraints YES" isEnabled = "NO"> + + - + diff --git a/MacPass/Base.lproj/InspectorView.xib b/MacPass/Base.lproj/InspectorView.xib index daa16da7..ba64e555 100644 --- a/MacPass/Base.lproj/InspectorView.xib +++ b/MacPass/Base.lproj/InspectorView.xib @@ -1,5 +1,5 @@ - + @@ -49,6 +49,11 @@ + + + + + @@ -58,6 +63,9 @@ + + + @@ -140,6 +148,14 @@ + + + + + No Selection + + + @@ -189,6 +205,7 @@ + diff --git a/MacPass/EntryView.xib b/MacPass/EntryView.xib index ecd3953e..0758b8fb 100644 --- a/MacPass/EntryView.xib +++ b/MacPass/EntryView.xib @@ -1,5 +1,5 @@ - + diff --git a/MacPass/MPEntryInspectorViewController.m b/MacPass/MPEntryInspectorViewController.m index 68759d06..4d8290d5 100644 --- a/MacPass/MPEntryInspectorViewController.m +++ b/MacPass/MPEntryInspectorViewController.m @@ -60,7 +60,6 @@ typedef NS_ENUM(NSUInteger, MPEntryTab) { @implementation MPEntryInspectorViewController -static NSString *kMPContentBindingString1 = @"content.%@"; static NSString *kMPContentBindingString2 = @"content.%@.%@"; static NSString *kMPContentBindingString3 = @"content.%@.%@.%@"; @@ -194,7 +193,7 @@ static NSString *kMPContentBindingString3 = @"content.%@.%@.%@"; if(row < 0) { return; // no selection } - KPKBinary *binary = self.contentEntry.binaries[row]; + KPKBinary *binary = self.representedEntry.binaries[row]; [self.representedEntry removeBinary:binary]; } @@ -205,8 +204,8 @@ static NSString *kMPContentBindingString3 = @"content.%@.%@.%@"; - (void)removeWindowAssociation:(id)sender { NSInteger row = self.windowAssociationsTableView.selectedRow; - if(row > - 1 && row < [self.contentEntry.autotype.associations count]) { - [self.representedEntry.autotype removeAssociation:self.contentEntry.autotype.associations[row]]; + if(row > - 1 && row < [self.representedEntry.autotype.associations count]) { + [self.representedEntry.autotype removeAssociation:self.representedEntry.autotype.associations[row]]; } } @@ -313,7 +312,7 @@ static NSString *kMPContentBindingString3 = @"content.%@.%@.%@"; NSString *password = [controller generatedPassword]; /* We should only use the password if there is actually one */ if(password.length > 0) { - self.contentEntry.password = [controller generatedPassword]; + self.representedEntry.password = [controller generatedPassword]; } } /* TODO: Check for Icon wizard */ @@ -371,39 +370,39 @@ static NSString *kMPContentBindingString3 = @"content.%@.%@.%@"; - (void)_bindEntry { [self.titleTextField bind:NSValueBinding - toObject:self.entryController - withKeyPath:[NSString stringWithFormat:kMPContentBindingString1, NSStringFromSelector(@selector(title))] + toObject:self + withKeyPath:[NSString stringWithFormat:@"%@.%@", NSStringFromSelector(@selector(representedObject)), NSStringFromSelector(@selector(title))] options:@{ NSNullPlaceholderBindingOption: NSLocalizedString(@"NONE", "")} ]; [self.passwordTextField bind:NSValueBinding - toObject:self.entryController - withKeyPath:[NSString stringWithFormat:kMPContentBindingString1, NSStringFromSelector(@selector(password))] + toObject:self + withKeyPath:[NSString stringWithFormat:@"%@.%@", NSStringFromSelector(@selector(representedObject)), NSStringFromSelector(@selector(password))] options:@{ NSNullPlaceholderBindingOption: NSLocalizedString(@"NONE", "") }]; [self.usernameTextField bind:NSValueBinding - toObject:self.entryController - withKeyPath:[NSString stringWithFormat:kMPContentBindingString1, NSStringFromSelector(@selector(username))] + toObject:self + withKeyPath:[NSString stringWithFormat:@"%@.%@", NSStringFromSelector(@selector(representedObject)), NSStringFromSelector(@selector(username))] options:@{ NSNullPlaceholderBindingOption: NSLocalizedString(@"NONE", "") }]; [self.URLTextField bind:NSValueBinding - toObject:self.entryController - withKeyPath:[NSString stringWithFormat:kMPContentBindingString1, NSStringFromSelector(@selector(url))] + toObject:self + withKeyPath:[NSString stringWithFormat:@"%@.%@", NSStringFromSelector(@selector(representedObject)), NSStringFromSelector(@selector(url))] options:@{ NSNullPlaceholderBindingOption: NSLocalizedString(@"NONE", "")}]; [self.expiresCheckButton bind:NSTitleBinding - toObject:self.entryController - withKeyPath:[NSString stringWithFormat:kMPContentBindingString2, NSStringFromSelector(@selector(timeInfo)), NSStringFromSelector(@selector(expirationDate))] + toObject:self + withKeyPath:[NSString stringWithFormat:@"%@.%@.%@", NSStringFromSelector(@selector(representedObject)), NSStringFromSelector(@selector(timeInfo)), NSStringFromSelector(@selector(expirationDate))] options:@{ NSValueTransformerNameBindingOption:MPExpiryDateValueTransformer }]; [self.expiresCheckButton bind:NSValueBinding - toObject:self.entryController - withKeyPath:[NSString stringWithFormat:kMPContentBindingString2, NSStringFromSelector(@selector(timeInfo)), NSStringFromSelector(@selector(expires))] + toObject:self + withKeyPath:[NSString stringWithFormat:@"%@.%@.%@", NSStringFromSelector(@selector(representedObject)), NSStringFromSelector(@selector(timeInfo)), NSStringFromSelector(@selector(expires))] options:nil]; [self.tagsTokenField bind:NSValueBinding - toObject:self.entryController - withKeyPath:[NSString stringWithFormat:kMPContentBindingString1, NSStringFromSelector(@selector(tags))] + toObject:self + withKeyPath:[NSString stringWithFormat:@"%@.%@", NSStringFromSelector(@selector(representedObject)), NSStringFromSelector(@selector(tags))] options:nil]; [self.uuidTextField bind:NSValueBinding - toObject:self.entryController - withKeyPath:[NSString stringWithFormat:kMPContentBindingString2, NSStringFromSelector(@selector(uuid)), NSStringFromSelector(@selector(UUIDString))] + toObject:self + withKeyPath:[NSString stringWithFormat:@"%@.%@.%@", NSStringFromSelector(@selector(representedObject)), NSStringFromSelector(@selector(uuid)), NSStringFromSelector(@selector(UUIDString))] options:@{ NSConditionallySetsEditableBindingOption: @NO }]; self.uuidTextField.editable = NO; @@ -414,37 +413,37 @@ static NSString *kMPContentBindingString3 = @"content.%@.%@.%@"; - (void)_bindAttachments { [_attachmentsController bind:NSContentArrayBinding - toObject:self.entryController - withKeyPath:[NSString stringWithFormat:kMPContentBindingString1, NSStringFromSelector(@selector(binaries))] + toObject:self + withKeyPath:[NSString stringWithFormat:@"%@.%@", NSStringFromSelector(@selector(representedObject)), NSStringFromSelector(@selector(binaries))] options:nil]; } - (void)_bindCustomFields { [_customFieldsController bind:NSContentArrayBinding - toObject:self.entryController - withKeyPath:[NSString stringWithFormat:kMPContentBindingString1, NSStringFromSelector(@selector(customAttributes))] + toObject:self + withKeyPath:[NSString stringWithFormat:@"%@.%@", NSStringFromSelector(@selector(representedObject)), NSStringFromSelector(@selector(customAttributes))] options:nil]; } - (void)_bindAutotype { [self.enableAutotypeCheckButton bind:NSValueBinding - toObject:self.entryController - withKeyPath:[NSString stringWithFormat:kMPContentBindingString2, NSStringFromSelector(@selector(autotype)), NSStringFromSelector(@selector(enabled))] options:nil]; + toObject:self + withKeyPath:[NSString stringWithFormat:@"%@.%@.%@", NSStringFromSelector(@selector(representedObject)), NSStringFromSelector(@selector(autotype)), NSStringFromSelector(@selector(enabled))] options:nil]; [self.obfuscateAutotypeCheckButton bind:NSValueBinding - toObject:self.entryController - withKeyPath:[NSString stringWithFormat:kMPContentBindingString2, NSStringFromSelector(@selector(autotype)), NSStringFromSelector(@selector(obfuscateDataTransfer))] + toObject:self + withKeyPath:[NSString stringWithFormat:@"%@.%@.%@", NSStringFromSelector(@selector(representedObject)), NSStringFromSelector(@selector(autotype)), NSStringFromSelector(@selector(obfuscateDataTransfer))] options:nil]; [self.customEntrySequenceTextField bind:NSEnabledBinding - toObject:self.entryController - withKeyPath:[NSString stringWithFormat:kMPContentBindingString2, NSStringFromSelector(@selector(autotype)), NSStringFromSelector(@selector(enabled))] + toObject:self + withKeyPath:[NSString stringWithFormat:@"%@.%@.%@", NSStringFromSelector(@selector(representedObject)), NSStringFromSelector(@selector(autotype)), NSStringFromSelector(@selector(enabled))] options:nil]; [self.customEntrySequenceTextField bind:NSValueBinding - toObject:self.entryController - withKeyPath:[NSString stringWithFormat:kMPContentBindingString2, NSStringFromSelector(@selector(autotype)), NSStringFromSelector(@selector(defaultKeystrokeSequence))] + toObject:self + withKeyPath:[NSString stringWithFormat:@"%@.%@.%@", NSStringFromSelector(@selector(representedObject)), NSStringFromSelector(@selector(autotype)), NSStringFromSelector(@selector(defaultKeystrokeSequence))] options:@{ NSValidatesImmediatelyBindingOption: @YES }]; [_windowAssociationsController bind:NSContentArrayBinding - toObject:self.entryController - withKeyPath:[NSString stringWithFormat:kMPContentBindingString2, NSStringFromSelector(@selector(autotype)), NSStringFromSelector(@selector(associations))] + toObject:self + withKeyPath:[NSString stringWithFormat:@"%@.%@.%@", NSStringFromSelector(@selector(representedObject)), NSStringFromSelector(@selector(autotype)), NSStringFromSelector(@selector(associations))] options:@{ NSSelectsAllWhenSettingContentBindingOption: @NO }]; [self.windowTitleComboBox setStringValue:@""]; [self.windowTitleComboBox bind:NSValueBinding diff --git a/MacPass/MPGroupInspectorViewController.m b/MacPass/MPGroupInspectorViewController.m index 3bbe8166..ec78ac55 100644 --- a/MacPass/MPGroupInspectorViewController.m +++ b/MacPass/MPGroupInspectorViewController.m @@ -10,6 +10,7 @@ #import "MPDocument.h" #import "MPPasteBoardController.h" #import "MPValueTransformerHelper.h" +#import "MPObjectController.h" #import "KeePassKit/KeePassKit.h" @@ -19,7 +20,7 @@ //@property (nonatomic, weak) KPKGroup *group; @property (strong) NSPopover *popover; -@property (strong) NSObjectController *groupController; +@property (strong) MPObjectController *groupController; @end @@ -32,7 +33,7 @@ - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil { self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; if (self) { - _groupController = [[NSObjectController alloc] init]; + _groupController = [[MPObjectController alloc] init]; } return self; } @@ -85,7 +86,6 @@ - (void)setupBindings:(MPDocument *)document { [self.groupController bind:NSContentObjectBinding toObject:self withKeyPath:NSStringFromSelector(@selector(representedObject)) options:nil]; - //[self.groupController bind:NSContentObjectBinding toObject:document withKeyPath:NSStringFromSelector(@selector(selectedGroup)) options:nil]; } - (void)_establishBindings { diff --git a/MacPass/MPObjectController.h b/MacPass/MPObjectController.h index 724fa36f..2556ac4c 100644 --- a/MacPass/MPObjectController.h +++ b/MacPass/MPObjectController.h @@ -10,4 +10,6 @@ @interface MPObjectController : NSObjectController +@property (weak) NSDocument *document; + @end diff --git a/MacPass/MPObjectController.m b/MacPass/MPObjectController.m index 458c9432..ae65330b 100644 --- a/MacPass/MPObjectController.m +++ b/MacPass/MPObjectController.m @@ -10,4 +10,34 @@ @implementation MPObjectController +//- (void)objectDidBeginEditing:(id)editor { +// NSLog(@"objectDidBeginEditing:%@", editor); +// [super objectDidBeginEditing:editor]; +//} +//- (void)objectDidEndEditing:(id)editor { +// NSLog(@"objectDidEndEditing:%@", editor); +// [super objectDidEndEditing:editor]; +//} + +- (void)discardEditing { + [super discardEditing]; +} + +- (BOOL)commitEditing { + return [super commitEditing]; +} + + +//- (BOOL)commitEditing { +// return [super commitEditing]; +//} +// +//- (BOOL)commitEditingAndReturnError:(NSError * _Nullable __autoreleasing *)error { +// return [super commitEditingAndReturnError:error]; +//} +// +//- (void)commitEditingWithDelegate:(id)delegate didCommitSelector:(SEL)didCommitSelector contextInfo:(void *)contextInfo { +// [super commitEditingWithDelegate:delegate didCommitSelector:didCommitSelector contextInfo:contextInfo]; +//} + @end diff --git a/MacPass/MPPasswordCreatorViewController.m b/MacPass/MPPasswordCreatorViewController.m index b6168b24..afaf31fb 100644 --- a/MacPass/MPPasswordCreatorViewController.m +++ b/MacPass/MPPasswordCreatorViewController.m @@ -196,7 +196,7 @@ typedef NS_ENUM(NSUInteger, MPPasswordRating) { if(!availableDefaults) { availableDefaults = [[NSMutableDictionary alloc] initWithCapacity:1]; } - availableDefaults[[self.entry.uuid UUIDString]] = entryDefaults; + availableDefaults[[self.representedObject uuid].UUIDString] = entryDefaults; [[NSUserDefaults standardUserDefaults] setObject:availableDefaults forKey:kMPSettingsKeyPasswordDefaultsForEntry]; } else if(!self.useEntryDefaults) { @@ -218,7 +218,7 @@ typedef NS_ENUM(NSUInteger, MPPasswordRating) { } NSMutableDictionary *availableDefaults = [[self _availableEntryDefaults] mutableCopy]; NSAssert(availableDefaults, @"Password generator defaults for should be present!"); - [availableDefaults removeObjectForKey:[self.entry.uuid UUIDString]]; + [availableDefaults removeObjectForKey:[self.representedObject uuid].UUIDString]; [[NSUserDefaults standardUserDefaults] setObject:availableDefaults forKey:kMPSettingsKeyPasswordDefaultsForEntry]; self.useEntryDefaults = NO; /* Resetting the UI and Defaults is handled via the setter */ [self _updateSetDefaultsButton:NO];