diff --git a/ChangeLog b/ChangeLog index 6f4acd481..b5f5ce7be 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,4 +1,21 @@ -2006-12-18 Saso Kiselkov +2006-12-19 Fred Kiefer + + * 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. diff --git a/Headers/AppKit/NSArrayController.h b/Headers/AppKit/NSArrayController.h new file mode 100644 index 000000000..e12cacc29 --- /dev/null +++ b/Headers/AppKit/NSArrayController.h @@ -0,0 +1,91 @@ +/** NSArrayController + + Controller class for arrays + + Copyright (C) 2006 Free Software Foundation, Inc. + + Author: Fred Kiefer + 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 + +#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 diff --git a/Headers/AppKit/NSController.h b/Headers/AppKit/NSController.h new file mode 100644 index 000000000..4495455fc --- /dev/null +++ b/Headers/AppKit/NSController.h @@ -0,0 +1,56 @@ +/** NSController + + abstract base class for controllers + + Copyright (C) 2006 Free Software Foundation, Inc. + + Author: Fred Kiefer + 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 + +#if OS_API_VERSION(100300,GS_API_LATEST) + +@class NSMutableArray; + +@interface NSController : NSObject +{ + 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 diff --git a/Headers/AppKit/NSKeyValueBinding.h b/Headers/AppKit/NSKeyValueBinding.h new file mode 100644 index 000000000..b41543abe --- /dev/null +++ b/Headers/AppKit/NSKeyValueBinding.h @@ -0,0 +1,99 @@ +/** NSKeyValueBinding + + Interfae declaration for key value binding + + Copyright (C) 2006 Free Software Foundation, Inc. + + Author: Fred Kiefer + 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 + +#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 diff --git a/Headers/AppKit/NSObjectController.h b/Headers/AppKit/NSObjectController.h new file mode 100644 index 000000000..efe00ffd9 --- /dev/null +++ b/Headers/AppKit/NSObjectController.h @@ -0,0 +1,99 @@ +/** NSObjectController + + Controller class + + Copyright (C) 2006 Free Software Foundation, Inc. + + Author: Fred Kiefer + 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 +#include + +#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 )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 diff --git a/Headers/AppKit/NSUserDefaultsController.h b/Headers/AppKit/NSUserDefaultsController.h new file mode 100644 index 000000000..8461e13fc --- /dev/null +++ b/Headers/AppKit/NSUserDefaultsController.h @@ -0,0 +1,65 @@ +/** NSUserDefaultsController + + Controller class for user defaults + + Copyright (C) 2006 Free Software Foundation, Inc. + + Author: Fred Kiefer + 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 + +#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 diff --git a/Source/GNUmakefile b/Source/GNUmakefile index 77f1e3c7d..b499b31c5 100644 --- a/Source/GNUmakefile +++ b/Source/GNUmakefile @@ -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 \ diff --git a/Source/NSArrayController.m b/Source/NSArrayController.m new file mode 100644 index 000000000..7a95e5b1f --- /dev/null +++ b/Source/NSArrayController.m @@ -0,0 +1,274 @@ +/** NSArrayController + + Controller class for arrays + + Copyright (C) 2006 Free Software Foundation, Inc. + + Author: Fred Kiefer + 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 +#include +#include +#include + +@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 diff --git a/Source/NSController.m b/Source/NSController.m new file mode 100644 index 000000000..7fdf80cd1 --- /dev/null +++ b/Source/NSController.m @@ -0,0 +1,93 @@ +/** NSController + + abstract base class for controllers + + Copyright (C) 2006 Free Software Foundation, Inc. + + Author: Fred Kiefer + 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 +#include + +@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 diff --git a/Source/NSObjectController.m b/Source/NSObjectController.m new file mode 100644 index 000000000..674dd4b0c --- /dev/null +++ b/Source/NSObjectController.m @@ -0,0 +1,253 @@ +/** NSObjectController + + Controller class + + Copyright (C) 2006 Free Software Foundation, Inc. + + Author: Fred Kiefer + 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 +#include +#include +#include +#include + +@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 )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 diff --git a/Source/NSUserDefaultsController.m b/Source/NSUserDefaultsController.m new file mode 100644 index 000000000..be9db0514 --- /dev/null +++ b/Source/NSUserDefaultsController.m @@ -0,0 +1,114 @@ +/** NSUserDefaultsController + + Controller class for user defaults + + Copyright (C) 2006 Free Software Foundation, Inc. + + Author: Fred Kiefer + 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 +#include +#include + +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 diff --git a/Source/externs.m b/Source/externs.m index 7778a5687..50e4763a4 100644 --- a/Source/externs.m +++ b/Source/externs.m @@ -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