Improvement to OASteppableTextField
I am using OASteppableTextField and would like to submit an improvement to it - not sure if there is some recommended way to do this, so will post the code here.
The issue: OASteppableTextField does not transform the values using a value transformer that may be attached to the binding. Solution: look for either a transformer object or transformer name in the binding options and transform the value using it, if there is one. There are no API changes or side effects from this improvement. I have tested this fix and it works nicely. Would appreciate a note in the commit notes if you include this in a future version of the framework, so I don't have to remember to edit it each time. Here is the revised method with comments at the start and end of the change: - (BOOL)_stepWithFormatterSelector:(SEL)formatterSelector; { NSFormatter *formatter = [self formatter]; if (![formatter respondsToSelector:formatterSelector]) return NO; id objectValue = [formatter performSelector:formatterSelector withObject:[self objectValue]]; if (![self validateSteppedObjectValue:objectValue]) return NO; [self setObjectValue:objectValue]; [NSApp sendAction:[self action] to:[self target] from:self]; NSDictionary *bindingInfo = [self infoForBinding:@"value"]; /****** START IMPROVEMENT *********/ if (bindingInfo) { NSDictionary *bindingOptions = [bindingInfo objectForKey:NSOptionsKey]; if ([bindingOptions objectForKey:NSValueTransformerBindingOption]) { NSValueTransformer *transformer = [bindingOptions objectForKey:NSValueTransformerBindingOption]; objectValue = [transformer reverseTransformedValue:objectValue]; } else if ([bindingOptions objectForKey:NSValueTransformerNameBindingOption]) { NSValueTransformer *transformer = [NSValueTransformer valueTransformerForName:[bindingOptions objectForKey:NSValueTransformerNameBindingOption]]; objectValue = [transformer reverseTransformedValue:objectValue]; } [[bindingInfo objectForKey:NSObservedObjectKey] setValue:objectValue forKeyPath:[bindingInfo objectForKey:NSObservedKeyPathKey]]; } /********* END IMPROVEMENT **********/ return YES; } |
Thanks!
I've added this in a slightly more general fashion (a new utility function OAPushValueThroughBinding) and pushed it to github [URL="http://github.com/omnigroup/OmniGroup/tree/307d5ca681d8b6705e176f14a485aa83050ac2d3"]http://github.com/omnigroup/OmniGroup/tree/307d5ca681d8b6705e176f14a485aa83050ac2d3[/URL] |
All times are GMT -8. The time now is 12:28 AM. |
Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2024, vBulletin Solutions, Inc.