From 2d6582240d21b60c0f639aab15c34b19a69faa8b Mon Sep 17 00:00:00 2001 From: michael starke Date: Sat, 4 Feb 2017 00:14:36 +0100 Subject: [PATCH] customTableView now does not rely on windowController for observer lookup --- MacPass/MPCustomFieldTableCellView.h | 3 +++ MacPass/MPCustomFieldTableCellView.m | 8 +++++--- MacPass/MPCustomFieldTableViewDelegate.m | 2 ++ MacPass/MPPluginDataViewController.m | 3 ++- MacPass/MPViewController.h | 2 +- 5 files changed, 13 insertions(+), 5 deletions(-) diff --git a/MacPass/MPCustomFieldTableCellView.h b/MacPass/MPCustomFieldTableCellView.h index a3d0a80a..db89aade 100644 --- a/MacPass/MPCustomFieldTableCellView.h +++ b/MacPass/MPCustomFieldTableCellView.h @@ -7,6 +7,7 @@ // #import +#import "MPModelChangeObserving.h" @interface MPCustomFieldTableCellView : NSTableCellView @@ -14,4 +15,6 @@ @property (nonatomic, weak) IBOutlet NSTextField *valueTextField; @property (nonatomic, weak) IBOutlet NSButton *removeButton; +@property (weak) id observer; + @end diff --git a/MacPass/MPCustomFieldTableCellView.m b/MacPass/MPCustomFieldTableCellView.m index 64cc641d..bcc0542b 100644 --- a/MacPass/MPCustomFieldTableCellView.m +++ b/MacPass/MPCustomFieldTableCellView.m @@ -25,10 +25,12 @@ - (void)setValue:(id)value forKeyPath:(NSString *)keyPath { if([keyPath hasPrefix:@"objectValue."]) { - [self.window.windowController.document willChangeModelProperty]; + [self.observer willChangeModelProperty]; + [super setValue:value forKeyPath:keyPath]; + [self.observer didChangeModelProperty]; + } + else { [super setValue:value forKeyPath:keyPath]; - [self.window.windowController.document didChangeModelProperty]; } - [super setValue:value forKeyPath:keyPath]; } @end diff --git a/MacPass/MPCustomFieldTableViewDelegate.m b/MacPass/MPCustomFieldTableViewDelegate.m index 3293effb..071ff574 100644 --- a/MacPass/MPCustomFieldTableViewDelegate.m +++ b/MacPass/MPCustomFieldTableViewDelegate.m @@ -43,6 +43,8 @@ view.removeButton.action = @selector(removeCustomField:); view.removeButton.tag = row; + view.observer = tableView.window.windowController.document; + return view; } diff --git a/MacPass/MPPluginDataViewController.m b/MacPass/MPPluginDataViewController.m index b213945b..9ecb1565 100644 --- a/MacPass/MPPluginDataViewController.m +++ b/MacPass/MPPluginDataViewController.m @@ -34,7 +34,7 @@ } - (void)didLoadView { - [self.pluginDataController bind:NSContentDictionaryBinding toObject:self.representedObject withKeyPath:NSStringFromSelector(@selector(customData)) options:nil]; + [self.pluginDataController bind:NSContentDictionaryBinding toObject:self.representedObject withKeyPath:NSStringFromSelector(@selector(mutableCustomData)) options:nil]; [self.pluginDataTabelView bind:NSContentBinding toObject:self.pluginDataController withKeyPath:NSStringFromSelector(@selector(arrangedObjects)) options:nil]; self.pluginDataTabelView.backgroundColor = [NSColor clearColor]; } @@ -60,6 +60,7 @@ toObject:view withKeyPath:[NSString stringWithFormat:@"%@.%@", NSStringFromSelector(@selector(objectValue)), NSStringFromSelector(@selector(key))] options:nil]; + view.observer = self.observer; return view; } diff --git a/MacPass/MPViewController.h b/MacPass/MPViewController.h index b56c35b5..0be43eb8 100644 --- a/MacPass/MPViewController.h +++ b/MacPass/MPViewController.h @@ -18,4 +18,4 @@ - (void)didLoadView; - (void)updateResponderChain; -@end \ No newline at end of file +@end