mirror of
https://github.com/darlinghq/darling-cocotron.git
synced 2025-02-20 03:31:51 +00:00
Andy Balholm's Continuously Updates Value bindng option
This commit is contained in:
parent
cec867e7b4
commit
a4aac1660a
@ -9,6 +9,22 @@
|
||||
/* Begin PBXBuildFile section */
|
||||
36570F9B0E818CD5008FE1BE /* NSGradient.m in Sources */ = {isa = PBXBuildFile; fileRef = 36570F990E818CD5008FE1BE /* NSGradient.m */; };
|
||||
365710650E81A10E008FE1BE /* NSGradient.h in Headers */ = {isa = PBXBuildFile; fileRef = 36570F980E818CD5008FE1BE /* NSGradient.h */; settings = {ATTRIBUTES = (Public, ); }; };
|
||||
A1CC7019100534AB00DB9974 /* NSCachingBinder.h in Headers */ = {isa = PBXBuildFile; fileRef = A1CC7017100534AB00DB9974 /* NSCachingBinder.h */; };
|
||||
A1CC701A100534AB00DB9974 /* NSCachingBinder.m in Sources */ = {isa = PBXBuildFile; fileRef = A1CC7018100534AB00DB9974 /* NSCachingBinder.m */; };
|
||||
A1CC701B100534AB00DB9974 /* NSCachingBinder.h in Headers */ = {isa = PBXBuildFile; fileRef = A1CC7017100534AB00DB9974 /* NSCachingBinder.h */; };
|
||||
A1CC701C100534AB00DB9974 /* NSCachingBinder.m in Sources */ = {isa = PBXBuildFile; fileRef = A1CC7018100534AB00DB9974 /* NSCachingBinder.m */; };
|
||||
A1CC701D100534AB00DB9974 /* NSCachingBinder.h in Headers */ = {isa = PBXBuildFile; fileRef = A1CC7017100534AB00DB9974 /* NSCachingBinder.h */; };
|
||||
A1CC701E100534AB00DB9974 /* NSCachingBinder.m in Sources */ = {isa = PBXBuildFile; fileRef = A1CC7018100534AB00DB9974 /* NSCachingBinder.m */; };
|
||||
A1CC701F100534AB00DB9974 /* NSCachingBinder.h in Headers */ = {isa = PBXBuildFile; fileRef = A1CC7017100534AB00DB9974 /* NSCachingBinder.h */; };
|
||||
A1CC7020100534AB00DB9974 /* NSCachingBinder.m in Sources */ = {isa = PBXBuildFile; fileRef = A1CC7018100534AB00DB9974 /* NSCachingBinder.m */; };
|
||||
A1CC70421005371100DB9974 /* NSTextBinder.h in Headers */ = {isa = PBXBuildFile; fileRef = A1CC70401005371100DB9974 /* NSTextBinder.h */; };
|
||||
A1CC70431005371100DB9974 /* NSTextBinder.m in Sources */ = {isa = PBXBuildFile; fileRef = A1CC70411005371100DB9974 /* NSTextBinder.m */; };
|
||||
A1CC70441005371100DB9974 /* NSTextBinder.h in Headers */ = {isa = PBXBuildFile; fileRef = A1CC70401005371100DB9974 /* NSTextBinder.h */; };
|
||||
A1CC70451005371100DB9974 /* NSTextBinder.m in Sources */ = {isa = PBXBuildFile; fileRef = A1CC70411005371100DB9974 /* NSTextBinder.m */; };
|
||||
A1CC70461005371100DB9974 /* NSTextBinder.h in Headers */ = {isa = PBXBuildFile; fileRef = A1CC70401005371100DB9974 /* NSTextBinder.h */; };
|
||||
A1CC70471005371100DB9974 /* NSTextBinder.m in Sources */ = {isa = PBXBuildFile; fileRef = A1CC70411005371100DB9974 /* NSTextBinder.m */; };
|
||||
A1CC70481005371100DB9974 /* NSTextBinder.h in Headers */ = {isa = PBXBuildFile; fileRef = A1CC70401005371100DB9974 /* NSTextBinder.h */; };
|
||||
A1CC70491005371100DB9974 /* NSTextBinder.m in Sources */ = {isa = PBXBuildFile; fileRef = A1CC70411005371100DB9974 /* NSTextBinder.m */; };
|
||||
C81BEA0F0EA6038800478D50 /* CairoContext.h in Headers */ = {isa = PBXBuildFile; fileRef = C81BEA0D0EA6038800478D50 /* CairoContext.h */; settings = {ATTRIBUTES = (Private, ); }; };
|
||||
C81BEA100EA6038800478D50 /* CairoContext.m in Sources */ = {isa = PBXBuildFile; fileRef = C81BEA0E0EA6038800478D50 /* CairoContext.m */; };
|
||||
C8283E4B0F0AEE3B009E89C4 /* X11InputSource.h in Headers */ = {isa = PBXBuildFile; fileRef = C8283E490F0AEE3B009E89C4 /* X11InputSource.h */; settings = {ATTRIBUTES = (Private, ); }; };
|
||||
@ -3330,6 +3346,10 @@
|
||||
6EC4ADE50A37294300E8D6CA /* NSButtonImageSource.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = NSButtonImageSource.m; sourceTree = "<group>"; };
|
||||
6ECABDF70A3FA2B700AD7F7B /* NSCustomView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = NSCustomView.h; sourceTree = "<group>"; };
|
||||
6ECABDF80A3FA2B700AD7F7B /* NSCustomView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = NSCustomView.m; sourceTree = "<group>"; };
|
||||
A1CC7017100534AB00DB9974 /* NSCachingBinder.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = NSCachingBinder.h; sourceTree = "<group>"; };
|
||||
A1CC7018100534AB00DB9974 /* NSCachingBinder.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = NSCachingBinder.m; sourceTree = "<group>"; };
|
||||
A1CC70401005371100DB9974 /* NSTextBinder.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = NSTextBinder.h; sourceTree = "<group>"; };
|
||||
A1CC70411005371100DB9974 /* NSTextBinder.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = NSTextBinder.m; sourceTree = "<group>"; };
|
||||
C81BEA0D0EA6038800478D50 /* CairoContext.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CairoContext.h; sourceTree = "<group>"; };
|
||||
C81BEA0E0EA6038800478D50 /* CairoContext.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CairoContext.m; sourceTree = "<group>"; };
|
||||
C8283E490F0AEE3B009E89C4 /* X11InputSource.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = X11InputSource.h; sourceTree = "<group>"; };
|
||||
@ -4743,6 +4763,10 @@
|
||||
FE8BAF1A0BC9EC0B0007FACA /* NSKeyValueBinding */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
A1CC70401005371100DB9974 /* NSTextBinder.h */,
|
||||
A1CC70411005371100DB9974 /* NSTextBinder.m */,
|
||||
A1CC7017100534AB00DB9974 /* NSCachingBinder.h */,
|
||||
A1CC7018100534AB00DB9974 /* NSCachingBinder.m */,
|
||||
FE8D951E0CE4057300AFB060 /* NSMultipleValueBinder.h */,
|
||||
FE8D951F0CE4057300AFB060 /* NSMultipleValueBinder.m */,
|
||||
C8B239A20BF8EEB500CA33AF /* defaultBindingOptions.plist */,
|
||||
@ -5164,6 +5188,8 @@
|
||||
FE9DB3D60FD6BD5A00A1CE17 /* NSRangeEntries.h in Headers */,
|
||||
FEAED7A00FD6C96E0043F915 /* KGDataConsumer.h in Headers */,
|
||||
FE2C7F560FDC4C8E00D5DFB5 /* NSStringKVCFunctions.h in Headers */,
|
||||
A1CC701D100534AB00DB9974 /* NSCachingBinder.h in Headers */,
|
||||
A1CC70441005371100DB9974 /* NSTextBinder.h in Headers */,
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
};
|
||||
@ -5525,6 +5551,8 @@
|
||||
FE9DB3D70FD6BD5B00A1CE17 /* NSRangeEntries.h in Headers */,
|
||||
FEAED79E0FD6C96E0043F915 /* KGDataConsumer.h in Headers */,
|
||||
FE2C7F550FDC4C8E00D5DFB5 /* NSStringKVCFunctions.h in Headers */,
|
||||
A1CC701F100534AB00DB9974 /* NSCachingBinder.h in Headers */,
|
||||
A1CC70421005371100DB9974 /* NSTextBinder.h in Headers */,
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
};
|
||||
@ -5881,6 +5909,8 @@
|
||||
FEAED7A20FD6C96E0043F915 /* KGDataConsumer.h in Headers */,
|
||||
FE2C7F570FDC4C8E00D5DFB5 /* NSStringKVCFunctions.h in Headers */,
|
||||
FEA661230FF5C6F200E2C03B /* KGFont_gdi.h in Headers */,
|
||||
A1CC7019100534AB00DB9974 /* NSCachingBinder.h in Headers */,
|
||||
A1CC70481005371100DB9974 /* NSTextBinder.h in Headers */,
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
};
|
||||
@ -6165,6 +6195,8 @@
|
||||
FEA317C50FD5893300F480D4 /* NSRaise.h in Headers */,
|
||||
FEA3182B0FD5961100F480D4 /* NSRangeEntries.h in Headers */,
|
||||
FE2C7F580FDC4C8E00D5DFB5 /* NSStringKVCFunctions.h in Headers */,
|
||||
A1CC701B100534AB00DB9974 /* NSCachingBinder.h in Headers */,
|
||||
A1CC70461005371100DB9974 /* NSTextBinder.h in Headers */,
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
};
|
||||
@ -6922,6 +6954,8 @@
|
||||
FEAED7A10FD6C96E0043F915 /* KGDataConsumer.m in Sources */,
|
||||
FEAED7A60FD6C9820043F915 /* CGPDFContext.m in Sources */,
|
||||
FEB07FA10FF9B37C00C27509 /* KGFont+PDF.m in Sources */,
|
||||
A1CC701E100534AB00DB9974 /* NSCachingBinder.m in Sources */,
|
||||
A1CC70451005371100DB9974 /* NSTextBinder.m in Sources */,
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
};
|
||||
@ -7251,6 +7285,8 @@
|
||||
FEAED79F0FD6C96E0043F915 /* KGDataConsumer.m in Sources */,
|
||||
FEAED7A50FD6C9820043F915 /* CGPDFContext.m in Sources */,
|
||||
FEB07FA20FF9B37C00C27509 /* KGFont+PDF.m in Sources */,
|
||||
A1CC7020100534AB00DB9974 /* NSCachingBinder.m in Sources */,
|
||||
A1CC70431005371100DB9974 /* NSTextBinder.m in Sources */,
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
};
|
||||
@ -7614,6 +7650,8 @@
|
||||
FEAED7A70FD6C9820043F915 /* CGPDFContext.m in Sources */,
|
||||
FEA661240FF5C6F300E2C03B /* KGFont_gdi.m in Sources */,
|
||||
FEB07FA00FF9B37C00C27509 /* KGFont+PDF.m in Sources */,
|
||||
A1CC701A100534AB00DB9974 /* NSCachingBinder.m in Sources */,
|
||||
A1CC70491005371100DB9974 /* NSTextBinder.m in Sources */,
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
};
|
||||
@ -7848,6 +7886,8 @@
|
||||
FEA3161A0FD5667D00F480D4 /* NSControllerMarker.m in Sources */,
|
||||
FEA3182C0FD5961100F480D4 /* NSRangeEntries.m in Sources */,
|
||||
FEB07FA30FF9B37C00C27509 /* KGFont+PDF.m in Sources */,
|
||||
A1CC701C100534AB00DB9974 /* NSCachingBinder.m in Sources */,
|
||||
A1CC70471005371100DB9974 /* NSTextBinder.m in Sources */,
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
};
|
||||
|
@ -56,6 +56,7 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
|
||||
-(BOOL)allowsEditingMultipleValues;
|
||||
-(BOOL)createsSortDescriptor;
|
||||
-(BOOL)raisesForNotApplicableKeys;
|
||||
-(BOOL)continuouslyUpdatesValue;
|
||||
-(id)multipleValuesPlaceholder;
|
||||
-(id)noSelectionPlaceholder;
|
||||
-(id)nullPlaceholder;
|
||||
|
@ -31,10 +31,8 @@ static void* NSBinderChangeContext;
|
||||
|
||||
-(BOOL)conditionallySetsEnabled
|
||||
{
|
||||
// FIX: needs to read from options
|
||||
if([_source respondsToSelector:@selector(setEnabled:)])
|
||||
return YES;
|
||||
return NO;
|
||||
return [[_options objectForKey:NSConditionallySetsEnabledBindingOption] boolValue] &&
|
||||
[_source respondsToSelector:@selector(setEnabled:)];
|
||||
}
|
||||
|
||||
-(BOOL)allowsEditingMultipleValues
|
||||
@ -53,6 +51,11 @@ static void* NSBinderChangeContext;
|
||||
return [[_options objectForKey:NSRaisesForNotApplicableKeysBindingOption] boolValue];
|
||||
}
|
||||
|
||||
-(BOOL)continuouslyUpdatesValue
|
||||
{
|
||||
return [[_options objectForKey:NSContinuouslyUpdatesValueBindingOption] boolValue];
|
||||
}
|
||||
|
||||
-(id)multipleValuesPlaceholder
|
||||
{
|
||||
id ret=[_options objectForKey:NSMultipleValuesPlaceholderBindingOption];
|
||||
|
37
AppKit/NSKeyValueBinding/NSCachingBinder.h
Normal file
37
AppKit/NSKeyValueBinding/NSCachingBinder.h
Normal file
@ -0,0 +1,37 @@
|
||||
/* Copyright (c) 2009 Andy Balholm
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
|
||||
// A subclass of _NSBinder that uses KVO to observe the destination but not the source.
|
||||
// It caches values so that changes are propagated only if the value has actually changed.
|
||||
|
||||
#import "NSBinder.h"
|
||||
|
||||
|
||||
@interface _NSCachingBinder : _NSBinder
|
||||
{
|
||||
id _cachedValue;
|
||||
BOOL _bound;
|
||||
}
|
||||
|
||||
- (id)cachedValue;
|
||||
- (void)setCachedValue:(id)value;
|
||||
|
||||
// Set the source (view) object's value to newValue
|
||||
- (void)showValue:(id)newValue;
|
||||
|
||||
// Set the destination (model) object's value to newValue
|
||||
- (void)applyValue:(id)newValue;
|
||||
- (void)applyDisplayedValue;
|
||||
|
||||
- (id)destinationValue;
|
||||
|
||||
- (void)syncUp;
|
||||
- (void)bind;
|
||||
- (void)unbind;
|
||||
|
||||
@end
|
155
AppKit/NSKeyValueBinding/NSCachingBinder.m
Normal file
155
AppKit/NSKeyValueBinding/NSCachingBinder.m
Normal file
@ -0,0 +1,155 @@
|
||||
/* Copyright (c) 2009 Andy Balholm
|
||||
Portions copyright (c) 2007 Johannes Fortmann
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
|
||||
#import "NSCachingBinder.h"
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
#import <AppKit/NSController.h>
|
||||
#import <AppKit/NSControl.h>
|
||||
#import "NSObject+BindingSupport.h"
|
||||
|
||||
static void * NSCachingBinderChangeContext = (void *)@"NSCachingBinderChangeContext";
|
||||
|
||||
@implementation _NSCachingBinder
|
||||
|
||||
- (void)startObservingChanges
|
||||
{
|
||||
[_destination addObserver:self
|
||||
forKeyPath:_keyPath
|
||||
options:0
|
||||
context:NSCachingBinderChangeContext];
|
||||
}
|
||||
|
||||
- (void)stopObservingChanges
|
||||
{
|
||||
if (_bound)
|
||||
[_destination removeObserver:self forKeyPath:_keyPath];
|
||||
}
|
||||
|
||||
- (void)dealloc
|
||||
{
|
||||
[_cachedValue release];
|
||||
|
||||
[super dealloc];
|
||||
}
|
||||
|
||||
- (id)cachedValue
|
||||
{
|
||||
return [[_cachedValue retain] autorelease];
|
||||
}
|
||||
|
||||
- (void)setCachedValue:(id)value
|
||||
{
|
||||
if (_cachedValue != value)
|
||||
{
|
||||
[_cachedValue release];
|
||||
_cachedValue = [value retain];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)showValue:(id)newValue
|
||||
{
|
||||
if (![_cachedValue isEqual:newValue])
|
||||
{
|
||||
[self setCachedValue:newValue];
|
||||
|
||||
BOOL editable=YES;
|
||||
BOOL isPlaceholder=NO;
|
||||
if(newValue==NSMultipleValuesMarker)
|
||||
{
|
||||
newValue=[self multipleValuesPlaceholder];
|
||||
if(![self allowsEditingMultipleValues])
|
||||
editable=NO;
|
||||
isPlaceholder=YES;
|
||||
}
|
||||
else if(newValue==NSNoSelectionMarker)
|
||||
{
|
||||
newValue=[self noSelectionPlaceholder];
|
||||
editable=NO;
|
||||
isPlaceholder=YES;
|
||||
}
|
||||
else if(!newValue || newValue==[NSNull null])
|
||||
{
|
||||
newValue=[self nullPlaceholder];
|
||||
isPlaceholder=YES;
|
||||
}
|
||||
|
||||
if([self conditionallySetsEditable])
|
||||
[_source setEditable:editable];
|
||||
if([self conditionallySetsEnabled])
|
||||
[_source setEnabled:editable];
|
||||
|
||||
[_source setValue:newValue
|
||||
forKeyPath:_bindingPath];
|
||||
|
||||
if(isPlaceholder && [_source respondsToSelector:@selector(_setCurrentValueIsPlaceholder:)])
|
||||
[_source _setCurrentValueIsPlaceholder:YES];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)applyValue:(id)newValue
|
||||
{
|
||||
if (![_cachedValue isEqual:newValue])
|
||||
{
|
||||
[self setCachedValue:newValue];
|
||||
[_destination setValue:newValue forKeyPath:_keyPath];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)applyDisplayedValue
|
||||
{
|
||||
[self applyValue:[_source valueForKeyPath:_bindingPath]];
|
||||
}
|
||||
|
||||
- (id)destinationValue
|
||||
{
|
||||
@try
|
||||
{
|
||||
return [_destination valueForKeyPath:_keyPath];
|
||||
}
|
||||
@catch(id ex)
|
||||
{
|
||||
if ([self raisesForNotApplicableKeys])
|
||||
[ex raise];
|
||||
else
|
||||
return NSNotApplicableMarker;
|
||||
}
|
||||
return nil; // To avoid compiler warnings
|
||||
}
|
||||
|
||||
- (void)observeValueForKeyPath:(NSString *)kp
|
||||
ofObject:(id)object
|
||||
change:(NSDictionary *)change
|
||||
context:(void *)context
|
||||
{
|
||||
if (context == NSCachingBinderChangeContext)
|
||||
{
|
||||
[self showValue:[self destinationValue]];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)syncUp
|
||||
{
|
||||
[self showValue:[self destinationValue]];
|
||||
}
|
||||
|
||||
- (void)bind
|
||||
{
|
||||
[self syncUp];
|
||||
[self startObservingChanges];
|
||||
_bound = YES;
|
||||
}
|
||||
|
||||
- (void)unbind
|
||||
{
|
||||
[self stopObservingChanges];
|
||||
_bound = NO;
|
||||
}
|
||||
|
||||
@end
|
@ -72,4 +72,5 @@ APPKIT_EXPORT NSString *NSValueTransformerNameBindingOption;
|
||||
APPKIT_EXPORT NSString *NSValueTransformerBindingOption;
|
||||
APPKIT_EXPORT NSString *NSConditionallySetsEnabledBindingOption;
|
||||
APPKIT_EXPORT NSString *NSConditionallySetsEditableBindingOption;
|
||||
APPKIT_EXPORT NSString *NSContinuouslyUpdatesValueBindingOption;
|
||||
|
||||
|
@ -34,6 +34,7 @@ NSString *NSValueTransformerNameBindingOption=@"NSValueTransformerName";
|
||||
NSString *NSValueTransformerBindingOption=@"NSValueTransformerBinding";
|
||||
NSString *NSConditionallySetsEnabledBindingOption=@"NSConditionallySetsEnabled";
|
||||
NSString *NSConditionallySetsEditableBindingOption=@"NSConditionallySetsEditable";
|
||||
NSString *NSContinuouslyUpdatesValueBindingOption=@"NSContinuouslyUpdatesValue";
|
||||
|
||||
@implementation NSObject (BindingSupport)
|
||||
|
||||
|
24
AppKit/NSKeyValueBinding/NSTextBinder.h
Normal file
24
AppKit/NSKeyValueBinding/NSTextBinder.h
Normal file
@ -0,0 +1,24 @@
|
||||
/* Copyright (c) 2009 Andy Balholm
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
|
||||
// A subclass of _NSCachingBinder that registers for text editing notifications from NSText and NSControl objects.
|
||||
|
||||
#import "NSCachingBinder.h"
|
||||
|
||||
@class NSNotification;
|
||||
|
||||
@interface _NSTextBinder : _NSCachingBinder
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
- (void)textDidChange:(NSNotification *)note;
|
||||
- (void)textDidEndEditing:(NSNotification *)note;
|
||||
- (void)windowWillClose:(NSNotification *)note;
|
||||
|
||||
@end
|
82
AppKit/NSKeyValueBinding/NSTextBinder.m
Normal file
82
AppKit/NSKeyValueBinding/NSTextBinder.m
Normal file
@ -0,0 +1,82 @@
|
||||
/* Copyright (c) 2009 Andy Balholm
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
|
||||
#import "NSTextBinder.h"
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
#import <AppKit/NSControl.h>
|
||||
#import <AppKit/NSText.h>
|
||||
#import <AppKit/NSView.h>
|
||||
#import <AppKit/NSWindow.h>
|
||||
|
||||
@implementation _NSTextBinder
|
||||
|
||||
- (void)startObservingChanges
|
||||
{
|
||||
[super startObservingChanges];
|
||||
|
||||
NSNotificationCenter * nc = [NSNotificationCenter defaultCenter];
|
||||
if ([_source isKindOfClass:[NSText class]])
|
||||
{
|
||||
[nc addObserver:self
|
||||
selector:@selector(textDidEndEditing:)
|
||||
name:NSTextDidEndEditingNotification
|
||||
object:_source];
|
||||
if ([self continuouslyUpdatesValue])
|
||||
[nc addObserver:self
|
||||
selector:@selector(textDidChange:)
|
||||
name:NSTextDidChangeNotification
|
||||
object:_source];
|
||||
}
|
||||
else if ([_source isKindOfClass:[NSControl class]])
|
||||
{
|
||||
[nc addObserver:self
|
||||
selector:@selector(textDidEndEditing:)
|
||||
name:NSControlTextDidEndEditingNotification
|
||||
object:_source];
|
||||
if ([self continuouslyUpdatesValue])
|
||||
[nc addObserver:self
|
||||
selector:@selector(textDidChange:)
|
||||
name:NSControlTextDidChangeNotification
|
||||
object:_source];
|
||||
}
|
||||
|
||||
if ([_source isKindOfClass:[NSView class]])
|
||||
{
|
||||
NSWindow * window = [_source window];
|
||||
if (window)
|
||||
[nc addObserver:self
|
||||
selector:@selector(windowWillClose:)
|
||||
name:NSWindowWillCloseNotification
|
||||
object:window];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)stopObservingChanges
|
||||
{
|
||||
[super stopObservingChanges];
|
||||
|
||||
[[NSNotificationCenter defaultCenter] removeObserver:self];
|
||||
}
|
||||
|
||||
- (void)textDidChange:(NSNotification *)note
|
||||
{
|
||||
[self applyDisplayedValue];
|
||||
}
|
||||
|
||||
- (void)textDidEndEditing:(NSNotification *)note
|
||||
{
|
||||
[self applyDisplayedValue];
|
||||
}
|
||||
|
||||
- (void)windowWillClose:(NSNotification *)note
|
||||
{
|
||||
[self applyDisplayedValue];
|
||||
}
|
||||
|
||||
@end
|
@ -1,5 +1,5 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||
<plist version="1.0">
|
||||
<dict>
|
||||
<key>NSActionCell</key>
|
||||
@ -21,6 +21,8 @@
|
||||
</dict>
|
||||
<key>NSTextField</key>
|
||||
<dict>
|
||||
<key>NSNullPlaceholder</key>
|
||||
<string></string>
|
||||
<key>NSMultipleValuesPlaceholder</key>
|
||||
<string>Multiple values</string>
|
||||
<key>NSNoSelectionPlaceholder</key>
|
||||
@ -28,6 +30,8 @@
|
||||
</dict>
|
||||
<key>NSTextFieldCell</key>
|
||||
<dict>
|
||||
<key>NSNullPlaceholder</key>
|
||||
<string></string>
|
||||
<key>NSMultipleValuesPlaceholder</key>
|
||||
<string>Multiple values</string>
|
||||
<key>NSNoSelectionPlaceholder</key>
|
||||
|
@ -12,6 +12,8 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
|
||||
#import <AppKit/NSCursor.h>
|
||||
#import <AppKit/NSPasteboard.h>
|
||||
#import <AppKit/NSDragging.h>
|
||||
#import "NSKeyValueBinding/NSTextBinder.h"
|
||||
#import "NSKeyValueBinding/NSObject+BindingSupport.h"
|
||||
|
||||
@implementation NSTextField
|
||||
|
||||
@ -19,6 +21,14 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
|
||||
return [NSTextFieldCell class];
|
||||
}
|
||||
|
||||
+(Class)_binderClassForBinding:(id)binding
|
||||
{
|
||||
if ([binding isEqual:@"value"])
|
||||
return [_NSTextBinder class];
|
||||
else
|
||||
return [super _binderClassForBinding:binding];
|
||||
}
|
||||
|
||||
-initWithCoder:(NSCoder *)coder {
|
||||
[super initWithCoder:coder];
|
||||
[self registerForDraggedTypes:[NSArray arrayWithObject:NSStringPboardType]];
|
||||
|
Loading…
x
Reference in New Issue
Block a user