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

View File

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

View File

@ -8,6 +8,8 @@
#import "Transformers.h"
#import <AppKit/NSColor.h>
@implementation FilePathTransformer
+ (Class)transformedValueClass {
@ -55,6 +57,22 @@
@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) {
@ -65,4 +83,6 @@ void RegisterTransformers(void) {
t = [FilePathTransformer new];
[NSValueTransformer setValueTransformer: t forName: @"FilePathTransformer"];
t = [ValidColorTransformer new];
[NSValueTransformer setValueTransformer: t forName: @"ValidColorTransformer"];
}