More transitions to representedObject for ViewController

This commit is contained in:
michael starke
2016-08-23 18:43:13 +02:00
parent b7fe98b410
commit 7755bc9b93
10 changed files with 101 additions and 43 deletions

View File

@@ -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 = "<group>"; };
4CD820221A32173100399DBB /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = Base; path = Base.lproj/ReferenceBuilderView.xib; sourceTree = "<group>"; };
4CD884B615BD47080042BBF8 /* DocumentWindow.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = DocumentWindow.xib; sourceTree = "<group>"; };
4CDE7B141D660983008C4160 /* MPObjectController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MPObjectController.h; sourceTree = "<group>"; };
4CDE7B151D660983008C4160 /* MPObjectController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MPObjectController.m; sourceTree = "<group>"; };
4CDF01A116D1B76700D0AC08 /* MPEntryViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MPEntryViewController.h; sourceTree = "<group>"; };
4CDF01A216D1B76700D0AC08 /* MPEntryViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MPEntryViewController.m; sourceTree = "<group>"; };
4CE2961318429AA5005F01CE /* MPAutotypeKeyPress.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MPAutotypeKeyPress.h; sourceTree = "<group>"; };
@@ -1354,6 +1357,8 @@
4C431BCC16E2A82700700A81 /* MPPasteBoardController.m */,
4C6AEEF71A043E2B00CA2420 /* MPDocumentController.h */,
4C6AEEF81A043E2B00CA2420 /* MPDocumentController.m */,
4CDE7B141D660983008C4160 /* MPObjectController.h */,
4CDE7B151D660983008C4160 /* MPObjectController.m */,
);
name = "Data Controller";
sourceTree = "<group>";
@@ -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 */,

View File

@@ -85,6 +85,10 @@
argument = "-NSConstraintBasedLayoutVisualizeMutuallyExclusiveConstraints YES"
isEnabled = "NO">
</CommandLineArgument>
<CommandLineArgument
argument = "-NSBindingDebugLogLevel YES"
isEnabled = "YES">
</CommandLineArgument>
</CommandLineArguments>
<EnvironmentVariables>
<EnvironmentVariable

View File

@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="10117" systemVersion="15F34" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES">
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="10117" systemVersion="15G31" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES">
<dependencies>
<deployment identifier="macosx"/>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="10117"/>

View File

@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="10117" systemVersion="15F34" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES">
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="10117" systemVersion="15G31" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES">
<dependencies>
<deployment identifier="macosx"/>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="10117"/>
@@ -49,6 +49,11 @@
<imageCell key="cell" alignment="left" imageScaling="proportionallyUpOrDown" image="NSActionTemplate" id="2999"/>
<connections>
<action selector="pickIcon:" target="-2" id="6wh-Ka-Thl"/>
<binding destination="-2" name="value" keyPath="representedObject.iconImage" id="agf-eg-okr">
<dictionary key="options">
<bool key="NSConditionallySetsEnabled" value="NO"/>
</dictionary>
</binding>
</connections>
</imageView>
<textField verticalHuggingPriority="750" horizontalCompressionResistancePriority="249" translatesAutoresizingMaskIntoConstraints="NO" id="3013">
@@ -58,6 +63,9 @@
<color key="textColor" name="controlTextColor" catalog="System" colorSpace="catalog"/>
<color key="backgroundColor" name="controlColor" catalog="System" colorSpace="catalog"/>
</textFieldCell>
<connections>
<binding destination="-2" name="value" keyPath="representedObject.title" id="2ek-Ns-ybY"/>
</connections>
</textField>
<splitView autosaveName="InspectorNotesSplitView" dividerStyle="thin" translatesAutoresizingMaskIntoConstraints="NO" id="3145">
<rect key="frame" x="0.0" y="30" width="278" height="582"/>
@@ -140,6 +148,14 @@
<color key="insertionPointColor" white="0.0" alpha="1" colorSpace="calibratedWhite"/>
<size key="minSize" width="236" height="177"/>
<size key="maxSize" width="463" height="10000000"/>
<connections>
<binding destination="-2" name="value" keyPath="representedObject.notes" id="E0d-ZH-Wbc">
<dictionary key="options">
<bool key="NSConditionallySetsEditable" value="NO"/>
<string key="NSNoSelectionPlaceholder">No Selection</string>
</dictionary>
</binding>
</connections>
</textView>
</subviews>
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
@@ -189,6 +205,7 @@
</constraints>
<point key="canvasLocation" x="268" y="-437"/>
</customView>
<userDefaultsController representsSharedInstance="YES" id="U5N-S2-0zc"/>
</objects>
<resources>
<image name="NSActionTemplate" width="14" height="14"/>

View File

@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="10117" systemVersion="15F34" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES">
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="10117" systemVersion="15G31" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES">
<dependencies>
<deployment identifier="macosx"/>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="10117"/>

View File

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

View File

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

View File

@@ -10,4 +10,6 @@
@interface MPObjectController : NSObjectController
@property (weak) NSDocument *document;
@end

View File

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

View File

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