From a5a6222c9fb4fc37c95798ba9ce7aeb8066ad7b8 Mon Sep 17 00:00:00 2001 From: Kelvin Sherlock Date: Sun, 13 Jun 2021 12:26:56 -0400 Subject: [PATCH] use bindings for media table views --- Ample/Base.lproj/MediaView.xib | 11 ++++++++++ Ample/MediaViewController.m | 38 ++-------------------------------- Ample/TableCellView.m | 18 ++++++++++++++++ 3 files changed, 31 insertions(+), 36 deletions(-) diff --git a/Ample/Base.lproj/MediaView.xib b/Ample/Base.lproj/MediaView.xib index ee41653..2667ee2 100644 --- a/Ample/Base.lproj/MediaView.xib +++ b/Ample/Base.lproj/MediaView.xib @@ -1,6 +1,7 @@ + @@ -51,6 +52,9 @@ + + + @@ -69,6 +73,8 @@ + + @@ -85,6 +91,11 @@ + + + NSIsNotNil + + diff --git a/Ample/MediaViewController.m b/Ample/MediaViewController.m index 0e436e6..d4649e6 100644 --- a/Ample/MediaViewController.m +++ b/Ample/MediaViewController.m @@ -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)item prepareView: v]; [v setObjectValue: item]; + + [(id)item prepareView: v]; return v; } diff --git a/Ample/TableCellView.m b/Ample/TableCellView.m index 165c044..ea70e02 100644 --- a/Ample/TableCellView.m +++ b/Ample/TableCellView.m @@ -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 {