Add two-way binding support to OakEncodingPopUpButton

Previously binding to the view’s encoding property would not update the bound object when the view changed its value.
This commit is contained in:
Allan Odgaard
2013-10-03 22:27:25 +02:00
parent 2fe3b95585
commit a2131a6472

View File

@@ -215,6 +215,20 @@ namespace // PopulateMenu{Flat,Hierarchical}
if(_encoding && ![self.availableEncodings containsObject:_encoding])
[self updateAvailableEncodings];
[self updateMenu];
if(NSDictionary* info = [self infoForBinding:@"encoding"])
{
id controller = info[NSObservedObjectKey];
NSString* keyPath = info[NSObservedKeyPathKey];
if(controller && controller != [NSNull null] && keyPath && (id)keyPath != [NSNull null])
{
NSString* newValue = _encoding;
NSString* oldValue = [controller valueForKeyPath:keyPath];
if(!oldValue || ![oldValue isEqualToString:newValue])
[controller setValue:newValue forKeyPath:keyPath];
}
}
}
- (void)setAvailableEncodings:(NSArray*)newEncodings