Improved attachObject:toParent: and implemented more of the resource manager.

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/apps/gorm/trunk@21080 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Gregory John Casamento 2005-04-10 22:21:59 +00:00
parent 3a84a68109
commit 660c9fd7ad
9 changed files with 212 additions and 160 deletions

View file

@ -1,3 +1,18 @@
2005-04-10 18:13 Gregory John Casamento <greg_casamento@yahoo.com>
* GormCore/GormDocument.h: Organized methods.
* GormCore/GormDocument.m: Added code here to add to top
level objects array, when appropriate.
* GormCore/GormGenericEditor.m: Prevent close when already
closed.
* GormCore/GormObjectEditor.m: Removed code which adds
to document/top level objects, this is done in the document now.
* GormCore/GormPrivate.h: Added new ivar to GormGenericEditor
* GormLib/IBResourceManager.h
* GormLib/IBResourceManager.m: Corrected implementation of
register methods.
* Resources/ClassInformation.plist: Added Object.
2005-04-03 07:36 Gregory John Casamento <greg_casamento@yahoo.com>
* GormLib/IBResourceManager.[hm]: Implementation of this class.

View file

@ -64,7 +64,7 @@
BOOL isActive;
BOOL isDocumentOpen;
NSMenu *savedMenu;
NSMenuItem *quitItem; /* Replaced during test */
NSMenuItem *quitItem; /* Replaced during test-mode */
NSMutableArray *savedEditors;
NSMutableArray *hidden;
NSMutableArray *openEditors;
@ -74,59 +74,39 @@
id filePrefsView;
id filePrefsManager;
NSWindow *filePrefsWindow;
NSMutableArray *resourceManagers;
}
- (void) addConnector: (id<IBConnectors>)aConnector;
- (NSArray*) allConnectors;
- (void) attachObject: (id)anObject toParent: (id)aParent;
- (void) attachObjects: (NSArray*)anArray toParent: (id)aParent;
/* Archiving objects */
- (void) beginArchiving;
- (GormClassManager*) classManager;
- (NSArray*) connectorsForDestination: (id)destination;
- (NSArray*) connectorsForDestination: (id)destination
ofClass: (Class)aConnectorClass;
- (NSArray*) connectorsForSource: (id)source;
- (NSArray*) connectorsForSource: (id)source
ofClass: (Class)aConnectorClass;
- (BOOL) containsObject: (id)anObject;
- (BOOL) containsObjectWithName: (NSString*)aName forParent: (id)parent;
- (BOOL) copyObject: (id)anObject
type: (NSString*)aType
toPasteboard: (NSPasteboard*)aPasteboard;
- (BOOL) copyObjects: (NSArray*)anArray
type: (NSString*)aType
toPasteboard: (NSPasteboard*)aPasteboard;
- (void) detachObject: (id)anObject;
- (void) detachObjects: (NSArray*)anArray;
- (NSString*) documentPath;
- (void) endArchiving;
/* Handle notifications */
- (void) handleNotification: (NSNotification*)aNotification;
/* Document management */
- (BOOL) isActive;
- (NSString*) nameForObject: (id)anObject;
- (id) objectForName: (NSString*)aString;
- (BOOL) objectIsVisibleAtLaunch: (id)anObject;
- (BOOL) objectIsDeferred: (id)anObject;
- (NSArray*) objects;
- (id) loadDocument: (NSString*)path;
- (id) openDocument: (id)sender;
- (id) parentOfObject: (id)anObject;
- (NSArray*) pasteType: (NSString*)aType
fromPasteboard: (NSPasteboard*)aPasteboard
parent: (id)parent;
- (void) removeConnector: (id<IBConnectors>)aConnector;
- (id) revertDocument: (id)sender;
- (BOOL) saveAsDocument: (id)sender;
- (BOOL) saveGormDocument: (id)sender;
- (void) setupDefaults: (NSString*)type;
- (void) setDocumentActive: (BOOL)flag;
- (void) setName: (NSString*)aName forObject: (id)object;
- (void) setObject: (id)anObject isVisibleAtLaunch: (BOOL)flag;
- (void) setObject: (id)anObject isDeferred: (BOOL)flag;
- (void) touch; /* Mark document as having been changed. */
- (NSWindow*) window;
- (BOOL) couldCloseDocument;
- (BOOL) windowShouldClose: (id)sender;
- (BOOL) isTopLevelObject: (id)obj;
- (void) closeAllEditors;
- (void) createResourceManagers;
- (NSArray *) resourceManagers;
// classes support..
/* Managing classes */
- (GormClassManager*) classManager;
- (id) createSubclass: (id)sender;
- (id) instantiateClass: (id)sender;
- (id) createClassFiles: (id)sender;
@ -138,11 +118,11 @@
- (BOOL) classIsSelected;
- (void) removeAllInstancesOfClass: (NSString *)classNamed;
// sound & image support
/* Sound & Image support */
- (id) openSound: (id)sender;
- (id) openImage: (id)sender;
// Internals support
/* Connections */
- (void) rebuildObjToNameMapping;
- (BOOL) removeConnectionsWithLabel: (NSString *)name
forClassNamed: (NSString *)className
@ -150,24 +130,24 @@
- (BOOL) removeConnectionsForClassNamed: (NSString *)name;
- (BOOL) renameConnectionsForClassNamed: (NSString *)name
toName: (NSString *)newName;
- (BOOL) isTopLevelObject: (id)obj;
- (void) closeAllEditors;
// class loading
/* class loading */
- (id) loadClass: (id)sender;
// services/windows menus...
/* services/windows menus... */
- (void) setServicesMenu: (NSMenu *)menu;
- (NSMenu *) servicesMenu;
- (void) setWindowsMenu: (NSMenu *)menu;
- (NSMenu *) windowsMenu;
// first responder/font manager
/* first responder/font manager */
- (id) fontManager;
- (id) firstResponder;
// windowAndRect:forObject: is called by Gorm to determine where it should
// draw selection markup
/*
* windowAndRect:forObject: is called by Gorm to determine where it should
* draw selection markup
*/
- (NSWindow*) windowAndRect: (NSRect*)r forObject: (id)object;
@end

View file

@ -254,7 +254,11 @@ static NSImage *fileImage = nil;
selector: @selector(handleNotification:)
name: IBWillEndTestingInterfaceNotification
object: nil];
[nc addObserver: self
selector: @selector(handleNotification:)
name: IBResourceManagerRegistryDidChangeNotification
object: nil];
// objects...
mainRect.origin = NSMakePoint(0,0);
scrollView = [[NSScrollView alloc] initWithFrame: scrollRect];
@ -379,8 +383,12 @@ static NSImage *fileImage = nil;
// are we upgrading an archive?
isOlderArchive = NO;
// document is open...
isDocumentOpen = YES;
// load resource managers
[self createResourceManagers];
}
else
{
@ -451,6 +459,7 @@ static NSImage *fileImage = nil;
{
aParent = filesOwner;
}
old = [self connectorsForSource: anObject ofClass: [NSNibConnector class]];
if ([old count] > 0)
{
@ -465,6 +474,7 @@ static NSImage *fileImage = nil;
[self addConnector: (id<IBConnectors>)con];
RELEASE(con);
}
/*
* Make sure that there is a name for this object.
*/
@ -488,6 +498,22 @@ static NSImage *fileImage = nil;
[anObject setReleasedWhenClosed: NO];
}
}
else if((aParent == filesOwner || aParent == nil) &&
[anObject isKindOfClass: [NSMenu class]] == NO)
{
if([anObject isKindOfClass: [NSObject class]] &&
[anObject isKindOfClass: [NSView class]] == NO)
{
[objectsView addObject: anObject];
[topLevelObjects addObject: anObject];
}
else if([anObject isKindOfClass: [NSView class]] && [anObject superview] == nil)
{
[objectsView addObject: anObject];
[topLevelObjects addObject: anObject];
}
}
/*
* Check if it's a font manager.
*/
@ -497,6 +523,7 @@ static NSImage *fileImage = nil;
// the proxy instead.
[self _instantiateFontManager];
}
/*
* Add the current menu and any submenus.
*/
@ -951,6 +978,10 @@ static NSImage *fileImage = nil;
// windows...
RELEASE(window);
RELEASE(filePrefsWindow);
// resource managers
RELEASE(resourceManagers);
[super dealloc];
}
@ -1508,6 +1539,15 @@ static NSImage *fileImage = nil;
[classesView selectClass: newClass];
}
}
else if([name isEqual: IBResourceManagerRegistryDidChangeNotification])
{
if(resourceManagers != nil)
{
Class cls = [aNotification object];
id mgr = [(IBResourceManager *)[cls alloc] initWithDocument: self];
[resourceManagers addObject: mgr];
}
}
}
- (id) instantiateClass: (id)sender
@ -1555,8 +1595,8 @@ static NSImage *fileImage = nil;
// add it to the top level objects...
[self setName: nil forObject: instance];
[self attachObject: instance toParent: nil];
[topLevelObjects addObject: instance];
[objectsView addObject: instance];
// [topLevelObjects addObject: instance];
// [objectsView addObject: instance];
// we want to record if it's custom or not and act appropriately...
if(isCustom)
@ -3426,6 +3466,31 @@ static NSImage *fileImage = nil;
{
return fontManager;
}
- (void) createResourceManagers
{
NSArray *resourceClasses = [IBResourceManager registeredResourceManagerClassesForFramework: nil];
NSEnumerator *en = [resourceClasses objectEnumerator];
Class cls = nil;
if(resourceManagers != nil)
{
// refresh...
DESTROY(resourceManagers);
}
resourceManagers = [[NSMutableArray alloc] init];
while((cls = [en nextObject]) != nil)
{
id mgr = [(IBResourceManager *)[cls alloc] initWithDocument: self];
[resourceManagers addObject: mgr];
}
}
- (NSArray *) resourceManagers
{
return resourceManagers;
}
@end
@implementation GormDocument (MenuValidation)

View file

@ -113,10 +113,13 @@
- (void) close
{
closed = YES;
[document editor: self didCloseForObject: [self editedObject]];
[self deactivate];
[self closeSubeditors];
if(closed == NO)
{
closed = YES;
[document editor: self didCloseForObject: [self editedObject]];
[self deactivate];
[self closeSubeditors];
}
}
// Stubbed out methods... Since this is an abstract class, some methods need to be
@ -137,6 +140,7 @@
document = aDocument;
closed = NO;
activated = NO;
resourceManager = nil;
}
return self;
}
@ -169,7 +173,8 @@
if(closed == NO)
[self close];
RELEASE(objects); //
RELEASE(objects);
RELEASE(resourceManager);
[super dealloc];
}

View file

@ -90,6 +90,9 @@ static NSMapTable *docMap = 0;
docMap = NSCreateMapTable(NSObjectMapKeyCallBacks,
NSObjectMapValueCallBacks,
2);
// create the resource manager...
[IBResourceManager registerResourceManagerClass: [IBResourceManager class]];
}
}
@ -128,7 +131,7 @@ static NSMapTable *docMap = 0;
if (selected != nil)
{
[document copyObjects: [self selection]
type: IBViewPboardType
type: IBObjectPboardType
toPasteboard: [NSPasteboard generalPasteboard]];
}
}
@ -158,7 +161,7 @@ static NSMapTable *docMap = 0;
[document detachObject: selected];
if ([selected isKindOfClass: [NSWindow class]] == YES)
{
NSArray *subviews = allSubviews([selected contentView]);
NSArray *subviews = allSubviews([(NSWindow *)selected contentView]);
[document detachObjects: subviews];
[selected close];
}
@ -428,8 +431,8 @@ static NSMapTable *docMap = 0;
if (dragType == IBObjectPboardType)
{
NSArray *array;
NSEnumerator *enumerator;
id obj;
// NSEnumerator *enumerator;
// id obj;
/*
* Ask the document to get the dragged objects from the pasteboard and
@ -438,13 +441,17 @@ static NSMapTable *docMap = 0;
array = [document pasteType: IBObjectPboardType
fromPasteboard: dragPb
parent: [objects objectAtIndex: 0]];
/*
enumerator = [array objectEnumerator];
while ((obj = [enumerator nextObject]) != nil)
{
RETAIN(obj); // FIXME: This will probably leak...
RETAIN(obj);
[[(GormDocument *)document topLevelObjects] addObject: obj];
[self addObject: obj];
}
*/
return YES;
}
else if (dragType == GormLinkPboardType)

View file

@ -112,6 +112,7 @@ extern NSString *GormResizeCellNotification;
NSString *dragType;
BOOL closed;
BOOL activated;
IBResourceManager *resourceManager;
}
// selection methods...
- (void) selectObjects: (NSArray*)objects;

View file

@ -26,11 +26,12 @@
#define INCLUDED_IBRESOURCEMANAGER_H
#include <Foundation/NSObject.h>
#include <Foundation/NSArray.h>
#include <InterfaceBuilder/IBProjects.h>
#include <InterfaceBuilder/IBProjectFiles.h>
#include <InterfaceBuilder/IBDocuments.h>
@class NSArray, NSString, NSPasteboard, NSMutableArray;
@class NSString, NSPasteboard, NSMutableArray;
/**
* Notification sent when a resource manager class is added to /removed from

View file

@ -23,6 +23,7 @@
*/
#include <InterfaceBuilder/IBResourceManager.h>
#include <InterfaceBuilder/IBObjectAdditions.h>
#include <InterfaceBuilder/IBPalette.h>
#include <Foundation/NSArchiver.h>
#include <Foundation/NSArray.h>
@ -30,19 +31,19 @@
#include <Foundation/NSMapTable.h>
#include <Foundation/NSNotification.h>
#include <Foundation/NSString.h>
#include <Foundation/NSNull.h>
#include <AppKit/NSPasteboard.h>
/**
* Notification sent when a resource manager class is added to /removed from
* the registry.
*/
NSString *IBResourceManagerRegistryDidChangeNotification = @"IBResourceManagerRegistryDidChangeNotification";
static NSMapTable *_resourceManagers = NULL;
@implementation IBResourceManager : NSObject
+ (void) _createTable
/**
* Create the resource manager table.
*/
+ (BOOL) _createTable
{
if(_resourceManagers == NULL)
{
@ -50,68 +51,83 @@ static NSMapTable *_resourceManagers = NULL;
NSObjectMapValueCallBacks,
2);
}
return (_resourceManagers != NULL);
}
/**
* Register the given class as a resource mananger.
* Add a class to the resourceManager master list of classes.
*/
+ (void) _addClass: (Class)managerClass
{
if([self _createTable])
{
NSMutableArray *list = NSMapGet(_resourceManagers, [NSNull null]);
if(list == nil)
{
list = [NSMutableArray array];
NSMapInsert(_resourceManagers, [NSNull null], list);
}
if([list containsObject: managerClass] == NO)
{
[list addObject: managerClass];
}
}
}
+ (void) registerResourceManagerClass: (Class)managerClass
{
NSMutableArray *list = NSMapGet(_resourceManagers, NULL);
if(list == NULL)
{
list = [NSMutableArray array];
NSMapInsert(_resourceManagers, NULL, list);
}
[list addObject: managerClass];
// notify.
[[NSNotificationCenter defaultCenter]
postNotificationName: IBResourceManagerRegistryDidChangeNotification
object: nil];
[self _addClass: managerClass];
}
/**
* Register the given class as a resource manager for the frameworks in the array.
*/
+ (void) registerResourceManagerClass: (Class)managerClass
forFrameworks: (NSArray *)frameworks
{
NSEnumerator *en = [frameworks objectEnumerator];
NSString *fw = nil;
[self _createTable];
while((fw = [en nextObject]) != nil)
if([self _createTable])
{
NSMutableArray *list = NSMapGet(_resourceManagers, fw);
if(list == NULL)
NSMutableArray *list = nil;
if(frameworks == nil)
{
list = [NSMutableArray array];
NSMapInsert(_resourceManagers, fw, list);
[self _addClass: managerClass];
}
[list addObject: managerClass];
}
else
{
NSEnumerator *en = [frameworks objectEnumerator];
NSString *fw = nil;
// notify
[[NSNotificationCenter defaultCenter]
postNotificationName: IBResourceManagerRegistryDidChangeNotification
object: nil];
// add it to all of the frameworks.
while((fw = [en nextObject]) != nil)
{
list = NSMapGet(_resourceManagers, fw);
if(list == nil)
{
list = [NSMutableArray array];
NSMapInsert(_resourceManagers, fw, list);
}
if([list containsObject: managerClass] == NO)
{
[list addObject: managerClass];
}
}
// also add it to the master list.
[self _addClass: managerClass];
}
// notify
[[NSNotificationCenter defaultCenter]
postNotificationName: IBResourceManagerRegistryDidChangeNotification
object: managerClass];
}
}
/**
* Return an array of classes for the given framework.
*/
+ (NSArray *) registeredResourceManagerClassesForFramework: (NSString *)framework
{
return (NSArray *)(NSMapGet(_resourceManagers, framework));
return (NSArray *)(NSMapGet(_resourceManagers, ((framework == nil)?(void *)[NSNull null]:framework)));
}
/**
* Returns YES, if the pasteboard contains a type the resource
* manager can accept.
*/
- (BOOL) acceptsResourcesFromPasteboard: (NSPasteboard *)pboard
{
NSArray *types = [pboard types];
@ -127,52 +143,43 @@ static NSMapTable *_resourceManagers = NULL;
return result;
}
/**
* Add an array of resources.
*/
- (void) addResources: (NSArray *)resourceList
{
// abstract...
[document attachObjects: resourceList toParent: nil];
}
/**
* Add resoures from the pasteboard. Invokes the
* acceptsResourcesFromPasteboard: method to determine
* if the resources will be added.
*/
- (void) addResourcesFromPasteboard: (NSPasteboard *)pboard
{
// abstract...
NSArray *resourcePbTypes = [self resourcePasteboardTypes];
NSString *type = nil;
NSEnumerator *en = [resourcePbTypes objectEnumerator];
while((type = [en nextObject]) != nil)
{
NSData *data = [pboard dataForType: type];
id obj = [NSUnarchiver unarchiveObjectWithData: data];
if(obj != nil)
{
[document attachObject: obj toParent: nil];
}
}
}
/**
* Called by an external application when a file owned by
* the GUI builder is modified. Override this method in a
* subclass to take some special action.
*/
- (void) application: (NSString *) appName didModifyFileAtPath: (NSString *)path
{
// does nothing.
}
/**
* Returns the document with which this resource manager is
* associated.
*/
- (id<IBDocuments>) document
{
return document;
}
/**
* Instantiate the resource manager with the given
* document object.
*/
- (id) initWithDocument: (id<IBDocuments>)doc
{
if((self = [super init]) != nil)
{
document = doc;
document = doc; // weak connection.
}
return self;
}
@ -186,73 +193,42 @@ static NSMapTable *_resourceManagers = NULL;
[super dealloc];
}
/**
* Returns YES, if this resource manager is non-modifiable.
*/
- (BOOL) isReadOnly;
{
return NO;
}
/**
* Called by an external application when the a file
* is added. Override in subclass to take action.
*/
- (void) project: (id<IBProjects>)proj didAddFile: (id<IBProjectFiles>)file
{
}
/**
* Called by an external application when the a file
* changes localization. Override this method in a subclass
* to take some special action.
*/
- (void) project: (id<IBProjects>)proj didChangeLocalizationOfFile: (id<IBProjectFiles>)file
{
}
/**
* Called by an external application when a file
* is removed. Override this in a subclass to take
* some special action.
*/
- (void) project: (id<IBProjects>)proj didRemoveFile: (id<IBProjectFiles>)file
{
// does nothing
// does nothing in base implementation.
}
/**
* Returns a list of resource file types this manager can accept. Default
* implementation returns nil.
*/
- (NSArray *) resourceFileTypes
{
return nil;
}
/**
* Returns a list of pasteboard types this manager can accept. Default
* implementation returns nil.
*/
- (NSArray *) resourcePasteboardTypes
{
return [NSArray arrayWithObjects: IBObjectPboardType, IBViewPboardType, nil];
}
/**
* Returns the associated resources for the objects.
*/
- (NSArray *) resourcesForObjects: (NSArray *)objs;
{
return nil;
}
/**
* Writes resources to the document path.
*/
- (void) writeToDocumentPath: (NSString *)path
{
// does nothing.
// does nothing in base implementation.
}
@end

View file

@ -586,4 +586,6 @@
);
Super = NSResponder;
};
Object = {
};
}