- first take on NSDictionaryController

- bugfix in NSString+KVCAdditions
- NSOpenGLView initWithFrame:pixelFormat: calls super initWithFrame:
- NSBinder conditionallySetsEnabled checks for setEnabled: method, not setEditable:
- NSMultipleValueBinder catches exceptions during per-cell set
- NSNib tries to load nibs compiled from .xib file
This commit is contained in:
Johannes Fortmann 2008-12-03 11:51:16 +00:00
parent 8cadfd182e
commit 3f1a57e96d
8 changed files with 152 additions and 6 deletions

View File

@ -14,6 +14,10 @@
C81D0ACA0E8E92C2003BE469 /* NSToolbar-Private.h in Headers */ = {isa = PBXBuildFile; fileRef = C81D0AC90E8E92C2003BE469 /* NSToolbar-Private.h */; settings = {ATTRIBUTES = (Private, ); }; };
C84909370E8D1FB900BA6D3A /* NSUserDefaultsControllerProxy.h in Headers */ = {isa = PBXBuildFile; fileRef = C84909350E8D1FB900BA6D3A /* NSUserDefaultsControllerProxy.h */; settings = {ATTRIBUTES = (Private, ); }; };
C84909380E8D1FB900BA6D3A /* NSUserDefaultsControllerProxy.m in Sources */ = {isa = PBXBuildFile; fileRef = C84909360E8D1FB900BA6D3A /* NSUserDefaultsControllerProxy.m */; };
C85D91950EE6A806004EBAEA /* NSDictionaryController.h in Headers */ = {isa = PBXBuildFile; fileRef = C85D91930EE6A806004EBAEA /* NSDictionaryController.h */; };
C85D91960EE6A806004EBAEA /* NSDictionaryController.m in Sources */ = {isa = PBXBuildFile; fileRef = C85D91940EE6A806004EBAEA /* NSDictionaryController.m */; };
C85D91970EE6A806004EBAEA /* NSDictionaryController.h in Headers */ = {isa = PBXBuildFile; fileRef = C85D91930EE6A806004EBAEA /* NSDictionaryController.h */; settings = {ATTRIBUTES = (Public, ); }; };
C85D91980EE6A806004EBAEA /* NSDictionaryController.m in Sources */ = {isa = PBXBuildFile; fileRef = C85D91940EE6A806004EBAEA /* NSDictionaryController.m */; };
C8720C790EA782DB00F02725 /* CairoCacheImage.h in Headers */ = {isa = PBXBuildFile; fileRef = C8720C770EA782DB00F02725 /* CairoCacheImage.h */; settings = {ATTRIBUTES = (Private, ); }; };
C8720C7A0EA782DB00F02725 /* CairoCacheImage.m in Sources */ = {isa = PBXBuildFile; fileRef = C8720C780EA782DB00F02725 /* CairoCacheImage.m */; };
C8746B290EA379CE007A6BE2 /* NSPlatform_linux.m in Sources */ = {isa = PBXBuildFile; fileRef = C8746B280EA379CE007A6BE2 /* NSPlatform_linux.m */; };
@ -2020,6 +2024,8 @@
C81D0AC90E8E92C2003BE469 /* NSToolbar-Private.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSToolbar-Private.h"; sourceTree = "<group>"; };
C84909350E8D1FB900BA6D3A /* NSUserDefaultsControllerProxy.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = NSUserDefaultsControllerProxy.h; sourceTree = "<group>"; };
C84909360E8D1FB900BA6D3A /* NSUserDefaultsControllerProxy.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = NSUserDefaultsControllerProxy.m; sourceTree = "<group>"; };
C85D91930EE6A806004EBAEA /* NSDictionaryController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = NSDictionaryController.h; sourceTree = "<group>"; };
C85D91940EE6A806004EBAEA /* NSDictionaryController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = NSDictionaryController.m; sourceTree = "<group>"; };
C8720C770EA782DB00F02725 /* CairoCacheImage.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CairoCacheImage.h; sourceTree = "<group>"; };
C8720C780EA782DB00F02725 /* CairoCacheImage.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CairoCacheImage.m; sourceTree = "<group>"; };
C8746B280EA379CE007A6BE2 /* NSPlatform_linux.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = NSPlatform_linux.m; sourceTree = "<group>"; };
@ -3289,6 +3295,8 @@
FE2A10250B44A239006C03DE /* NSController */ = {
isa = PBXGroup;
children = (
C85D91930EE6A806004EBAEA /* NSDictionaryController.h */,
C85D91940EE6A806004EBAEA /* NSDictionaryController.m */,
C8C52C8D0E7ED1FF003F03B5 /* NSObservationProxy.h */,
C8C52C8E0E7ED1FF003F03B5 /* NSObservationProxy.m */,
FE8D94A90CE3A6C700AFB060 /* NSControllerSelectionProxy.h */,
@ -3757,6 +3765,7 @@
C81BEA0F0EA6038800478D50 /* CairoContext.h in Headers */,
C8720C790EA782DB00F02725 /* CairoCacheImage.h in Headers */,
FE25FF640EE58712009C91B1 /* KGFont.h in Headers */,
C85D91950EE6A806004EBAEA /* NSDictionaryController.h in Headers */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@ -4110,6 +4119,7 @@
C84909370E8D1FB900BA6D3A /* NSUserDefaultsControllerProxy.h in Headers */,
C81D0ACA0E8E92C2003BE469 /* NSToolbar-Private.h in Headers */,
FE25FF620EE58712009C91B1 /* KGFont.h in Headers */,
C85D91970EE6A806004EBAEA /* NSDictionaryController.h in Headers */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@ -4676,6 +4686,7 @@
C81BEA100EA6038800478D50 /* CairoContext.m in Sources */,
C8720C7A0EA782DB00F02725 /* CairoCacheImage.m in Sources */,
FE25FF650EE58712009C91B1 /* KGFont.m in Sources */,
C85D91960EE6A806004EBAEA /* NSDictionaryController.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@ -5033,6 +5044,7 @@
36570F9B0E818CD5008FE1BE /* NSGradient.m in Sources */,
C84909380E8D1FB900BA6D3A /* NSUserDefaultsControllerProxy.m in Sources */,
FE25FF630EE58712009C91B1 /* KGFont.m in Sources */,
C85D91980EE6A806004EBAEA /* NSDictionaryController.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};

View File

@ -0,0 +1,19 @@
/* Copyright (c) 2008 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 <AppKit/NSArrayController.h>
@class NSDictionary;
@interface NSDictionaryController : NSArrayController {
NSDictionary* _contentDictionary;
id _includedKeys;
id _excludedKeys;
}
@end

View File

@ -0,0 +1,102 @@
/* Copyright (c) 2008 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 <AppKit/NSDictionaryController.h>
#import <Foundation/NSString.h>
#import <Foundation/NSMutableArray.h>
#import <Foundation/NSMutableDictionary.h>
#import <Foundation/NSException.h>
#import <Foundation/NSKeyedUnarchiver.h>
@interface NSDictionaryControllerProxy : NSObject
{
id _key;
id _dictionary;
id _controller;
}
@property (copy) id key;
@property (retain) id value;
@property (retain) id dictionary;
@property (assign) id controller;
@end
@implementation NSDictionaryControllerProxy
@synthesize key=_key;
@synthesize dictionary=_dictionary;
@synthesize controller=_controller;
-(id)value {
return [_dictionary objectForKey:_key];
}
-(void)setValue:(id)newVal {
[_dictionary setObject:newVal forKey:_key];
}
-(id)description {
return [NSString stringWithFormat:@"%@ (%@ %p)", [super description], [self key], [self value]];
}
-(void)dealloc {
[_key release];
[_dictionary release];
[super dealloc];
}
@end
@implementation NSDictionaryController
-(id)initWithCoder:(NSCoder*)coder
{
if((self = [super initWithCoder:coder]))
{
_includedKeys=[[coder decodeObjectForKey:@"NSIncludedKeys"] retain];
_excludedKeys=[[coder decodeObjectForKey:@"NSExcludedKeys"] retain];
}
return self;
}
-(void)dealloc {
[_contentDictionary release];
[_includedKeys release];
[_excludedKeys release];
[super dealloc];
}
-(id)contentDictionary {
return _contentDictionary;
}
-(void)setContentDictionary:(id)dict {
if(dict!=_contentDictionary) {
[_contentDictionary release];
if(NSIsControllerMarker(dict)) {
dict=nil;
}
_contentDictionary=[dict retain];
id contentArray=[NSMutableArray array];
for(id key in [_contentDictionary allKeys]) {
if(![_excludedKeys containsObject:key]) {
NSDictionaryControllerProxy* proxy=[NSDictionaryControllerProxy new];
proxy.key=key;
proxy.dictionary=_contentDictionary;
[contentArray addObject:proxy];
[proxy release];
}
}
[self setContent:contentArray];
}
}
@end

View File

@ -23,13 +23,14 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
@implementation _NSBinder (BindingOptions)
-(BOOL)conditionallySetsEditable
{
return [[_options objectForKey:NSConditionallySetsEditableBindingOption] boolValue];
return [[_options objectForKey:NSConditionallySetsEditableBindingOption] boolValue] &&
[_source respondsToSelector:@selector(setEditable:)];
}
-(BOOL)conditionallySetsEnabled
{
// FIX: needs to read from options
if([_source respondsToSelector:@selector(setEditable:)])
if([_source respondsToSelector:@selector(setEnabled:)])
return YES;
return NO;
}

View File

@ -47,7 +47,12 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
-(void)applyToObject:(id)object inRow:(int)row keyPath:(id)path
{
[object setValue:[[_rowValues objectAtIndex:row] valueForKeyPath:_valueKeyPath] forKey:path];
@try {
[object setValue:[[_rowValues objectAtIndex:row] valueForKeyPath:_valueKeyPath] forKey:path];
}
@catch(id e) {
// NSLog(@"exception %@ while setting value for key path %@ for row %i", e, _valueKeyPath, row);
}
}
-(void)applyToObject:(id)object inRow:(int)row
@ -141,7 +146,7 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
-(void)startObservingChanges
{
NS_DURING
@try {
[_destination addObserver:self forKeyPath:_arrayKeyPath options:0 context:_destination];
if(![_valueKeyPath hasPrefix:@"@"])
[_rowValues addObserver:self
@ -149,8 +154,9 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
forKeyPath:_valueKeyPath
options:0
context:nil];
NS_HANDLER
NS_ENDHANDLER
}
@catch(id e) {
}
}
-(void)stopObservingChanges

View File

@ -25,6 +25,7 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
}
-initWithFrame:(NSRect)frame pixelFormat:(NSOpenGLPixelFormat *)pixelFormat {
[super initWithFrame:frame];
_pixelFormat=[pixelFormat retain];
_context=nil;
return self;

View File

@ -29,6 +29,9 @@ NSString *NSNibTopLevelObjects=@"NSNibTopLevelObjects";
if([[NSFileManager defaultManager] fileExistsAtPath:path isDirectory:&isDirectory] && isDirectory)
keyedobjects=[[path stringByAppendingPathComponent:@"keyedobjects"] stringByAppendingPathExtension:@"nib"];
if(!keyedobjects && !isDirectory)
keyedobjects=path; // assume new-style compiled xib
if((_data=[[NSData alloc] initWithContentsOfFile:keyedobjects])==nil){
NSLog(@"%s: unable to init nib from file '%@'", __PRETTY_FUNCTION__, keyedobjects);
[self release];

View File

@ -22,6 +22,8 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
if([self hasPrefix:start] && [self hasSuffix:end])
{
NSString* keyName=[self substringWithRange:NSMakeRange([start length], [self length]-[end length]-[start length])];
if(![keyName length])
return NO;
*ret = [NSString stringWithFormat:@"%@%@", [[keyName substringToIndex:1] lowercaseString], [keyName substringFromIndex:1]];
return YES;
}