mirror of
https://github.com/gnustep/libs-gui.git
synced 2025-04-23 15:11:37 +00:00
* Source/NSObjectController.m: Complete encoding/decoding methods.
* Headers/AppKit/NSArrayController.h, * Source/NSArrayController.m: Add some implementation to this class. git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@34904 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
733983d52b
commit
37db8ec30e
4 changed files with 316 additions and 94 deletions
|
@ -1,3 +1,10 @@
|
|||
2012-03-08 Fred Kiefer <FredKiefer@gmx.de>
|
||||
|
||||
* Source/NSObjectController.m: Complete encoding/decoding methods.
|
||||
* Headers/AppKit/NSArrayController.h,
|
||||
* Source/NSArrayController.m: Add some implementation to this
|
||||
class.
|
||||
|
||||
2012-03-05 Eric Wasylishen <ewasylishen@gmail.com>
|
||||
|
||||
* Source/NSMenuItemCell.m (-titleRectForBounds:): Attempted fix
|
||||
|
|
|
@ -31,21 +31,32 @@
|
|||
|
||||
#import <AppKit/NSObjectController.h>
|
||||
|
||||
#if OS_API_VERSION(100300,GS_API_LATEST)
|
||||
#if OS_API_VERSION(MAC_OS_X_VERSION_10_3,GS_API_LATEST)
|
||||
|
||||
@class NSArray;
|
||||
@class NSMutableArray;
|
||||
@class NSIndexSet;
|
||||
@class NSPredicate;
|
||||
|
||||
@interface NSArrayController : NSObjectController
|
||||
{
|
||||
NSMutableArray *_arrange_objects;
|
||||
NSArray *_sort_descriptors;
|
||||
NSMutableArray *_arranged_objects;
|
||||
NSIndexSet *_selection_indexes;
|
||||
BOOL _avoids_empty_Selection;
|
||||
BOOL _preserves_selection;
|
||||
NSArray *_sort_descriptors;
|
||||
NSPredicate *_filter_predicate;
|
||||
struct GSArrayControllerFlagsType {
|
||||
unsigned always_uses_multiple_values_marker: 1;
|
||||
unsigned automatically_rearranges_objects: 1;
|
||||
unsigned avoids_empty_selection: 1;
|
||||
unsigned clears_filter_predicate_on_insertion: 1;
|
||||
unsigned preserves_selection: 1;
|
||||
unsigned selects_inserted_objects: 1;
|
||||
} _acflags;
|
||||
}
|
||||
|
||||
- (void) addObject: (id)obj;
|
||||
- (void) addObjects: (NSArray*)obj;
|
||||
- (void) removeObject: (id)obj;
|
||||
- (void) removeObjects: (NSArray*)obj;
|
||||
- (BOOL) canInsert;
|
||||
- (void) insert: (id)sender;
|
||||
|
@ -53,36 +64,50 @@
|
|||
- (BOOL) addSelectedObjects: (NSArray*)obj;
|
||||
- (BOOL) addSelectionIndexes: (NSIndexSet*)idx;
|
||||
- (BOOL) setSelectedObjects: (NSArray*)obj;
|
||||
- (BOOL) setSelectionIndex: (unsigned int)idx;
|
||||
- (BOOL) setSelectionIndex: (NSUInteger)idx;
|
||||
- (BOOL) setSelectionIndexes: (NSIndexSet*)idx;
|
||||
- (BOOL) removeSelectedObjects: (NSArray*)obj;
|
||||
- (BOOL) removeSelectionIndexes: (NSIndexSet*)idx;
|
||||
- (BOOL) canSelectNext;
|
||||
- (BOOL) canSelectPrevious;
|
||||
- (void) selectNext: (id)sender;
|
||||
- (void) selectPrevious: (id)sender;
|
||||
- (NSArray*) selectedObjects;
|
||||
- (unsigned int) selectionIndex;
|
||||
- (NSUInteger) selectionIndex;
|
||||
- (NSIndexSet*) selectionIndexes;
|
||||
|
||||
- (BOOL) canSelectNext;
|
||||
- (BOOL) canSelectPrevious;
|
||||
- (BOOL) avoidsEmptySelection;
|
||||
- (void) setAvoidsEmptySelection: (BOOL)flag;
|
||||
- (BOOL) preservesSelection;
|
||||
- (void) setPreservesSelection: (BOOL)flag;
|
||||
- (BOOL) selectsInsertedObjects;
|
||||
- (void) setSelectsInsertedObjects: (BOOL)flag;
|
||||
#if OS_API_VERSION(MAC_OS_X_VERSION_10_4, GS_API_LATEST)
|
||||
- (BOOL) alwaysUsesMultipleValuesMarker;
|
||||
- (void) setAlwaysUsesMultipleValuesMarker: (BOOL)flag;
|
||||
- (BOOL) clearsFilterPredicateOnInsertion;
|
||||
- (void) setClearsFilterPredicateOnInsertion: (BOOL)flag;
|
||||
#endif
|
||||
#if OS_API_VERSION(MAC_OS_X_VERSION_10_5, GS_API_LATEST)
|
||||
- (BOOL) automaticallyRearrangesObjects;
|
||||
- (void) setAutomaticallyRearrangesObjects: (BOOL)flag;
|
||||
#endif
|
||||
|
||||
- (NSArray*) arrangeObjects: (NSArray*)obj;
|
||||
- (id) arrangedObjects;
|
||||
- (void) rearrangeObjects;
|
||||
- (void) setSortDescriptors: (NSArray*)desc;
|
||||
- (NSArray*) sortDescriptors;
|
||||
#if OS_API_VERSION(MAC_OS_X_VERSION_10_4, GS_API_LATEST)
|
||||
- (void) setFilterPredicate: (NSPredicate*)filterPredicate;
|
||||
- (NSPredicate*) filterPredicate;
|
||||
#endif
|
||||
|
||||
- (void) insertObject: (id)obj
|
||||
atArrangedObjectIndex: (unsigned int)idx;
|
||||
atArrangedObjectIndex: (NSUInteger)idx;
|
||||
- (void) insertObjects: (NSArray*)obj
|
||||
atArrangedObjectIndexes: (NSIndexSet*)idx;
|
||||
- (void) removeObjectAtArrangedObjectIndex: (unsigned int)idx;
|
||||
- (void) removeObjectAtArrangedObjectIndex: (NSUInteger)idx;
|
||||
- (void) removeObjectsAtArrangedObjectIndexes: (NSIndexSet*)idx;
|
||||
|
||||
@end
|
||||
|
|
|
@ -27,18 +27,35 @@
|
|||
*/
|
||||
|
||||
|
||||
#import <Foundation/NSArchiver.h>
|
||||
#import <Foundation/NSArray.h>
|
||||
#import <Foundation/NSDictionary.h>
|
||||
#import <Foundation/NSIndexSet.h>
|
||||
#import <Foundation/NSPredicate.h>
|
||||
#import <Foundation/NSSortDescriptor.h>
|
||||
#import <Foundation/NSString.h>
|
||||
|
||||
#import "AppKit/NSArrayController.h"
|
||||
#import "AppKit/NSKeyValueBinding.h"
|
||||
#import "GSBindingHelpers.h"
|
||||
#import "GSFastEnumeration.h"
|
||||
|
||||
@implementation NSArrayController
|
||||
|
||||
+ (void) initialize
|
||||
{
|
||||
if (self == [NSArrayController class])
|
||||
{
|
||||
[self exposeBinding: @"contentArray"];
|
||||
}
|
||||
}
|
||||
|
||||
- (id) initWithContent: (id)content
|
||||
{
|
||||
if ((self = [super initWithContent: content]) != nil)
|
||||
{
|
||||
_arrange_objects = [[NSMutableArray alloc] init];
|
||||
_arranged_objects = [content copy];
|
||||
[self setSelectsInsertedObjects: YES];
|
||||
}
|
||||
|
||||
return self;
|
||||
|
@ -53,31 +70,53 @@
|
|||
return self;
|
||||
}
|
||||
|
||||
- (void) dealloc
|
||||
{
|
||||
DESTROY(_arranged_objects);
|
||||
DESTROY(_selection_indexes);
|
||||
DESTROY(_sort_descriptors);
|
||||
DESTROY(_filter_predicate);
|
||||
[super dealloc];
|
||||
}
|
||||
|
||||
- (void) addObject: (id)obj
|
||||
{
|
||||
[_content addObject: obj];
|
||||
[_arrange_objects addObject: obj];
|
||||
if ([self automaticallyRearrangesObjects])
|
||||
{
|
||||
[self rearrangeObjects];
|
||||
}
|
||||
}
|
||||
|
||||
- (void) addObjects: (NSArray*)obj
|
||||
{
|
||||
[_content addObjectsFromArray: obj];
|
||||
if ([self automaticallyRearrangesObjects])
|
||||
{
|
||||
[self rearrangeObjects];
|
||||
}
|
||||
if ([self selectsInsertedObjects])
|
||||
{
|
||||
[_arrange_objects addObjectsFromArray: obj];
|
||||
[self addSelectedObjects: obj];
|
||||
}
|
||||
}
|
||||
|
||||
- (void) removeObject: (id)obj
|
||||
{
|
||||
[_content removeObject: obj];
|
||||
[_arrange_objects removeObject: obj];
|
||||
if ([self automaticallyRearrangesObjects])
|
||||
{
|
||||
[self rearrangeObjects];
|
||||
}
|
||||
}
|
||||
|
||||
- (void) removeObjects: (NSArray*)obj
|
||||
{
|
||||
[_content removeObjectsInArray: obj];
|
||||
[_arrange_objects removeObjectsInArray: obj];
|
||||
if ([self automaticallyRearrangesObjects])
|
||||
{
|
||||
[self rearrangeObjects];
|
||||
}
|
||||
}
|
||||
|
||||
- (BOOL) canInsert
|
||||
|
@ -93,161 +132,233 @@
|
|||
RELEASE(new);
|
||||
}
|
||||
|
||||
- (NSIndexSet*) _indexSetForObjects: (NSArray*)objects
|
||||
{
|
||||
NSMutableIndexSet *tmp = [NSMutableIndexSet new];
|
||||
id<NSFastEnumeration> enumerator = objects;
|
||||
|
||||
FOR_IN (id, obj, enumerator)
|
||||
{
|
||||
NSUInteger index = [_arranged_objects indexOfObject: obj];
|
||||
if (NSNotFound != index)
|
||||
{
|
||||
[tmp addIndex: index];
|
||||
}
|
||||
}
|
||||
END_FOR_IN(enumerator)
|
||||
|
||||
return AUTORELEASE(tmp);
|
||||
}
|
||||
|
||||
- (BOOL) addSelectedObjects: (NSArray*)obj
|
||||
{
|
||||
// TODO
|
||||
return NO;
|
||||
return [self addSelectionIndexes: [self _indexSetForObjects: obj]];
|
||||
}
|
||||
|
||||
- (BOOL) addSelectionIndexes: (NSIndexSet*)idx
|
||||
{
|
||||
// TODO
|
||||
return NO;
|
||||
NSMutableIndexSet *tmp = AUTORELEASE([_selection_indexes mutableCopy]);
|
||||
|
||||
[tmp addIndexes: idx];
|
||||
return [self setSelectionIndexes: tmp];
|
||||
}
|
||||
|
||||
- (BOOL) setSelectedObjects: (NSArray*)obj
|
||||
{
|
||||
// TODO
|
||||
return NO;
|
||||
return [self setSelectionIndexes: [self _indexSetForObjects: obj]];
|
||||
}
|
||||
|
||||
- (BOOL) setSelectionIndex: (unsigned int)idx
|
||||
- (BOOL) setSelectionIndex: (NSUInteger)idx
|
||||
{
|
||||
// TODO
|
||||
return NO;
|
||||
return [self setSelectionIndexes:
|
||||
[NSIndexSet indexSetWithIndex: idx]];
|
||||
}
|
||||
|
||||
- (BOOL) setSelectionIndexes: (NSIndexSet*)idx
|
||||
{
|
||||
// TODO
|
||||
return NO;
|
||||
if ([_selection_indexes isEqual: idx])
|
||||
{
|
||||
return NO;
|
||||
}
|
||||
else
|
||||
{
|
||||
ASSIGNCOPY(_selection_indexes, idx);
|
||||
return YES;
|
||||
}
|
||||
}
|
||||
|
||||
- (BOOL) removeSelectedObjects: (NSArray*)obj
|
||||
{
|
||||
// TODO
|
||||
return NO;
|
||||
return [self removeSelectionIndexes: [self _indexSetForObjects: obj]];
|
||||
}
|
||||
|
||||
- (BOOL) removeSelectionIndexes: (NSIndexSet*)idx
|
||||
{
|
||||
// TODO
|
||||
return NO;
|
||||
}
|
||||
NSMutableIndexSet *tmp = AUTORELEASE([_selection_indexes mutableCopy]);
|
||||
|
||||
- (void) selectNext: (id)sender
|
||||
{
|
||||
// TODO
|
||||
return;
|
||||
[tmp removeIndexes: idx];
|
||||
return [self setSelectionIndexes: tmp];
|
||||
}
|
||||
|
||||
- (void) selectPrevious: (id)sender
|
||||
{
|
||||
// TODO
|
||||
return;
|
||||
}
|
||||
|
||||
- (NSArray*) selectedObjects
|
||||
{
|
||||
// TODO
|
||||
return nil;
|
||||
}
|
||||
|
||||
- (unsigned int) selectionIndex
|
||||
{
|
||||
// TODO
|
||||
return -1;
|
||||
}
|
||||
|
||||
- (NSIndexSet*) selectionIndexes
|
||||
{
|
||||
// TODO
|
||||
return nil;
|
||||
}
|
||||
|
||||
|
||||
- (BOOL) canSelectNext
|
||||
{
|
||||
// TODO
|
||||
return NO;
|
||||
NSUInteger cur = [self selectionIndex];
|
||||
|
||||
if ((cur == NSNotFound) || (cur + 1 == [_content count]))
|
||||
{
|
||||
return NO;
|
||||
}
|
||||
else
|
||||
{
|
||||
return YES;
|
||||
}
|
||||
}
|
||||
|
||||
- (BOOL) canSelectPrevious
|
||||
{
|
||||
// TODO
|
||||
return NO;
|
||||
NSUInteger cur = [self selectionIndex];
|
||||
|
||||
if ((cur == NSNotFound) || (cur == 0))
|
||||
{
|
||||
return NO;
|
||||
}
|
||||
else
|
||||
{
|
||||
return YES;
|
||||
}
|
||||
}
|
||||
|
||||
- (void) selectNext: (id)sender
|
||||
{
|
||||
NSUInteger cur = [self selectionIndex];
|
||||
|
||||
[self setSelectionIndexes:
|
||||
[NSIndexSet indexSetWithIndex: cur + 1]];
|
||||
}
|
||||
|
||||
- (void) selectPrevious: (id)sender
|
||||
{
|
||||
NSUInteger cur = [self selectionIndex];
|
||||
|
||||
[self setSelectionIndexes:
|
||||
[NSIndexSet indexSetWithIndex: cur - 1]];
|
||||
}
|
||||
|
||||
- (NSArray*) selectedObjects
|
||||
{
|
||||
// We make the selection work on the arranged objects
|
||||
return [_arranged_objects objectsAtIndexes: _selection_indexes];
|
||||
}
|
||||
|
||||
- (NSUInteger) selectionIndex
|
||||
{
|
||||
return [_selection_indexes firstIndex];
|
||||
}
|
||||
|
||||
- (NSIndexSet*) selectionIndexes
|
||||
{
|
||||
return AUTORELEASE([_selection_indexes copy]);
|
||||
}
|
||||
|
||||
- (BOOL) avoidsEmptySelection
|
||||
{
|
||||
// TODO
|
||||
return NO;
|
||||
return _acflags.avoids_empty_selection;
|
||||
}
|
||||
|
||||
- (void) setAvoidsEmptySelection: (BOOL)flag
|
||||
{
|
||||
// TODO
|
||||
return;
|
||||
_acflags.avoids_empty_selection = flag;
|
||||
}
|
||||
|
||||
- (BOOL) preservesSelection
|
||||
{
|
||||
// TODO
|
||||
return NO;
|
||||
return _acflags.preserves_selection;
|
||||
}
|
||||
|
||||
- (void) setPreservesSelection: (BOOL)flag
|
||||
{
|
||||
// TODO
|
||||
return;
|
||||
_acflags.preserves_selection = flag;
|
||||
}
|
||||
|
||||
- (BOOL) alwaysUsesMultipleValuesMarker;
|
||||
{
|
||||
return _acflags.always_uses_multiple_values_marker;
|
||||
}
|
||||
|
||||
- (void) setAlwaysUsesMultipleValuesMarker: (BOOL)flag;
|
||||
{
|
||||
_acflags.always_uses_multiple_values_marker = flag;
|
||||
}
|
||||
|
||||
- (BOOL) clearsFilterPredicateOnInsertion;
|
||||
{
|
||||
return _acflags.clears_filter_predicate_on_insertion;
|
||||
}
|
||||
|
||||
- (void) setClearsFilterPredicateOnInsertion: (BOOL)flag;
|
||||
{
|
||||
_acflags.clears_filter_predicate_on_insertion = flag;
|
||||
}
|
||||
|
||||
- (BOOL) automaticallyRearrangesObjects;
|
||||
{
|
||||
return _acflags.automatically_rearranges_objects;
|
||||
}
|
||||
|
||||
- (void) setAutomaticallyRearrangesObjects: (BOOL)flag;
|
||||
{
|
||||
_acflags.automatically_rearranges_objects = flag;
|
||||
}
|
||||
|
||||
- (BOOL) selectsInsertedObjects
|
||||
{
|
||||
// TODO
|
||||
return NO;
|
||||
return _acflags.selects_inserted_objects;
|
||||
}
|
||||
|
||||
- (void) setSelectsInsertedObjects: (BOOL)flag
|
||||
{
|
||||
// TODO
|
||||
return;
|
||||
_acflags.selects_inserted_objects = flag;
|
||||
}
|
||||
|
||||
|
||||
- (NSArray*) arrangeObjects: (NSArray*)obj
|
||||
{
|
||||
// TODO
|
||||
return nil;
|
||||
NSArray *temp = [obj filteredArrayUsingPredicate: _filter_predicate];
|
||||
|
||||
return [temp sortedArrayUsingDescriptors: _sort_descriptors];
|
||||
}
|
||||
|
||||
- (id) arrangedObjects
|
||||
{
|
||||
// TODO
|
||||
return nil;
|
||||
return _arranged_objects;
|
||||
}
|
||||
|
||||
- (void) rearrangeObjects
|
||||
{
|
||||
// TODO
|
||||
return;
|
||||
ASSIGN(_arranged_objects, [self arrangeObjects: _content]);
|
||||
}
|
||||
|
||||
- (void) setSortDescriptors: (NSArray*)desc
|
||||
{
|
||||
// TODO
|
||||
return;
|
||||
ASSIGNCOPY(_sort_descriptors, desc);
|
||||
}
|
||||
|
||||
- (NSArray*) sortDescriptors
|
||||
{
|
||||
// TODO
|
||||
return nil;
|
||||
return AUTORELEASE([_sort_descriptors copy]);
|
||||
}
|
||||
|
||||
- (void) setFilterPredicate: (NSPredicate*)filterPredicate
|
||||
{
|
||||
ASSIGN(_filter_predicate, filterPredicate);
|
||||
}
|
||||
|
||||
- (NSPredicate*) filterPredicate
|
||||
{
|
||||
return _filter_predicate;
|
||||
}
|
||||
|
||||
- (void) insertObject: (id)obj
|
||||
atArrangedObjectIndex: (unsigned int)idx
|
||||
atArrangedObjectIndex: (NSUInteger)idx
|
||||
{
|
||||
// TODO
|
||||
return;
|
||||
|
@ -260,16 +371,88 @@ atArrangedObjectIndexes: (NSIndexSet*)idx
|
|||
return;
|
||||
}
|
||||
|
||||
- (void) removeObjectAtArrangedObjectIndex: (unsigned int)idx
|
||||
- (void) removeObjectAtArrangedObjectIndex: (NSUInteger)idx
|
||||
{
|
||||
// TODO
|
||||
return;
|
||||
[self removeObject: [_arranged_objects objectAtIndex: idx]];
|
||||
}
|
||||
|
||||
- (void) removeObjectsAtArrangedObjectIndexes: (NSIndexSet*)idx
|
||||
{
|
||||
// TODO
|
||||
return;
|
||||
[self removeObjects: [_arranged_objects objectsAtIndexes: idx]];
|
||||
}
|
||||
|
||||
- (void)bind: (NSString *)binding
|
||||
toObject: (id)anObject
|
||||
withKeyPath: (NSString *)keyPath
|
||||
options: (NSDictionary *)options
|
||||
{
|
||||
if ([binding isEqual: @"contentArray"])
|
||||
{
|
||||
GSKeyValueBinding *kvb;
|
||||
|
||||
[self unbind: binding];
|
||||
kvb = [[GSKeyValueBinding alloc] initWithBinding: @"content"
|
||||
withName: binding
|
||||
toObject: anObject
|
||||
withKeyPath: keyPath
|
||||
options: options
|
||||
fromObject: self];
|
||||
// The binding will be retained in the binding table
|
||||
RELEASE(kvb);
|
||||
}
|
||||
else
|
||||
{
|
||||
[super bind: binding
|
||||
toObject: anObject
|
||||
withKeyPath: keyPath
|
||||
options: options];
|
||||
}
|
||||
}
|
||||
|
||||
- (void) encodeWithCoder: (NSCoder *)coder
|
||||
{
|
||||
[super encodeWithCoder: coder];
|
||||
if ([coder allowsKeyedCoding])
|
||||
{
|
||||
[coder encodeBool: [self avoidsEmptySelection] forKey: @"NSAvoidsEmptySelection"];
|
||||
[coder encodeBool: [self preservesSelection] forKey: @"NSPreservesSelection"];
|
||||
[coder encodeBool: [self selectsInsertedObjects] forKey: @"NSSelectsInsertedObjects"];
|
||||
}
|
||||
else
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
- (id) initWithCoder: (NSCoder *)coder
|
||||
{
|
||||
if ((self = [super initWithCoder: coder]) == nil)
|
||||
{
|
||||
return nil;
|
||||
}
|
||||
|
||||
if ([coder allowsKeyedCoding])
|
||||
{
|
||||
if ([coder containsValueForKey: @"NSAvoidsEmptySelection"])
|
||||
{
|
||||
[self setAvoidsEmptySelection:
|
||||
[coder decodeBoolForKey: @"NSAvoidsEmptySelection"]];
|
||||
}
|
||||
if ([coder containsValueForKey: @"NSPreservesSelection"])
|
||||
{
|
||||
[self setPreservesSelection:
|
||||
[coder decodeBoolForKey: @"NSPreservesSelection"]];
|
||||
}
|
||||
if ([coder containsValueForKey: @"NSSelectsInsertedObjects"])
|
||||
{
|
||||
[self setSelectsInsertedObjects:
|
||||
[coder decodeBoolForKey: @"NSSelectsInsertedObjects"]];
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
}
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
@end
|
||||
|
|
|
@ -145,6 +145,8 @@
|
|||
[coder encodeBool: _is_editable forKey: @"NSEditable"];
|
||||
[coder encodeBool: _automatically_prepares_content forKey: @"NSAutomaticallyPreparesContent"];
|
||||
[coder encodeObject: _managed_proxy forKey: @"_NSManagedProxy"];
|
||||
[coder encodeObject: NSStringFromClass([self objectClass])
|
||||
forKey: @"NSObjectClassName"];
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -175,6 +177,11 @@
|
|||
_is_editable = [coder decodeBoolForKey: @"NSEditable"];
|
||||
_automatically_prepares_content = [coder decodeBoolForKey: @"NSAutomaticallyPreparesContent"];
|
||||
ASSIGN(_managed_proxy, [coder decodeObjectForKey: @"_NSManagedProxy"]);
|
||||
if ([coder containsValueForKey: @"NSObjectClassName"])
|
||||
{
|
||||
NSString *className = [coder decodeObjectForKey: @"NSObjectClassName"];
|
||||
[self setObjectClass: NSClassFromString(className)];
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue