mirror of
https://github.com/gnustep/libs-gui.git
synced 2025-04-23 15:11:37 +00:00
Add more implementation to NSObjectController.
Patch by Andy Balholm <andy@balholm.com>. git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@28374 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
ca5161d0a1
commit
48a1be38fa
4 changed files with 98 additions and 9 deletions
|
@ -1,3 +1,11 @@
|
|||
2009-06-29 Fred Kiefer <FredKiefer@gmx.de>
|
||||
|
||||
* Headers/AppKit/NSKeyValueBinding.h,
|
||||
* Source/externs.m: Add NSContentObjectBinding.
|
||||
* Source/NSObjectController.m: Add more implementation to this
|
||||
class.
|
||||
Patch by Andy Balholm <andy@balholm.com>.
|
||||
|
||||
2009-06-28 Fred Kiefer <FredKiefer@gmx.de>
|
||||
|
||||
* Headers/AppKit/AppKit.h : Addd NSFontDescriptor.h.
|
||||
|
|
|
@ -103,6 +103,7 @@ APPKIT_EXPORT id NSNotApplicableMarker;
|
|||
|
||||
// Binding name constants
|
||||
APPKIT_EXPORT NSString *NSAlignmentBinding;
|
||||
APPKIT_EXPORT NSString *NSContentObjectBinding;
|
||||
APPKIT_EXPORT NSString *NSEditableBinding;
|
||||
APPKIT_EXPORT NSString *NSEnabledBinding;
|
||||
APPKIT_EXPORT NSString *NSFontBinding;
|
||||
|
|
|
@ -32,8 +32,13 @@
|
|||
#include <Foundation/NSString.h>
|
||||
#include <Foundation/NSArchiver.h>
|
||||
#include <Foundation/NSKeyedArchiver.h>
|
||||
#include <Foundation/NSKeyValueObserving.h>
|
||||
#include <Foundation/NSKeyValueCoding.h>
|
||||
#include <AppKit/NSObjectController.h>
|
||||
|
||||
#include "AppKit/NSKeyValueBinding.h"
|
||||
#include "GSBindingHelpers.h"
|
||||
|
||||
@interface _NSManagedProxy : NSObject
|
||||
{
|
||||
NSString *_entity_name_key;
|
||||
|
@ -91,6 +96,20 @@
|
|||
|
||||
@implementation NSObjectController
|
||||
|
||||
+ (void) initialize
|
||||
{
|
||||
if (self == [NSObjectController class])
|
||||
{
|
||||
[self exposeBinding: NSContentObjectBinding];
|
||||
[self setKeys: [NSArray arrayWithObject: @"editable"]
|
||||
triggerChangeNotificationsForDependentKey: @"canAdd"];
|
||||
[self setKeys: [NSArray arrayWithObject: @"editable"]
|
||||
triggerChangeNotificationsForDependentKey: @"canRemove"];
|
||||
[self setKeys: [NSArray arrayWithObject: @"content"]
|
||||
triggerChangeNotificationsForDependentKey: @"selectedObjects"];
|
||||
}
|
||||
}
|
||||
|
||||
- (id) initWithContent: (id)content
|
||||
{
|
||||
if ((self = [super init]) != nil)
|
||||
|
@ -111,9 +130,11 @@
|
|||
|
||||
- (void) dealloc
|
||||
{
|
||||
[GSKeyValueBinding unbindAllForObject: self];
|
||||
RELEASE(_content);
|
||||
RELEASE(_entity_name_key);
|
||||
RELEASE(_fetch_predicate);
|
||||
RELEASE(_selection);
|
||||
[super dealloc];
|
||||
}
|
||||
|
||||
|
@ -174,7 +195,43 @@
|
|||
|
||||
- (void) setContent: (id)content
|
||||
{
|
||||
NSMutableArray *selection;
|
||||
|
||||
ASSIGN(_content, content);
|
||||
if (content)
|
||||
{
|
||||
selection = [[NSMutableArray alloc] initWithObjects: &content count: 1];
|
||||
}
|
||||
else
|
||||
{
|
||||
selection = [[NSMutableArray alloc] init];
|
||||
}
|
||||
ASSIGN(_selection, selection);
|
||||
RELEASE(selection);
|
||||
}
|
||||
|
||||
- (void)bind: (NSString *)binding
|
||||
toObject: (id)anObject
|
||||
withKeyPath: (NSString *)keyPath
|
||||
options: (NSDictionary *)options
|
||||
{
|
||||
if ([binding isEqual:NSContentObjectBinding])
|
||||
{
|
||||
[self unbind: binding];
|
||||
[[GSKeyValueBinding alloc] initWithBinding: @"content"
|
||||
withName: binding
|
||||
toObject: anObject
|
||||
withKeyPath: keyPath
|
||||
options: options
|
||||
fromObject: self];
|
||||
}
|
||||
else
|
||||
{
|
||||
[super bind: binding
|
||||
toObject: anObject
|
||||
withKeyPath: keyPath
|
||||
options: options];
|
||||
}
|
||||
}
|
||||
|
||||
- (Class) objectClass
|
||||
|
@ -212,40 +269,62 @@
|
|||
|
||||
- (void) add: (id)sender
|
||||
{
|
||||
id new = [self newObject];
|
||||
if ([self canAdd])
|
||||
{
|
||||
id new = [self newObject];
|
||||
|
||||
[self addObject: new];
|
||||
RELEASE(new);
|
||||
[self addObject: new];
|
||||
RELEASE(new);
|
||||
}
|
||||
}
|
||||
|
||||
- (void) addObject: (id)obj
|
||||
{
|
||||
NSDictionary * bindingInfo = [self infoForBinding: NSContentObjectBinding];
|
||||
|
||||
[self setContent: obj];
|
||||
// TODO
|
||||
if (bindingInfo)
|
||||
{
|
||||
// Change the relationship of the object that our content is bound to.
|
||||
id masterObject = [bindingInfo objectForKey: NSObservedObjectKey];
|
||||
NSString * keyPath = [bindingInfo objectForKey: NSObservedKeyPathKey];
|
||||
[masterObject setValue: obj forKeyPath: keyPath];
|
||||
}
|
||||
}
|
||||
|
||||
- (void) remove: (id)sender
|
||||
{
|
||||
[self removeObject: [self content]];
|
||||
if ([self canRemove])
|
||||
{
|
||||
[self removeObject: [self content]];
|
||||
}
|
||||
}
|
||||
|
||||
- (void) removeObject: (id)obj
|
||||
{
|
||||
if (obj == [self content])
|
||||
{
|
||||
NSDictionary * bindingInfo = [self infoForBinding: NSContentObjectBinding];
|
||||
|
||||
[self setContent: nil];
|
||||
// TODO
|
||||
if (bindingInfo)
|
||||
{
|
||||
// Change the relationship of the object that our content is bound to.
|
||||
id masterObject = [bindingInfo objectForKey: NSObservedObjectKey];
|
||||
NSString * keyPath = [bindingInfo objectForKey: NSObservedKeyPathKey];
|
||||
[masterObject setValue: nil forKeyPath: keyPath];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
- (BOOL) canAdd
|
||||
{
|
||||
return YES;
|
||||
return [self isEditable];
|
||||
}
|
||||
|
||||
- (BOOL) canRemove
|
||||
{
|
||||
return YES;
|
||||
return [self isEditable] && [[self selectedObjects] count] > 0;
|
||||
}
|
||||
|
||||
- (BOOL) isEditable
|
||||
|
@ -261,7 +340,7 @@
|
|||
- (NSArray*) selectedObjects
|
||||
{
|
||||
// TODO
|
||||
return nil;
|
||||
return _selection;
|
||||
}
|
||||
|
||||
- (id) selection
|
||||
|
|
|
@ -626,6 +626,7 @@ NSString *NSValueTransformerNameBindingOption = @"NSValueTransformerName";
|
|||
NSString *NSValueTransformerBindingOption = @"NSValueTransformer";
|
||||
|
||||
NSString *NSAlignmentBinding = @"alignment";
|
||||
NSString *NSContentObjectBinding = @"contentObject";
|
||||
NSString *NSEditableBinding = @"editable";
|
||||
NSString *NSEnabledBinding = @"enabled";
|
||||
NSString *NSFontBinding = @"font";
|
||||
|
|
Loading…
Reference in a new issue