From d9cc3735846427b056b03a435f8f4ecec20d961d Mon Sep 17 00:00:00 2001 From: Gregory John Casamento Date: Mon, 11 Apr 2005 00:16:01 +0000 Subject: [PATCH] Implementation of resource manager handling for adding objects to the document. git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/apps/gorm/trunk@21082 72102866-910b-0410-8b05-ffd578937521 --- ChangeLog | 10 ++++++++++ GormCore/GormDocument.h | 1 + GormCore/GormDocument.m | 17 +++++++++++++++++ GormCore/GormObjectEditor.m | 27 ++++++++++++--------------- GormLib/IBResourceManager.h | 2 +- GormLib/IBResourceManager.m | 33 ++++++++++++--------------------- 6 files changed, 53 insertions(+), 37 deletions(-) diff --git a/ChangeLog b/ChangeLog index 0b2accd8..bcf67e95 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,13 @@ +2005-04-10 20:09 Gregory John Casamento + + * GormCore/GormDocument.h + * GormCore/GormDocument.m: addition of the method + resourceManagerForPasteboard:. + * GormCore/GormObjectEditor.m: Changes to utilize IBResourceManager + * GormLib/IBResourceManager.h + * GormLib/IBResourceManager.m: Changes to add objects to the document + properly. + 2005-04-10 18:13 Gregory John Casamento * GormCore/GormDocument.h: Organized methods. diff --git a/GormCore/GormDocument.h b/GormCore/GormDocument.h index e4fa9eaa..847448d5 100644 --- a/GormCore/GormDocument.h +++ b/GormCore/GormDocument.h @@ -104,6 +104,7 @@ - (void) closeAllEditors; - (void) createResourceManagers; - (NSArray *) resourceManagers; +- (IBResourceManager *) resourceManagerForPasteboard: (NSPasteboard *)pboard; /* Managing classes */ - (GormClassManager*) classManager; diff --git a/GormCore/GormDocument.m b/GormCore/GormDocument.m index bee360a4..4d4826a0 100644 --- a/GormCore/GormDocument.m +++ b/GormCore/GormDocument.m @@ -3491,6 +3491,23 @@ static NSImage *fileImage = nil; { return resourceManagers; } + +- (IBResourceManager *) resourceManagerForPasteboard: (NSPasteboard *)pboard +{ + NSEnumerator *en = [resourceManagers objectEnumerator]; + IBResourceManager *mgr = nil, *result = nil; + + while((mgr = [en nextObject]) != nil) + { + if([mgr acceptsResourcesFromPasteboard: pboard]) + { + result = mgr; + break; + } + } + + return result; +} @end @implementation GormDocument (MenuValidation) diff --git a/GormCore/GormObjectEditor.m b/GormCore/GormObjectEditor.m index 70a15c30..e72b2b0e 100644 --- a/GormCore/GormObjectEditor.m +++ b/GormCore/GormObjectEditor.m @@ -215,12 +215,16 @@ static NSMapTable *docMap = 0; - (unsigned) draggingEntered: (id)sender { NSArray *types; + NSString *type; dragPb = [sender draggingPasteboard]; types = [dragPb types]; - if ([types containsObject: IBObjectPboardType] == YES) + resourceManager = [(GormDocument *)document resourceManagerForPasteboard: dragPb]; + type = [[resourceManager resourcePasteboardTypes] firstObjectCommonWithArray: types]; + + if (type != nil) { - dragType = IBObjectPboardType; + dragType = type; } else if ([types containsObject: GormLinkPboardType] == YES) { @@ -235,7 +239,7 @@ static NSMapTable *docMap = 0; - (unsigned) draggingUpdated: (id)sender { - if (dragType == IBObjectPboardType) + if ([[resourceManager resourcePasteboardTypes] containsObject: dragType]) { return NSDragOperationCopy; } @@ -428,9 +432,9 @@ static NSMapTable *docMap = 0; - (BOOL) performDragOperation: (id)sender { - if (dragType == IBObjectPboardType) + if ([[resourceManager resourcePasteboardTypes] containsObject: dragType]) { - NSArray *array; + // NSArray *array; // NSEnumerator *enumerator; // id obj; @@ -438,20 +442,13 @@ static NSMapTable *docMap = 0; * Ask the document to get the dragged objects from the pasteboard and * add them to it's collection of known objects. */ + /* array = [document pasteType: IBObjectPboardType fromPasteboard: dragPb parent: [objects objectAtIndex: 0]]; - - /* - enumerator = [array objectEnumerator]; - while ((obj = [enumerator nextObject]) != nil) - { - RETAIN(obj); - [[(GormDocument *)document topLevelObjects] addObject: obj]; - [self addObject: obj]; - } */ - + + [resourceManager addResourcesFromPasteboard: dragPb]; return YES; } else if (dragType == GormLinkPboardType) diff --git a/GormLib/IBResourceManager.h b/GormLib/IBResourceManager.h index 71ab4f40..3a69daa5 100644 --- a/GormLib/IBResourceManager.h +++ b/GormLib/IBResourceManager.h @@ -73,7 +73,7 @@ enum IBResourceLocation { + (NSArray *) registeredResourceManagerClassesForFramework: (NSString *)framework; /** - * Returns YES, if the pasteboard contains a type the resource + * Returns YES, if the pasteboard contains a type the resource * manager can accept. */ - (BOOL) acceptsResourcesFromPasteboard: (NSPasteboard *)pboard; diff --git a/GormLib/IBResourceManager.m b/GormLib/IBResourceManager.m index a8be81de..122d84d9 100644 --- a/GormLib/IBResourceManager.m +++ b/GormLib/IBResourceManager.m @@ -132,15 +132,8 @@ static NSMapTable *_resourceManagers = NULL; { NSArray *types = [pboard types]; NSArray *resourcePbTypes = [self resourcePasteboardTypes]; - id obj = [types firstObjectCommonWithArray: resourcePbTypes]; - BOOL result = NO; - - if(obj != nil) - { - result = YES; - } - - return result; + NSString *type = [types firstObjectCommonWithArray: resourcePbTypes]; + return (type != nil); } - (void) addResources: (NSArray *)resourceList @@ -150,19 +143,17 @@ static NSMapTable *_resourceManagers = NULL; - (void) addResourcesFromPasteboard: (NSPasteboard *)pboard { - NSArray *resourcePbTypes = [self resourcePasteboardTypes]; - NSString *type = nil; - NSEnumerator *en = [resourcePbTypes objectEnumerator]; + NSArray *types = [pboard types]; + NSArray *resourcePbTypes = [self resourcePasteboardTypes]; + NSString *type = [types firstObjectCommonWithArray: resourcePbTypes]; - while((type = [en nextObject]) != nil) - { - NSData *data = [pboard dataForType: type]; - id obj = [NSUnarchiver unarchiveObjectWithData: data]; - if(obj != nil) - { - [document attachObject: obj toParent: nil]; - } - } + /* + * Ask the document to get the dragged objects from the pasteboard and + * add them to it's collection of known objects. + */ + [document pasteType: type + fromPasteboard: pboard + parent: nil]; } - (void) application: (NSString *) appName didModifyFileAtPath: (NSString *)path