dded basic support for the controller classes from Cocoa.

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@24218 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Fred Kiefer 2006-12-19 18:35:16 +00:00
parent 1eefe4bf31
commit 2eaf22ccb4
12 changed files with 1180 additions and 1 deletions

View file

@ -1,3 +1,20 @@
2006-12-19 Fred Kiefer <FredKiefer@gmx.de>
* Headers/AppKit/NSObjectController.h
* Headers/AppKit/NSUserDefaultsController.h
* Headers/AppKit/NSKeyValueBinding.h
* Headers/AppKit/NSArrayController.h
* Headers/AppKit/NSController.h
* Source/NSObjectController.m
* Source/NSUserDefaultsController.m
* Source/NSArrayController.m
* Source/NSController.m:
New files added as basic support for controllers.
Mostly not implemented.
* Source/GNUmakefile
* Source/externs.m:
Add these new classes and helper variables.
2006-12-18 Saso Kiselkov
* Source/NSAlert.m: Left align long alert messages.

View file

@ -0,0 +1,91 @@
/** <title>NSArrayController</title>
<abstract>Controller class for arrays</abstract>
Copyright <copy>(C) 2006 Free Software Foundation, Inc.</copy>
Author: Fred Kiefer <fredkiefer@gmx.de>
Date: June 2006
This file is part of the GNUstep GUI Library.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with this library; see the file COPYING.LIB.
If not, write to the Free Software Foundation,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#ifndef _GNUstep_H_NSArrayController
#define _GNUstep_H_NSArrayController
#include <AppKit/NSObjectController.h>
#if OS_API_VERSION(100300,GS_API_LATEST)
@class NSArray;
@class NSIndexSet;
@interface NSArrayController : NSObjectController
{
NSMutableArray *_arrange_objects;
NSArray *_sort_descriptors;
NSIndexSet *_selection_indexes;
BOOL _avoids_empty_Selection;
BOOL _preserves_selection;
}
- (void) addObjects: (NSArray*)obj;
- (void) removeObjects: (NSArray*)obj;
- (BOOL) canInsert;
- (void) insert: (id)sender;
- (BOOL) addSelectedObjects: (NSArray*)obj;
- (BOOL) addSelectionIndexes: (NSIndexSet*)idx;
- (BOOL) setSelectedObjects: (NSArray*)obj;
- (BOOL) setSelectionIndex: (unsigned int)idx;
- (BOOL) setSelectionIndexes: (NSIndexSet*)idx;
- (BOOL) removeSelectedObjects: (NSArray*)obj;
- (BOOL) removeSelectionIndexes: (NSIndexSet*)idx;
- (void) selectNext: (id)sender;
- (void) selectPrevious: (id)sender;
- (NSArray*) selectedObjects;
- (unsigned int) 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;
- (NSArray*) arrangeObjects: (NSArray*)obj;
- (id) arrangedObjects;
- (void) rearrangeObjects;
- (void) setSortDescriptors: (NSArray*)desc;
- (NSArray*) sortDescriptors;
- (void) insertObject: (id)obj
atArrangedObjectIndex: (unsigned int)idx;
- (void) insertObjects: (NSArray*)obj
atArrangedObjectIndexes: (NSIndexSet*)idx;
- (void) removeObjectAtArrangedObjectIndex: (unsigned int)idx;
- (void) removeObjectsAtArrangedObjectIndexes: (NSIndexSet*)idx;
@end
#endif // OS_API_VERSION
#endif // _GNUstep_H_NSArrayController

View file

@ -0,0 +1,56 @@
/** <title>NSController</title>
<abstract>abstract base class for controllers</abstract>
Copyright <copy>(C) 2006 Free Software Foundation, Inc.</copy>
Author: Fred Kiefer <fredkiefer@gmx.de>
Date: June 2006
This file is part of the GNUstep GUI Library.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with this library; see the file COPYING.LIB.
If not, write to the Free Software Foundation,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#ifndef _GNUstep_H_NSController
#define _GNUstep_H_NSController
#include <Foundation/NSObject.h>
#if OS_API_VERSION(100300,GS_API_LATEST)
@class NSMutableArray;
@interface NSController : NSObject <NSCoding>
{
NSMutableArray *_editors;
}
// NSEditor protocol
- (BOOL) commitEditing;
- (void) discardEditing;
- (BOOL) isEditing;
// NSEditorRegistration protocol
- (void) objectDidBeginEditing: (id)editor;
- (void) objectDidEndEditing: (id)editor;
@end
#endif // OS_API_VERSION
#endif // _GNUstep_H_NSController

View file

@ -0,0 +1,99 @@
/** <title>NSKeyValueBinding</title>
<abstract>Interfae declaration for key value binding</abstract>
Copyright <copy>(C) 2006 Free Software Foundation, Inc.</copy>
Author: Fred Kiefer <fredkiefer@gmx.de>
Date: June 2006
This file is part of the GNUstep GUI Library.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with this library; see the file COPYING.LIB.
If not, write to the Free Software Foundation,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#ifndef _GNUstep_H_NSKeyValueBinding
#define _GNUstep_H_NSKeyValueBinding
#include <Foundation/NSObject.h>
#if OS_API_VERSION(100300,GS_API_LATEST)
@class NSString;
@class NSArray;
@class NSDictionary;
@interface NSObject (NSKeyValueBindingCreation)
+ (void) exposeBinding: (NSString *)key;
- (NSArray *) exposedBindings;
- (Class) valueClassForBinding: (NSString *)binding;
- (void) bind: (NSString *)binding
toObject: (id)controller
withKeyPath: (NSString *)keyPath
options: (NSDictionary *)options;
- (void) unbind: (NSString *)binding;
- (void) commitEditingWithDelegate: (id)delegate
didCommitSelector: (SEL)didCommitSelector
contextInfo: (void *)contextInfo;
- (NSDictionary *) infoForBinding: (NSString *)binding;
@end
@interface NSObject (NSPlaceholder)
+ (id) defaultPlaceholderForMarker: (id)marker
withBinding: (NSString *)binding;
+ (void) setDefaultPlaceholder: (id)placeholder
forMarker: (id)marker
withBinding: (NSString *)binding;
@end
@interface NSObject (NSEditor)
- (BOOL) commitEditing;
- (void) discardEditing;
@end
@interface NSObject (NSEditorRegistration)
- (void) objectDidBeginEditing: (id)editor;
- (void) objectDidEndEditing: (id)editor;
@end
// Keys in options dictionary
// binding values
// Keys in dictionary returned by infoForBinding
APPKIT_EXPORT NSString *NSObservedObjectKey;
APPKIT_EXPORT NSString *NSObservedKeyPath;
APPKIT_EXPORT NSString *NSOptionsKey;
// special markers
APPKIT_EXPORT id NSMultipleValuesMarker;
APPKIT_EXPORT id NSNoSelectionMarker;
APPKIT_EXPORT id NSNotApplicableMarker;
#endif // OS_API_VERSION
#endif // _GNUstep_H_NSKeyValueBinding

View file

@ -0,0 +1,99 @@
/** <title>NSObjectController</title>
<abstract>Controller class</abstract>
Copyright <copy>(C) 2006 Free Software Foundation, Inc.</copy>
Author: Fred Kiefer <fredkiefer@gmx.de>
Date: June 2006
This file is part of the GNUstep GUI Library.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with this library; see the file COPYING.LIB.
If not, write to the Free Software Foundation,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#ifndef _GNUstep_H_NSObjectController
#define _GNUstep_H_NSObjectController
#include <AppKit/NSController.h>
#include <AppKit/NSMenuItem.h>
#if OS_API_VERSION(100300,GS_API_LATEST)
@class NSArray;
@class NSMutableArray;
@class NSString;
@class NSPredicate;
@class NSError;
@class NSFetchRequest;
@class NSManagedObjectContext;
@interface NSObjectController : NSController
{
Class _object_class;
id _content;
NSMutableArray *_selection;
NSString *_entity_name_key;
NSPredicate *_fetch_predicate;
NSManagedObjectContext *_managed_object_context;
BOOL _is_editable;
BOOL _automatically_prepares_content;
}
- (id) initWithContent: (id)content;
- (id) content;
- (void) setContent: (id)content;
- (Class) objectClass;
- (void) setObjectClass: (Class)class;
- (id) newObject;
- (void) prepareContent;
- (BOOL) automaticallyPreparesContent;
- (void) setAutomaticallyPreparesContent: (BOOL)flag;
- (void) add: (id)sender;
- (void) addObject: (id)obj;
- (void) remove: (id)sender;
- (void) removeObject: (id)obj;
- (BOOL) canAdd;
- (BOOL) canRemove;
- (BOOL) isEditable;
- (void) setEditable: (BOOL)flag;
- (NSArray*) selectedObjects;
- (id) selection;
- (BOOL) validateMenuItem: (id <NSMenuItem>)item;
#if OS_API_VERSION(100400,GS_API_LATEST)
- (NSString*) entityNameKey;
- (void) setEntityName: (NSString*)entityName;
- (NSPredicate*) fetchPredicate;
- (void) setFetchPredicate: (NSPredicate*)predicate;
- (void) fetch: (id)sender;
- (BOOL) fetchWithRequest: (NSFetchRequest*)fetchRequest
merge: (BOOL)merge
error: (NSError**)error;
- (NSManagedObjectContext*) managedObjectContext;
- (void) setManagedObjectContext: (NSManagedObjectContext*)managedObjectContext;
#endif //OS_API_VERSION
@end
#endif // OS_API_VERSION
#endif // _GNUstep_H_NSObjectController

View file

@ -0,0 +1,65 @@
/** <title>NSUserDefaultsController</title>
<abstract>Controller class for user defaults</abstract>
Copyright <copy>(C) 2006 Free Software Foundation, Inc.</copy>
Author: Fred Kiefer <fredkiefer@gmx.de>
Date: September 2006
This file is part of the GNUstep GUI Library.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with this library; see the file COPYING.LIB.
If not, write to the Free Software Foundation,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#ifndef _GNUstep_H_NSUserDefaultsController
#define _GNUstep_H_NSUserDefaultsController
#include <AppKit/NSController.h>
#if OS_API_VERSION(100300,GS_API_LATEST)
@class NSUserDefaults;
@class NSDictionary;
@class NSMutableDictionary;
@interface NSUserDefaultsController : NSController
{
NSUserDefaults* _defaults;
NSDictionary* _initial_values;
BOOL _applies_immediately;
}
+ (id) sharedUserDefaultsController;
- (id) initWithDefaults: (NSUserDefaults*)defaults
initialValues: (NSDictionary*)initialValues;
- (NSUserDefaults*) defaults;
- (id) values;
- (NSDictionary*) initialValues;
- (void) setInitialValues: (NSDictionary*)values;
- (BOOL) appliesImmediately;
- (void) setAppliesImmediately: (BOOL)flag;
- (void) revert: (id)sender;
- (void) revertToInitialValues: (id)sender;
- (void) save: (id)sender;
@end
#endif // OS_API_VERSION
#endif // _GNUstep_H_NSUserDefaultsController

View file

@ -51,6 +51,7 @@ NSActionCell.m \
NSAffineTransform.m \
NSAlert.m \
NSApplication.m \
NSArrayController.m \
NSAttributedString.m \
NSBezierPath.m \
NSBitmapImageRep.m \
@ -75,6 +76,7 @@ NSColorWell.m \
NSComboBox.m \
NSComboBoxCell.m \
NSControl.m \
NSController.m \
NSCursor.m \
NSCustomImageRep.m \
NSDataLink.m \
@ -110,6 +112,7 @@ NSMenuItemCell.m \
NSMovie.m \
NSMovieView.m \
NSNib.m \
NSObjectController.m \
NSOpenGLContext.m \
NSOpenGLPixelFormat.m \
NSOpenGLView.m \
@ -159,6 +162,7 @@ NSTextFieldCell.m \
NSTextStorage.m \
NSToolbar.m \
NSToolbarItem.m \
NSUserDefaultsController.m \
NSView.m \
NSWindow+Toolbar.m \
NSWindow.m \
@ -230,6 +234,7 @@ NSActionCell.h \
NSAffineTransform.h \
NSAlert.h \
NSApplication.h \
NSArrayController.h \
NSBezierPath.h \
NSBox.h \
NSBitmapImageRep.h \
@ -248,6 +253,7 @@ NSColorWell.h \
NSComboBox.h \
NSComboBoxCell.h \
NSControl.h \
NSController.h \
NSCursor.h \
NSCustomImageRep.h \
NSDataLink.h \
@ -282,6 +288,7 @@ NSMenuItemCell.h \
NSMenuView.h \
NSMovie.h \
NSMovieView.h \
NSObjectController.h \
NSOpenPanel.h \
NSOpenGL.h \
NSOpenGLView.h \
@ -332,6 +339,7 @@ NSTextStorage.h \
NSTextView.h \
NSToolbar.h \
NSToolbarItem.h \
NSUserDefaultsController.h \
NSView.h \
NSWindow.h \
NSWindowController.h \

274
Source/NSArrayController.m Normal file
View file

@ -0,0 +1,274 @@
/** <title>NSArrayController</title>
<abstract>Controller class for arrays</abstract>
Copyright <copy>(C) 2006 Free Software Foundation, Inc.</copy>
Author: Fred Kiefer <fredkiefer@gmx.de>
Date: June 2006
This file is part of the GNUstep GUI Library.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with this library; see the file COPYING.LIB.
If not, write to the Free Software Foundation,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#include <Foundation/NSArray.h>
#include <Foundation/NSDictionary.h>
#include <Foundation/NSString.h>
#include <AppKit/NSArrayController.h>
@implementation NSArrayController
- (id) initWithContent: (id)content
{
if ((self = [super initWithContent: content]) != nil)
{
_arrange_objects = [[NSMutableArray alloc] init];
}
return self;
}
- (id) init
{
NSMutableArray *new = [[NSMutableArray alloc] init];
self = [self initWithContent: new];
RELEASE(new);
return self;
}
- (void) addObject: (id)obj
{
[_content addObject: obj];
[_arrange_objects addObject: obj];
}
- (void) addObjects: (NSArray*)obj
{
[_content addObjectsFromArray: obj];
if ([self selectsInsertedObjects])
{
[_arrange_objects addObjectsFromArray: obj];
}
}
- (void) removeObject: (id)obj
{
[_content removeObject: obj];
[_arrange_objects removeObject: obj];
}
- (void) removeObjects: (NSArray*)obj
{
[_content removeObjectsInArray: obj];
[_arrange_objects removeObjectsInArray: obj];
}
- (BOOL) canInsert
{
return YES;
}
- (void) insert: (id)sender
{
id new = [self newObject];
[_content addObject: new];
RELEASE(new);
}
- (BOOL) addSelectedObjects: (NSArray*)obj
{
// TODO
return NO;
}
- (BOOL) addSelectionIndexes: (NSIndexSet*)idx
{
// TODO
return NO;
}
- (BOOL) setSelectedObjects: (NSArray*)obj
{
// TODO
return NO;
}
- (BOOL) setSelectionIndex: (unsigned int)idx
{
// TODO
return NO;
}
- (BOOL) setSelectionIndexes: (NSIndexSet*)idx
{
// TODO
return NO;
}
- (BOOL) removeSelectedObjects: (NSArray*)obj
{
// TODO
return NO;
}
- (BOOL) removeSelectionIndexes: (NSIndexSet*)idx
{
// TODO
return NO;
}
- (void) selectNext: (id)sender
{
// TODO
return;
}
- (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;
}
- (BOOL) canSelectPrevious
{
// TODO
return NO;
}
- (BOOL) avoidsEmptySelection
{
// TODO
return NO;
}
- (void) setAvoidsEmptySelection: (BOOL)flag
{
// TODO
return;
}
- (BOOL) preservesSelection
{
// TODO
return NO;
}
- (void) setPreservesSelection: (BOOL)flag
{
// TODO
return;
}
- (BOOL) selectsInsertedObjects
{
// TODO
return NO;
}
- (void) setSelectsInsertedObjects: (BOOL)flag
{
// TODO
return;
}
- (NSArray*) arrangeObjects: (NSArray*)obj
{
// TODO
return nil;
}
- (id) arrangedObjects
{
// TODO
return nil;
}
- (void) rearrangeObjects
{
// TODO
return;
}
- (void) setSortDescriptors: (NSArray*)desc
{
// TODO
return;
}
- (NSArray*) sortDescriptors
{
// TODO
return nil;
}
- (void) insertObject: (id)obj
atArrangedObjectIndex: (unsigned int)idx
{
// TODO
return;
}
- (void) insertObjects: (NSArray*)obj
atArrangedObjectIndexes: (NSIndexSet*)idx
{
// TODO
return;
}
- (void) removeObjectAtArrangedObjectIndex: (unsigned int)idx
{
// TODO
return;
}
- (void) removeObjectsAtArrangedObjectIndexes: (NSIndexSet*)idx
{
// TODO
return;
}
@end

93
Source/NSController.m Normal file
View file

@ -0,0 +1,93 @@
/** <title>NSController</title>
<abstract>abstract base class for controllers</abstract>
Copyright <copy>(C) 2006 Free Software Foundation, Inc.</copy>
Author: Fred Kiefer <fredkiefer@gmx.de>
Date: June 2006
This file is part of the GNUstep GUI Library.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with this library; see the file COPYING.LIB.
If not, write to the Free Software Foundation,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#include <Foundation/NSArray.h>
#include <AppKit/NSController.h>
@implementation NSController
- (id) init
{
_editors = [[NSMutableArray alloc] init];
return self;
}
- (void) dealloc
{
RELEASE(_editors);
[super dealloc];
}
- (void) encodeWithCoder: (NSCoder *)aCoder
{
// TODO
}
- (id) initWithCoder: (NSCoder *)aDecoder
{
// TODO
return self;
}
- (BOOL) isEditing
{
return [_editors count] > 0;
}
- (BOOL) commitEditing
{
unsigned c = [_editors count];
unsigned i;
for (i = 0; i < c; i++)
{
if (![[_editors objectAtIndex: i] commitEditing])
{
return NO;
}
}
return YES;
}
- (void) discardEditing
{
[_editors makeObjectsPerformSelector: @selector(discardEditing)];
}
- (void) objectDidBeginEditing: (id)editor
{
[_editors addObject: editor];
}
- (void) objectDidEndEditing: (id)editor
{
[_editors removeObject: editor];
}
@end

253
Source/NSObjectController.m Normal file
View file

@ -0,0 +1,253 @@
/** <title>NSObjectController</title>
<abstract>Controller class</abstract>
Copyright <copy>(C) 2006 Free Software Foundation, Inc.</copy>
Author: Fred Kiefer <fredkiefer@gmx.de>
Date: June 2006
This file is part of the GNUstep GUI Library.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with this library; see the file COPYING.LIB.
If not, write to the Free Software Foundation,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#include <Foundation/NSArray.h>
#include <Foundation/NSDictionary.h>
#include <Foundation/NSPredicate.h>
#include <Foundation/NSString.h>
#include <AppKit/NSObjectController.h>
@implementation NSObjectController
- (id) initWithContent: (id)content
{
if ((self = [super init]) != nil)
{
[self setContent: content];
[self setObjectClass: [NSMutableDictionary class]];
[self setEditable: YES];
}
return self;
}
- (id) init
{
return [self initWithContent: nil];
}
- (void) dealloc
{
RELEASE(_content);
RELEASE(_entity_name_key);
RELEASE(_fetch_predicate);
[super dealloc];
}
- (void) encodeWithCoder: (NSCoder *)aCoder
{
[super encodeWithCoder: aCoder];
// TODO
}
- (id) initWithCoder: (NSCoder *)aDecoder
{
self = [super initWithCoder: aDecoder];
// TODO
if ([self automaticallyPreparesContent])
{
if ([self managedObjectContext] != nil)
{
[self fetch: aDecoder];
}
else
{
[self prepareContent];
}
}
return self;
}
- (id) content
{
return _content;
}
- (void) setContent: (id)content
{
ASSIGN(_content, content);
}
- (Class) objectClass
{
return _object_class;
}
- (void) setObjectClass: (Class)class
{
_object_class = class;
}
- (id) newObject
{
return [[[self objectClass] alloc] init];
}
- (void) prepareContent
{
id new = [self newObject];
[self setContent: new];
RELEASE(new);
}
- (BOOL) automaticallyPreparesContent
{
return _automatically_prepares_content;
}
- (void) setAutomaticallyPreparesContent: (BOOL)flag
{
_automatically_prepares_content = flag;
}
- (void) add: (id)sender
{
id new = [self newObject];
[self addObject: new];
RELEASE(new);
}
- (void) addObject: (id)obj
{
[self setContent: obj];
// TODO
}
- (void) remove: (id)sender
{
[self removeObject: [self content]];
}
- (void) removeObject: (id)obj
{
if (obj == [self content])
{
[self setContent: nil];
// TODO
}
}
- (BOOL) canAdd
{
return YES;
}
- (BOOL) canRemove
{
return YES;
}
- (BOOL) isEditable
{
return _is_editable;
}
- (void) setEditable: (BOOL)flag
{
_is_editable = flag;
}
- (NSArray*) selectedObjects
{
// TODO
return nil;
}
- (id) selection
{
// TODO
return nil;
}
- (BOOL) validateMenuItem: (id <NSMenuItem>)item
{
SEL action = [item action];
if (sel_eq(action, @selector(add:)))
{
return [self canAdd];
}
else if (sel_eq(action, @selector(remove:)))
{
return [self canRemove];
}
return YES;
}
- (NSString*) entityNameKey
{
return _entity_name_key;
}
- (void) setEntityName: (NSString*)entityName
{
ASSIGN(_entity_name_key, entityName);
}
- (NSPredicate*) fetchPredicate
{
return _fetch_predicate;
}
- (void) setFetchPredicate: (NSPredicate*)predicate
{
ASSIGN(_fetch_predicate, predicate);
}
- (void) fetch: (id)sender
{
NSError *error;
[self fetchWithRequest: nil merge: NO error: &error];
}
- (BOOL) fetchWithRequest: (NSFetchRequest*)fetchRequest
merge: (BOOL)merge
error: (NSError**)error
{
// TODO
//[_managed_object_context executeFetchRequest: fetchRequest error: error];
return NO;
}
- (NSManagedObjectContext*) managedObjectContext
{
return _managed_object_context;
}
- (void) setManagedObjectContext: (NSManagedObjectContext*)managedObjectContext
{
_managed_object_context = managedObjectContext;
}
@end

View file

@ -0,0 +1,114 @@
/** <title>NSUserDefaultsController</title>
<abstract>Controller class for user defaults</abstract>
Copyright <copy>(C) 2006 Free Software Foundation, Inc.</copy>
Author: Fred Kiefer <fredkiefer@gmx.de>
Date: September 2006
This file is part of the GNUstep GUI Library.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with this library; see the file COPYING.LIB.
If not, write to the Free Software Foundation,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#include <Foundation/NSDictionary.h>
#include <Foundation/NSUserDefaults.h>
#include <AppKit/NSUserDefaultsController.h>
static id shared = nil;
@implementation NSUserDefaultsController
+ (id) sharedUserDefaultsController
{
if (shared == nil)
{
shared = [[NSUserDefaultsController alloc]
initWithDefaults: nil
initialValues: nil];
}
return shared;
}
- (id) initWithDefaults: (NSUserDefaults*)defaults
initialValues: (NSDictionary*)initialValues
{
if ((self = [super init]) != nil)
{
if (defaults == nil)
{
defaults = [NSUserDefaults standardUserDefaults];
}
ASSIGN(_defaults, defaults);
[self setInitialValues: initialValues];
}
return self;
}
- (NSUserDefaults*) defaults
{
return _defaults;
}
- (id) values
{
// TODO
return nil;
}
- (NSDictionary*) initialValues
{
return _initial_values;
}
- (void) setInitialValues: (NSDictionary*)values
{
ASSIGN(_initial_values, values);
}
- (BOOL) appliesImmediately
{
return _applies_immediately;
}
- (void) setAppliesImmediately: (BOOL)flag
{
_applies_immediately = flag;
}
- (void) revert: (id)sender
{
[self discardEditing];
if (![self appliesImmediately])
{
// TODO
}
}
- (void) revertToInitialValues: (id)sender
{
// TODO
}
- (void) save: (id)sender
{
// TODO
}
@end

View file

@ -490,6 +490,16 @@ const NSWindowDepth _GSWindowDepths[7] = { 258, 264, 514, 516, 517, 520, 0 };
/* End of color functions externs */
// NSKeyValueBinding
NSString *NSObservedObjectKey = @"NSObservedObjectKey";
NSString *NSObservedKeyPath = @"NSObservedKeyPath";
NSString *NSOptionsKey = @"NSOptionsKey";
// FIXME: Need to defined!
id NSMultipleValuesMarker = nil;
id NSNoSelectionMarker = nil;
id NSNotApplicableMarker = nil;
extern void __objc_gui_force_linking (void);
void