From 1465667cebfd4a5570257cb8a58795eaabbdcb14 Mon Sep 17 00:00:00 2001 From: Gregory John Casamento Date: Mon, 11 Apr 2005 04:05:30 +0000 Subject: [PATCH] Corrections for IBResourceManager. git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/apps/gorm/trunk@21084 72102866-910b-0410-8b05-ffd578937521 --- ChangeLog | 7 +++++ GormCore/GormDocument.m | 22 +++++++------ GormCore/GormObjectEditor.m | 61 +++++++++++++++++++++---------------- 3 files changed, 54 insertions(+), 36 deletions(-) diff --git a/ChangeLog b/ChangeLog index ee145f7e..49cba072 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2005-04-10 23:59 Gregory John Casamento + + * GormCore/GormDocument.m: Moved call to register IBResourceManager + here and also correct a memory problem. + * GormCore/GormObjectEditor.m: Corrected a problem with + registering the types. + 2005-04-10 22:42 Gregory John Casamento * GormCore/GormFilePrefsManager.m diff --git a/GormCore/GormDocument.m b/GormCore/GormDocument.m index 4d4826a0..d6ece2e6 100644 --- a/GormCore/GormDocument.m +++ b/GormCore/GormDocument.m @@ -180,6 +180,9 @@ static NSImage *fileImage = nil; { fileImage = [[NSImage alloc] initWithContentsOfFile: path]; } + + // create the resource manager... + [IBResourceManager registerResourceManagerClass: [IBResourceManager class]]; [self setVersion: GNUSTEP_NIB_VERSION]; } @@ -259,6 +262,9 @@ static NSImage *fileImage = nil; name: IBResourceManagerRegistryDidChangeNotification object: nil]; + // load resource managers + [self createResourceManagers]; + // objects... mainRect.origin = NSMakePoint(0,0); scrollView = [[NSScrollView alloc] initWithFrame: scrollRect]; @@ -386,9 +392,6 @@ static NSImage *fileImage = nil; // document is open... isDocumentOpen = YES; - - // load resource managers - [self createResourceManagers]; } else { @@ -1262,7 +1265,7 @@ static NSImage *fileImage = nil; id link; editor = [[eClass alloc] initWithObject: anObject inDocument: self]; - link = [GormObjectToEditor new]; + link = AUTORELEASE([GormObjectToEditor new]); [link setSource: anObject]; [link setDestination: editor]; [connections addObject: link]; @@ -1272,7 +1275,6 @@ static NSImage *fileImage = nil; [openEditors addObject: editor]; } - RELEASE(link); if (anEditor == nil) { /* @@ -1286,11 +1288,10 @@ static NSImage *fileImage = nil; /* * Link to the parent of the editor. */ - link = [GormEditorToParent new]; + link = AUTORELEASE([GormEditorToParent new]); [link setSource: editor]; [link setDestination: anEditor]; [connections addObject: link]; - RELEASE(link); } else { @@ -1298,6 +1299,7 @@ static NSImage *fileImage = nil; } [editor activate]; RELEASE((NSObject *)editor); + return editor; } else if ([links count] == 0) @@ -2261,8 +2263,9 @@ static NSImage *fileImage = nil; else { NSEnumerator *enumerator = [objects objectEnumerator]; - id obj; NSRect frame; + id obj; + while ((obj = [enumerator nextObject]) != nil) { // check to see if the object has a frame. If so, then @@ -2526,7 +2529,7 @@ static NSImage *fileImage = nil; } // nameCopy = [aName copy]; /* Make sure it's immutable */ [nameTable setObject: object forKey: aName]; - RELEASE(object); // make sure that when it's removed from the table, it's released. + // RELEASE(object); // TODO: Make sure whether we do or do not need this. NSMapInsert(objToName, (void*)object, (void*) aName); //nameCopy); if (oldName != nil) { @@ -2548,7 +2551,6 @@ static NSImage *fileImage = nil; [cc setObject: className forKey: aName]; //nameCopy]; } } - // RELEASE(nameCopy); // release the copy of the name which we made... } - (void) setObject: (id)anObject isVisibleAtLaunch: (BOOL)flag diff --git a/GormCore/GormObjectEditor.m b/GormCore/GormObjectEditor.m index e72b2b0e..b4706c4c 100644 --- a/GormCore/GormObjectEditor.m +++ b/GormCore/GormObjectEditor.m @@ -90,9 +90,6 @@ static NSMapTable *docMap = 0; docMap = NSCreateMapTable(NSObjectMapKeyCallBacks, NSObjectMapValueCallBacks, 2); - - // create the resource manager... - [IBResourceManager registerResourceManagerClass: [IBResourceManager class]]; } } @@ -124,16 +121,12 @@ static NSMapTable *docMap = 0; - (void) pasteInSelection { + // not implemented } - (void) copySelection { - if (selected != nil) - { - [document copyObjects: [self selection] - type: IBObjectPboardType - toPasteboard: [NSPasteboard generalPasteboard]]; - } + // not implemented } - (void) deleteSelection @@ -216,11 +209,12 @@ static NSMapTable *docMap = 0; { NSArray *types; NSString *type; + NSArray *resourceTypes = [resourceManager resourcePasteboardTypes]; dragPb = [sender draggingPasteboard]; types = [dragPb types]; resourceManager = [(GormDocument *)document resourceManagerForPasteboard: dragPb]; - type = [[resourceManager resourcePasteboardTypes] firstObjectCommonWithArray: types]; + type = [resourceTypes firstObjectCommonWithArray: types]; if (type != nil) { @@ -286,6 +280,24 @@ static NSMapTable *docMap = 0; { } +- (void) _registerForAllResourceManagers +{ + NSMutableArray *allTypes = [[NSMutableArray alloc] initWithObjects: GormLinkPboardType, nil]; + NSArray *mgrs = [(GormDocument *)document resourceManagers]; + NSEnumerator *en = [mgrs objectEnumerator]; + IBResourceManager *mgr = nil; + + AUTORELEASE(allTypes); + + while((mgr = [en nextObject]) != nil) + { + NSArray *pbTypes = [mgr resourcePasteboardTypes]; + [allTypes addObjectsFromArray: pbTypes]; + } + + [self registerForDraggedTypes: allTypes]; +} + - (void) handleNotification: (NSNotification*)aNotification { NSString *name = [aNotification name]; @@ -295,6 +307,10 @@ static NSMapTable *docMap = 0; NSDebugLog(@"Recieved notification"); [self setCellSize: defaultCellSize()]; } + else if([name isEqual: IBResourceManagerRegistryDidChangeNotification]) + { + [self _registerForAllResourceManagers]; + } } /* @@ -319,8 +335,9 @@ static NSMapTable *docMap = 0; document = aDocument; - [self registerForDraggedTypes: [NSArray arrayWithObjects: - IBObjectPboardType, GormLinkPboardType, nil]]; + [self _registerForAllResourceManagers]; + // [self registerForDraggedTypes: [NSArray arrayWithObjects: + // IBObjectPboardType, GormLinkPboardType, nil]]; [self setAutosizesCells: NO]; [self setCellSize: defaultCellSize()]; @@ -353,6 +370,12 @@ static NSMapTable *docMap = 0; selector: @selector(handleNotification:) name: GormResizeCellNotification object: nil]; + + [[NSNotificationCenter defaultCenter] + addObserver: self + selector: @selector(handleNotification:) + name: IBResourceManagerRegistryDidChangeNotification + object: nil]; } return self; } @@ -434,20 +457,6 @@ static NSMapTable *docMap = 0; { if ([[resourceManager resourcePasteboardTypes] containsObject: dragType]) { - // NSArray *array; - // NSEnumerator *enumerator; - // id obj; - - /* - * 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]]; - */ - [resourceManager addResourcesFromPasteboard: dragPb]; return YES; }