From 445a8c9cc5117ff02d1628dc221d1733e898ad57 Mon Sep 17 00:00:00 2001 From: Gregory John Casamento Date: Sun, 24 Aug 2003 17:10:05 +0000 Subject: [PATCH] Corrected issue which was causing custom class associations to not be deleted when a class is replaced or removed. git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/apps/gorm/trunk@17531 72102866-910b-0410-8b05-ffd578937521 --- ChangeLog | 11 +++++ GormClassManager.m | 84 ++++++++++++++++++++++++++++++++------ GormCustomClassInspector.m | 17 +++++--- GormDocument.m | 20 ++++++--- 4 files changed, 108 insertions(+), 24 deletions(-) diff --git a/ChangeLog b/ChangeLog index 2aa9f0ee..715b9c32 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,14 @@ +2003-08-23 Gregory John Casamento + + * GormDocument.m: Added some debug logs. And in + _replaceObjectsWithTemplates: modified the method to use the + customClassMap call instead of accessing the map directly. + * GormClassManager.m: renameClassNamed: and removeClassNamed: both + were failing to delete the custom class associations when a custom + class is renamed or removed. Added the code to do this. + * GormCustomClassInspector.m: Added check for nil return from the + classManager. Code will print a warning to stdout, if this happens. + 2003-08-23 Gregory John Casamento * GormDocument.m: Corrected selection problem. Moved code to diff --git a/GormClassManager.m b/GormClassManager.m index 4fb40484..e62e4bbd 100644 --- a/GormClassManager.m +++ b/GormClassManager.m @@ -146,12 +146,16 @@ return new; } -- (BOOL) addClassNamed: (NSString*)className - withSuperClassNamed: (NSString*)superClassName - withActions: (NSArray*)actions - withOutlets: (NSArray*)outlets +- (BOOL) addClassNamed: (NSString*)class_name + withSuperClassNamed: (NSString*)super_class_name + withActions: (NSArray*)_actions + withOutlets: (NSArray*)_outlets { BOOL result = NO; + NSString *className = [class_name copy]; + NSString *superClassName = [super_class_name copy]; + NSArray *actions = [_actions copy]; + NSArray *outlets = [_outlets copy]; if ([superClassName isEqualToString: @"NSObject"] || [classInformation objectForKey: superClassName] != nil) @@ -195,11 +199,12 @@ return result; } -- (void) addOutlet: (NSString*)anOutlet forObject: (id)anObject +- (void) addOutlet: (NSString*)outlet forObject: (id)anObject { NSMutableDictionary *info = [self classInfoForObject: anObject]; NSMutableArray *extraOutlets = [info objectForKey: @"ExtraOutlets"]; NSArray *allOutlets = [self allOutletsForObject: anObject]; + NSString *anOutlet = [outlet copy]; if ([allOutlets containsObject: anOutlet] == YES) { @@ -215,11 +220,12 @@ [[info objectForKey: @"AllOutlets"] addObject: anOutlet]; } -- (void) addAction: (NSString *)anAction forClassNamed: (NSString *)className +- (void) addAction: (NSString *)action forClassNamed: (NSString *)className { NSMutableDictionary *info = [classInformation objectForKey: className]; NSMutableArray *extraActions = [info objectForKey: @"ExtraActions"]; NSArray *allActions = [self allActionsForClassNamed: className]; + NSString *anAction = [action copy]; if ([allActions containsObject: anAction]) { @@ -240,11 +246,12 @@ } } -- (void) addOutlet: (NSString *)anOutlet forClassNamed: (NSString *)className +- (void) addOutlet: (NSString *)outlet forClassNamed: (NSString *)className { NSMutableDictionary *info = [classInformation objectForKey: className]; NSMutableArray *extraOutlets = [info objectForKey: @"ExtraOutlets"]; NSArray *allOutlets = [self allOutletsForClassNamed: className]; + NSString *anOutlet = [outlet copy]; if ([allOutlets containsObject: anOutlet]) { @@ -263,13 +270,14 @@ } - (void) replaceAction: (NSString *)oldAction - withAction: (NSString *)newAction + withAction: (NSString *)new_action forClassNamed: className { NSMutableDictionary *info = [classInformation objectForKey: className]; NSMutableArray *extraActions = [info objectForKey: @"ExtraActions"]; NSMutableArray *actions = [info objectForKey: @"Actions"]; NSMutableArray *allActions = [info objectForKey: @"AllActions"]; + NSString *newAction = [new_action copy]; if ([allActions containsObject: newAction] || [extraActions containsObject: newAction]) @@ -302,13 +310,14 @@ } - (void) replaceOutlet: (NSString *)oldOutlet - withOutlet: (NSString *)newOutlet + withOutlet: (NSString *)new_outlet forClassNamed: className { NSMutableDictionary *info = [classInformation objectForKey: className]; NSMutableArray *extraOutlets = [info objectForKey: @"ExtraOutlets"]; NSMutableArray *outlets = [info objectForKey: @"Outlets"]; NSMutableArray *allOutlets = [info objectForKey: @"AllOutlets"]; + NSString *newOutlet = [new_outlet copy]; if ([allOutlets containsObject: newOutlet] || [extraOutlets containsObject: newOutlet]) @@ -457,6 +466,11 @@ return nil; } +- (NSArray*) allCustomClassNames +{ + return [customClassMap allKeys]; +} + - (NSArray*) allClassNames { NSArray *array = [NSArray arrayWithObject: @"NSObject"]; @@ -898,8 +912,24 @@ { if ([customClasses containsObject: className]) { + NSEnumerator *en = [customClassMap keyEnumerator]; + id object = nil; + [self _touch]; [customClasses removeObject: className]; + + while((object = [en nextObject]) != nil) + { + id customClassName = [customClassMap objectForKey: object]; + if(customClassName != nil) + { + if([className isEqualToString: customClassName]) + { + NSDebugLog(@"Deleting object -> customClass association %@ -> %@",object,customClassName); + [customClassMap removeObjectForKey: object]; + } + } + } } [classInformation removeObjectForKey: className]; @@ -909,10 +939,13 @@ object: self]; } -- (BOOL) renameClassNamed: (NSString*)oldName newName: (NSString*)name +- (BOOL) renameClassNamed: (NSString*)oldName newName: (NSString*)newName { id classInfo = [classInformation objectForKey: oldName]; NSNotificationCenter *nc = [NSNotificationCenter defaultCenter]; + NSString *name = [newName copy]; + + NSDebugLog(@"Old name %@, new name %@",oldName,name); if (classInfo != nil && [classInformation objectForKey: name] == nil) { @@ -926,8 +959,31 @@ if ((index = [customClasses indexOfObject: oldName]) != NSNotFound) { + NSEnumerator *en = [customClassMap keyEnumerator]; + id object = nil; + + NSDebugLog(@"replacing object with %@, %@",name, customClasses); [customClasses replaceObjectAtIndex: index withObject: name]; + NSDebugLog(@"replaced object with %@, %@",name, customClasses); + + // show the class map before... + NSDebugLog(@"customClassMap = %@",customClassMap); + while((object = [en nextObject]) != nil) + { + id customClassName = [customClassMap objectForKey: object]; + if(customClassName != nil) + { + if([oldName isEqualToString: customClassName]) + { + NSDebugLog(@"Replacing object -> customClass association %@ -> %@",object,customClassName); + [customClassMap setObject: name forKey: object]; + } + } + } + NSDebugLog(@"New customClassMap = %@",customClassMap); // and after } + else + NSLog(@"customClass not found %@",oldName); [nc postNotificationName: IBClassNameChangedNotification object: self]; return YES; @@ -1013,6 +1069,7 @@ */ RELEASE(classInformation); classInformation = [NSMutableDictionary new]; + RETAIN(classInformation); enumerator = [dict keyEnumerator]; while ((key = [enumerator nextObject]) != nil) { @@ -1305,7 +1362,8 @@ NSString *name = [[(id)NSApp activeDocument] nameForObject: object]; NSString *result = [self customClassForName: name]; // NSString *result = [customClassMap objectForKey: name]; - NSDebugLog(@"in customClassForObject: object = %@, name = %@, result = %@, customClassMap = %@",object, name, result, customClassMap); + NSDebugLog(@"in customClassForObject: object = %@, name = %@, result = %@, customClassMap = %@", + object, name, result, customClassMap); return result; } @@ -1330,7 +1388,7 @@ { // copy the dictionary.. NSDebugLog(@"dictionary = %@",dict); - ASSIGN(customClassMap, dict); + ASSIGN(customClassMap, [dict mutableCopy]); RETAIN(customClassMap); } @@ -1342,6 +1400,8 @@ - (NSString *) nonCustomSuperClassOf: (NSString *)className { NSString *result = className; + + NSAssert([self isCustomClass: className],NSInvalidArgumentException); // iterate up the chain until a non-custom superclass is found... while ([self isCustomClass: result]) diff --git a/GormCustomClassInspector.m b/GormCustomClassInspector.m index 94e783b1..d67953d5 100644 --- a/GormCustomClassInspector.m +++ b/GormCustomClassInspector.m @@ -114,15 +114,20 @@ NSDebugLog(@"selected = %@, class = %@",stringValue,nameForObject); /* add or remove the mapping as necessary. */ - if (![stringValue isEqualToString: classForObject]) + if(nameForObject != nil) { - [_classManager setCustomClass: stringValue - forObject: nameForObject]; + if (![stringValue isEqualToString: classForObject]) + { + [_classManager setCustomClass: stringValue + forObject: nameForObject]; + } + else + { + [_classManager removeCustomClassForObject: nameForObject]; + } } else - { - [_classManager removeCustomClassForObject: nameForObject]; - } + NSLog(@"Name for object returned as nil"); } // Browser delegate diff --git a/GormDocument.m b/GormDocument.m index bb75121c..205e1faf 100644 --- a/GormDocument.m +++ b/GormDocument.m @@ -1896,6 +1896,8 @@ static NSImage *classesImage = nil; [[c nameTable] setObject: cc forKey: GSCustomClassMap]; } [classManager setCustomClassMap: cc]; + NSLog(@"cc = %@", cc); + NSLog(@"customClasses = %@", [classManager customClassMap]); // convert from old file format... if (isDir == NO) @@ -2568,19 +2570,22 @@ static NSImage *classesImage = nil; - (void) _replaceObjectsWithTemplates: (NSArchiver *)archiver { GormClassManager *cm = [self classManager]; - NSDictionary *classMap = [cm customClassMap]; - NSEnumerator *en = [classMap keyEnumerator]; + NSEnumerator *en = [[cm customClassMap] keyEnumerator]; id key = nil; - NSLog(@"Called"); + NSDebugLog(@"Called "); while((key = [en nextObject]) != nil) { - id customClass = [classMap objectForKey: key]; + id customClass = [cm customClassForName: key]; id object = [self objectForName: key]; + + // put code here to repair old .gorm files if necessary. + + NSDebugLog(@"customClass = %@",customClass); NSString *superClass = [cm nonCustomSuperClassOf: customClass]; id template = [GSTemplateFactory templateForObject: object withClassName: customClass withSuperClassName: superClass]; - NSLog(@"object = %@, key = %@, className = %@", object, key, customClass); + NSDebugLog(@"object = %@, key = %@, className = %@", object, key, customClass); [archiver replaceObject: object withObject: template]; } } @@ -2640,7 +2645,10 @@ static NSImage *classesImage = nil; [self _replaceObjectsWithTemplates: archiver]; [archiver encodeRootObject: self]; - NSDebugLog(@"nameTable = %@",nameTable); + NSLog(@"nameTable = %@",nameTable); + + NSLog(@"customClasses = %@", [classManager customClassMap]); + fileExists = [mgr fileExistsAtPath: documentPath isDirectory: &isDir]; if (fileExists) {