diff --git a/MacPass/KPKNode+IconImage.m b/MacPass/KPKNode+IconImage.m index 2d374dcd..5903982e 100644 --- a/MacPass/KPKNode+IconImage.m +++ b/MacPass/KPKNode+IconImage.m @@ -27,8 +27,11 @@ #import "MPIconHelper.h" @interface NSImage (MPTintedImage) + @end + @implementation NSImage (MPTintedImage) + - (NSImage *)imageWithTintColor:(NSColor *)tintColor { /* only tint templated images! */ if(NO == self.template) { @@ -42,6 +45,7 @@ image.template = NO; return image; } + @end @implementation KPKNode (IconImage) diff --git a/MacPass/MPEntryAttributeViewController.m b/MacPass/MPEntryAttributeViewController.m index 58cae97c..312c7973 100644 --- a/MacPass/MPEntryAttributeViewController.m +++ b/MacPass/MPEntryAttributeViewController.m @@ -235,10 +235,6 @@ NSString *nameForDefaultKey(NSString *key) { self.actionButton.hidden = YES; } -- (void)commitChanges { - // to nothing -} - - (void)objectDidBeginEditing:(id)editor { [self.view.window.windowController.document objectDidBeginEditing:editor]; [super objectDidBeginEditing:editor]; diff --git a/MacPass/MPInspectorEditor.h b/MacPass/MPInspectorEditor.h index 4605e66d..ca20513b 100644 --- a/MacPass/MPInspectorEditor.h +++ b/MacPass/MPInspectorEditor.h @@ -20,7 +20,6 @@ NS_ASSUME_NONNULL_BEGIN @protocol MPInspectorEditor @required @property (nonatomic) BOOL isEditor; -- (void)commitChanges; @end /// NodeInspectorEditors require the represented object to be a KPKNode diff --git a/MacPass/MPNodeExpirationViewController.m b/MacPass/MPNodeExpirationViewController.m index e115b9a5..d7c29614 100644 --- a/MacPass/MPNodeExpirationViewController.m +++ b/MacPass/MPNodeExpirationViewController.m @@ -59,10 +59,6 @@ [self _updateValues]; } -- (void)commitChanges { - // write back expiration changes -} - - (void)_updateValues { self.view.hidden = !self.representedTimeInfo.expires; self.expiredCheckButton.state = HNHUIStateForBool(self.representedTimeInfo.expires); diff --git a/MacPass/MPNodeIconViewController.m b/MacPass/MPNodeIconViewController.m index 7a330fb8..f58f1f1c 100644 --- a/MacPass/MPNodeIconViewController.m +++ b/MacPass/MPNodeIconViewController.m @@ -13,7 +13,7 @@ #import "KPKNode+IconImage.h" @interface MPNodeIconViewController () -@property (strong) IBOutlet NSImageView *imageView; +@property (strong) IBOutlet NSButton *imageButton; @property (strong) IBOutlet NSTextField *textField; @property (copy) NSUUID *iconUUID; @property NSUInteger iconId; @@ -25,40 +25,15 @@ - (void)viewDidLoad { [super viewDidLoad]; - self.imageView.cell.backgroundStyle = NSBackgroundStyleRaised; - self.textField.placeholderString = NSLocalizedString(@"NO_TITLE", @"Fallback to items with no title"); -} - -- (void)setRepresentedObject:(id)representedObject { - if(self.representedNode) { - KPKNode *node = self.representedNode; - if(node.asEntry) { - [NSNotificationCenter.defaultCenter removeObserver:self name:KPKWillChangeEntryNotification object:self.representedObject]; - [NSNotificationCenter.defaultCenter removeObserver:self name:KPKDidChangeEntryNotification object:self.representedObject]; - } - else if(node.asGroup) { - [NSNotificationCenter.defaultCenter removeObserver:self name:KPKWillChangeGroupNotification object:self.representedObject]; - [NSNotificationCenter.defaultCenter removeObserver:self name:KPKDidChangeGroupNotification object:self.representedObject]; - } - else { - NSLog(@"Inconsitant state for notification handling"); - } - } - super.representedObject = representedObject; - if(self.representedNode) { - KPKNode *node = self.representedNode; - if(node.asEntry) { - [NSNotificationCenter.defaultCenter addObserver:self selector:@selector(_willChangeNode:) name:KPKWillChangeEntryNotification object:self.representedObject]; - [NSNotificationCenter.defaultCenter addObserver:self selector:@selector(_didChangeNode:) name:KPKDidChangeEntryNotification object:self.representedObject]; - } - else if(node.asGroup) { - [NSNotificationCenter.defaultCenter addObserver:self selector:@selector(_willChangeNode:) name:KPKWillChangeGroupNotification object:self.representedObject]; - [NSNotificationCenter.defaultCenter addObserver:self selector:@selector(_didChangeNode:) name:KPKDidChangeGroupNotification object:self.representedObject]; - } - else { - NSLog(@"Inconsitant state for notification handling"); - } - } + //self.imageView.cell.backgroundStyle = NSBackgroundStyleRaised; + [self.imageButton bind:NSImageBinding + toObject:self + withKeyPath:[NSString stringWithFormat:@"%@.%@", NSStringFromSelector(@selector(representedObject)), NSStringFromSelector(@selector(iconImage))] + options:@{NSConditionallySetsEnabledBindingOption: @NO}]; + [self.textField bind:NSValueBinding + toObject:self + withKeyPath:[NSString stringWithFormat:@"%@.%@", NSStringFromSelector(@selector(representedObject)), NSStringFromSelector(@selector(title))] + options:@{NSNullPlaceholderBindingOption:NSLocalizedString(@"NO_TITLE", @"Fallback to items with no title")}]; [self _updateValueAndEditing]; } @@ -75,24 +50,7 @@ } - (void)_updateValueAndEditing { - self.imageView.enabled = self.isEditor; - self.iconUUID = self.representedNode.iconUUID; - self.iconId = self.representedNode.iconId; - self.imageView.image = self.representedNode.iconImage; - self.textField.stringValue = self.representedNode.title.length > 0 ? self.representedNode.title : @""; -} - -- (void)commitChanges { - self.representedNode.iconUUID = self.iconUUID; - self.representedNode.iconId = self.iconId; -} - -- (void)_willChangeNode:(NSNotification *)notification { - -} - -- (void)_didChangeNode:(NSNotification *)notification { - [self _updateValueAndEditing]; + self.imageButton.enabled = self.isEditor; } @end diff --git a/MacPass/MPNodeIconViewController.xib b/MacPass/MPNodeIconViewController.xib index 5cf5d274..8a363253 100644 --- a/MacPass/MPNodeIconViewController.xib +++ b/MacPass/MPNodeIconViewController.xib @@ -8,9 +8,8 @@ - + - @@ -20,14 +19,6 @@ - - - - - - - - @@ -38,24 +29,38 @@ + - - - + + - - + + +