bind the media eject button.

contentTintColor is not exposed in interface builder, otherwise it could
all be handled there.
This commit is contained in:
Kelvin Sherlock 2020-09-27 22:06:03 -04:00
parent 68136487ff
commit 4425fe33f8
3 changed files with 41 additions and 6 deletions

View File

@ -163,7 +163,7 @@
[item setIndex: ix]; [item setIndex: ix];
[item setValid: ix < _validCount]; [item setValid: ix < _validCount];
[view reloadItem: item]; // [view reloadItem: item];
++ix; ++ix;
} }
@ -201,21 +201,33 @@
} }
-(void)prepareView: (TablePathView *)view { -(void)prepareView: (TablePathView *)view {
NSValueTransformer *t;
NSDictionary *options;
NSPathControl *pc = [view pathControl]; NSPathControl *pc = [view pathControl];
NSButton *button = [view ejectButton]; NSButton *button = [view ejectButton];
[pc unbind: @"value"]; [pc unbind: @"value"];
[pc unbind: @"enabled"];
[pc bind: @"value" toObject: self withKeyPath: @"url" options: nil]; [pc bind: @"value" toObject: self withKeyPath: @"url" options: nil];
[pc bind: @"enabled" toObject: self withKeyPath: @"valid" options: options];
[button unbind: @"enabled"]; [button unbind: @"enabled"];
NSValueTransformer *t = [NSValueTransformer valueTransformerForName: NSIsNotNilTransformerName]; [button unbind: @"contentTintColor"];
NSDictionary *options = @{ NSValueTransformerBindingOption: t}; t = [NSValueTransformer valueTransformerForName: NSIsNotNilTransformerName];
options = @{ NSValueTransformerBindingOption: t};
[button bind: @"enabled" toObject: self withKeyPath: @"url" options: options]; [button bind: @"enabled" toObject: self withKeyPath: @"url" options: options];
t = [NSValueTransformer valueTransformerForName: @"ValidColorTransformer"];
options = @{ NSValueTransformerBindingOption: t};
[button bind: @"contentTintColor" toObject: self withKeyPath: @"valid" options: options];
#if 0
NSColor *tintColor = nil; NSColor *tintColor = nil;
if (!_valid) tintColor = [NSColor redColor]; if (!_valid) tintColor = [NSColor redColor];
[button setContentTintColor: tintColor]; [button setContentTintColor: tintColor];
#endif
} }
-(CGFloat)height { -(CGFloat)height {
@ -223,7 +235,8 @@
} }
-(void)invalidate { -(void)invalidate {
_valid = NO; if (!_valid) return;
[self setValid: NO];
} }
@end @end
@ -391,6 +404,7 @@ static NSString *kDragType = @"private.ample.media";
if (!ident) return nil; if (!ident) return nil;
NSTableCellView *v = [outlineView makeViewWithIdentifier: ident owner: self]; NSTableCellView *v = [outlineView makeViewWithIdentifier: ident owner: self];
[(id<MediaNode>)item prepareView: v]; [(id<MediaNode>)item prepareView: v];
[v setObjectValue: item];
return v; return v;
} }

View File

@ -13,11 +13,12 @@ void RegisterTransformers(void);
NS_ASSUME_NONNULL_BEGIN NS_ASSUME_NONNULL_BEGIN
@interface FilePathTransformer : NSValueTransformer @interface FilePathTransformer : NSValueTransformer
@end @end
@interface FileSizeTransformer : NSValueTransformer @interface FileSizeTransformer : NSValueTransformer
@end
@interface ValidColorTransformer : NSValueTransformer
@end @end

View File

@ -8,6 +8,8 @@
#import "Transformers.h" #import "Transformers.h"
#import <AppKit/NSColor.h>
@implementation FilePathTransformer @implementation FilePathTransformer
+ (Class)transformedValueClass { + (Class)transformedValueClass {
@ -55,6 +57,22 @@
@end @end
@implementation ValidColorTransformer
+ (BOOL)allowsReverseTransformation {
return NO;
}
+ (Class)transformedValueClass {
return [NSColor class];
}
- (id)transformedValue:(id)value {
BOOL valid = [(NSNumber *)value boolValue];
return valid ? nil : [NSColor redColor];
}
@end
void RegisterTransformers(void) { void RegisterTransformers(void) {
@ -65,4 +83,6 @@ void RegisterTransformers(void) {
t = [FilePathTransformer new]; t = [FilePathTransformer new];
[NSValueTransformer setValueTransformer: t forName: @"FilePathTransformer"]; [NSValueTransformer setValueTransformer: t forName: @"FilePathTransformer"];
t = [ValidColorTransformer new];
[NSValueTransformer setValueTransformer: t forName: @"ValidColorTransformer"];
} }