use bindings for media table views

This commit is contained in:
Kelvin Sherlock 2021-06-13 12:26:56 -04:00
parent 058da073ee
commit a5a6222c9f
3 changed files with 31 additions and 36 deletions

View File

@ -1,6 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="15705" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" customObjectInstantitationMethod="direct">
<dependencies>
<deployment identifier="macosx"/>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="15705"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
@ -51,6 +52,9 @@
<color key="textColor" name="controlTextColor" catalog="System" colorSpace="catalog"/>
<color key="backgroundColor" name="controlColor" catalog="System" colorSpace="catalog"/>
</textFieldCell>
<connections>
<binding destination="33q-UT-ur5" name="value" keyPath="objectValue.title" id="JQR-UW-ifh"/>
</connections>
</textField>
</subviews>
<connections>
@ -69,6 +73,8 @@
</pathCell>
<connections>
<action selector="pathAction:" target="-2" id="4oX-bW-ANp"/>
<binding destination="yGq-lc-RCM" name="enabled" keyPath="objectValue.valid" id="f8P-gt-vmK"/>
<binding destination="yGq-lc-RCM" name="value" keyPath="objectValue.url" id="Ony-ph-VVo"/>
</connections>
</pathControl>
<imageView horizontalHuggingPriority="251" verticalHuggingPriority="251" id="6g1-NT-J1w">
@ -85,6 +91,11 @@
</buttonCell>
<connections>
<action selector="ejectAction:" target="-2" id="XAl-eQ-nUj"/>
<binding destination="yGq-lc-RCM" name="enabled" keyPath="objectValue.url" id="suf-EI-g6t">
<dictionary key="options">
<string key="NSValueTransformerName">NSIsNotNil</string>
</dictionary>
</binding>
</connections>
</button>
</subviews>

View File

@ -81,8 +81,6 @@
-(void)prepareView: (NSTableCellView *)view {
[view setObjectValue: self];
[[view textField] setStringValue: _title];
}
-(CGFloat)height {
@ -208,39 +206,6 @@
-(void)prepareView: (TablePathView *)view {
NSValueTransformer *t;
NSDictionary *options;
[view setObjectValue: self];
NSPathControl *pc = [view pathControl];
NSButton *button = [view ejectButton];
[pc unbind: @"value"];
[pc unbind: @"enabled"];
[pc bind: @"value" toObject: self withKeyPath: @"url" options: nil];
[pc bind: @"enabled" toObject: self withKeyPath: @"valid" options: options];
[button unbind: @"enabled"];
t = [NSValueTransformer valueTransformerForName: NSIsNotNilTransformerName];
options = @{ NSValueTransformerBindingOption: t};
[button bind: @"enabled" toObject: self withKeyPath: @"url" options: options];
if (@available(macOS 10.14, *)) {
[button unbind: @"contentTintColor"];
t = [NSValueTransformer valueTransformerForName: @"ValidColorTransformer"];
options = @{ NSValueTransformerBindingOption: t};
[button bind: @"contentTintColor" toObject: self withKeyPath: @"valid" options: options];
} else {
// El Capitan TODO...
}
#if 0
NSColor *tintColor = nil;
if (!_valid) tintColor = [NSColor systemRedColor];
[button setContentTintColor: tintColor];
#endif
}
-(CGFloat)height {
@ -436,8 +401,9 @@ static NSString *kDragType = @"private.ample.media";
NSString *ident = [item viewIdentifier];
if (!ident) return nil;
NSTableCellView *v = [outlineView makeViewWithIdentifier: ident owner: self];
[(id<MediaNode>)item prepareView: v];
[v setObjectValue: item];
[(id<MediaNode>)item prepareView: v];
return v;
}

View File

@ -14,6 +14,24 @@
NSTrackingRectTag _trackingRect;
}
-(void)awakeFromNib {
// need to do it here for 10.11 compatibility.
if (@available(macOS 10.14, *)) {
NSValueTransformer *t;
NSDictionary *options;
t = [NSValueTransformer valueTransformerForName: @"ValidColorTransformer"];
options = @{ NSValueTransformerBindingOption: t};
[_ejectButton bind: @"contentTintColor" toObject: self withKeyPath: @"objectValue.valid" options: options];
} else {
// El Capitan TODO...
}
}
#if 0
-(void)awakeFromNib {