aboutsummaryrefslogtreecommitdiffstats
path: root/Framework/MASShortcutView.m
diff options
context:
space:
mode:
Diffstat (limited to 'Framework/MASShortcutView.m')
-rw-r--r--Framework/MASShortcutView.m50
1 files changed, 50 insertions, 0 deletions
diff --git a/Framework/MASShortcutView.m b/Framework/MASShortcutView.m
index 6f562a5..d03efbc 100644
--- a/Framework/MASShortcutView.m
+++ b/Framework/MASShortcutView.m
@@ -1,6 +1,8 @@
#import "MASShortcutView.h"
#import "MASShortcutValidator.h"
+NSString *const MASShortcutBinding = @"shortcutValue";
+
#define HINT_BUTTON_WIDTH 23.0
#define BUTTON_FONT_SIZE 11.0
#define SEGMENT_CHROME_WIDTH 6.0
@@ -149,6 +151,7 @@
_shortcutValue = shortcutValue;
[self resetToolTips];
[self setNeedsDisplay:YES];
+ [self propagateValue:shortcutValue forBinding:@"shortcutValue"];
if (self.shortcutValueChange) {
self.shortcutValueChange(self);
@@ -462,4 +465,51 @@ void *kUserDataHint = &kUserDataHint;
}
}
+#pragma mark Bindings
+
+// http://tomdalling.com/blog/cocoa/implementing-your-own-cocoa-bindings/
+-(void) propagateValue:(id)value forBinding:(NSString*)binding;
+{
+ NSParameterAssert(binding != nil);
+
+ //WARNING: bindingInfo contains NSNull, so it must be accounted for
+ NSDictionary* bindingInfo = [self infoForBinding:binding];
+ if(!bindingInfo)
+ return; //there is no binding
+
+ //apply the value transformer, if one has been set
+ NSDictionary* bindingOptions = [bindingInfo objectForKey:NSOptionsKey];
+ if(bindingOptions){
+ NSValueTransformer* transformer = [bindingOptions valueForKey:NSValueTransformerBindingOption];
+ if(!transformer || (id)transformer == [NSNull null]){
+ NSString* transformerName = [bindingOptions valueForKey:NSValueTransformerNameBindingOption];
+ if(transformerName && (id)transformerName != [NSNull null]){
+ transformer = [NSValueTransformer valueTransformerForName:transformerName];
+ }
+ }
+
+ if(transformer && (id)transformer != [NSNull null]){
+ if([[transformer class] allowsReverseTransformation]){
+ value = [transformer reverseTransformedValue:value];
+ } else {
+ NSLog(@"WARNING: binding \"%@\" has value transformer, but it doesn't allow reverse transformations in %s", binding, __PRETTY_FUNCTION__);
+ }
+ }
+ }
+
+ id boundObject = [bindingInfo objectForKey:NSObservedObjectKey];
+ if(!boundObject || boundObject == [NSNull null]){
+ NSLog(@"ERROR: NSObservedObjectKey was nil for binding \"%@\" in %s", binding, __PRETTY_FUNCTION__);
+ return;
+ }
+
+ NSString* boundKeyPath = [bindingInfo objectForKey:NSObservedKeyPathKey];
+ if(!boundKeyPath || (id)boundKeyPath == [NSNull null]){
+ NSLog(@"ERROR: NSObservedKeyPathKey was nil for binding \"%@\" in %s", binding, __PRETTY_FUNCTION__);
+ return;
+ }
+
+ [boundObject setValue:value forKeyPath:boundKeyPath];
+}
+
@end