customTableView now does not rely on windowController for observer lookup

This commit is contained in:
michael starke
2017-02-04 00:14:36 +01:00
parent 2e7e032007
commit 2d6582240d
5 changed files with 13 additions and 5 deletions

View File

@@ -7,6 +7,7 @@
// //
#import <Cocoa/Cocoa.h> #import <Cocoa/Cocoa.h>
#import "MPModelChangeObserving.h"
@interface MPCustomFieldTableCellView : NSTableCellView @interface MPCustomFieldTableCellView : NSTableCellView
@@ -14,4 +15,6 @@
@property (nonatomic, weak) IBOutlet NSTextField *valueTextField; @property (nonatomic, weak) IBOutlet NSTextField *valueTextField;
@property (nonatomic, weak) IBOutlet NSButton *removeButton; @property (nonatomic, weak) IBOutlet NSButton *removeButton;
@property (weak) id<MPModelChangeObserving> observer;
@end @end

View File

@@ -25,10 +25,12 @@
- (void)setValue:(id)value forKeyPath:(NSString *)keyPath { - (void)setValue:(id)value forKeyPath:(NSString *)keyPath {
if([keyPath hasPrefix:@"objectValue."]) { if([keyPath hasPrefix:@"objectValue."]) {
[self.window.windowController.document willChangeModelProperty]; [self.observer willChangeModelProperty];
[super setValue:value forKeyPath:keyPath]; [super setValue:value forKeyPath:keyPath];
[self.window.windowController.document didChangeModelProperty]; [self.observer didChangeModelProperty];
} }
else {
[super setValue:value forKeyPath:keyPath]; [super setValue:value forKeyPath:keyPath];
} }
}
@end @end

View File

@@ -43,6 +43,8 @@
view.removeButton.action = @selector(removeCustomField:); view.removeButton.action = @selector(removeCustomField:);
view.removeButton.tag = row; view.removeButton.tag = row;
view.observer = tableView.window.windowController.document;
return view; return view;
} }

View File

@@ -34,7 +34,7 @@
} }
- (void)didLoadView { - (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 bind:NSContentBinding toObject:self.pluginDataController withKeyPath:NSStringFromSelector(@selector(arrangedObjects)) options:nil];
self.pluginDataTabelView.backgroundColor = [NSColor clearColor]; self.pluginDataTabelView.backgroundColor = [NSColor clearColor];
} }
@@ -60,6 +60,7 @@
toObject:view toObject:view
withKeyPath:[NSString stringWithFormat:@"%@.%@", NSStringFromSelector(@selector(objectValue)), NSStringFromSelector(@selector(key))] withKeyPath:[NSString stringWithFormat:@"%@.%@", NSStringFromSelector(@selector(objectValue)), NSStringFromSelector(@selector(key))]
options:nil]; options:nil];
view.observer = self.observer;
return view; return view;
} }