Fix issue with NSNibControlConnector handling in XIB loading routine.

This commit is contained in:
Gregory John Casamento 2021-05-06 23:15:48 -04:00
parent d2062aeff0
commit a7fb78ecd0

View file

@ -1,9 +1,9 @@
/* GormNibWrapperLoader /* GormXibWrapperLoader
* *
* Copyright (C) 2010 Free Software Foundation, Inc. * Copyright (C) 2010, 2021 Free Software Foundation, Inc.
* *
* Author: Gregory John Casamento <greg_casamento@yahoo.com> * Author: Gregory John Casamento <greg_casamento@yahoo.com>
* Date: 2010 * Date: 2010, 2021
* *
* This file is part of GNUstep. * This file is part of GNUstep.
* *
@ -51,6 +51,27 @@
return @"GSXibFileType"; return @"GSXibFileType";
} }
- (id) _replaceProxyInstanceWithRealObject: (id)obj
{
if ([obj isKindOfClass: [GormObjectProxy class]])
{
if ([[obj className] isEqualToString: @"NSApplication"])
{
return [document filesOwner];
}
if ([[obj className] isEqualToString: @"FirstResponder"])
{
return [document firstResponder];
}
}
else if (obj == nil)
{
return [document firstResponder];
}
return obj;
}
- (BOOL) loadFileWrapper: (NSFileWrapper *)wrapper withDocument: (GormDocument *) doc - (BOOL) loadFileWrapper: (NSFileWrapper *)wrapper withDocument: (GormDocument *) doc
{ {
BOOL result = NO; BOOL result = NO;
@ -128,14 +149,11 @@
{ {
IBConnectionRecord *cr = nil; IBConnectionRecord *cr = nil;
NSArray *rootObjects = nil; NSArray *rootObjects = nil;
id firstResponder = nil; id xibFirstResponder = nil;
// NSLog(@"%@", [container customClassNames]);
// NSLog(@"%@", container);
rootObjects = [u decodeObjectForKey: @"IBDocument.RootObjects"]; rootObjects = [u decodeObjectForKey: @"IBDocument.RootObjects"];
nibFilesOwner = [rootObjects objectAtIndex: 0]; nibFilesOwner = [rootObjects objectAtIndex: 0];
firstResponder = [rootObjects objectAtIndex: 1]; xibFirstResponder = [rootObjects objectAtIndex: 1];
docFilesOwner = [doc filesOwner]; docFilesOwner = [doc filesOwner];
// //
@ -157,7 +175,7 @@
NSString *objName = nil; NSString *objName = nil;
// skip the file's owner, it is handled above... // skip the file's owner, it is handled above...
if ((obj == nibFilesOwner) || (obj == firstResponder)) if ((obj == nibFilesOwner) || (obj == xibFirstResponder))
{ {
continue; continue;
} }
@ -195,7 +213,7 @@
// Add to the document... // Add to the document...
[doc attachObject: o [doc attachObject: o
toParent: nil]; toParent: nil];
// record the custom class... // record the custom class...
if ([classManager isCustomClass: className]) if ([classManager isCustomClass: className])
@ -208,7 +226,7 @@
[obj isKindOfClass: [GormWindowTemplate class]] == NO) [obj isKindOfClass: [GormWindowTemplate class]] == NO)
{ {
[doc attachObject: obj [doc attachObject: obj
toParent: nil]; toParent: nil];
} }
if (customClassName != nil) if (customClassName != nil)
@ -234,26 +252,22 @@
while ((customClassDict = [en nextObject]) != nil) while ((customClassDict = [en nextObject]) != nil)
{ {
NSString *theId = [customClassDict objectForKey: @"id"]; NSString *theId = [customClassDict objectForKey: @"id"];
if ([theId isEqualToString: @"-1"] ||
[theId isEqualToString: @"-2"] ||
[theId isEqualToString: @"-3"])
{
continue;
}
NSString *customClassName = [customClassDict objectForKey: @"customClassName"]; NSString *customClassName = [customClassDict objectForKey: @"customClassName"];
NSString *parentClassName = [customClassDict objectForKey: @"parentClassName"]; NSString *parentClassName = [customClassDict objectForKey: @"parentClassName"];
id realObject = [decoded objectForKey: theId]; id realObject = [decoded objectForKey: theId];
NSString *theName = nil; NSString *theName = nil;
realObject = [self _replaceProxyInstanceWithRealObject: realObject];
NSDebugLog(@"realObject = %@", realObject);
if ([doc containsObject: realObject]) if ([doc containsObject: realObject])
{ {
theName = [doc nameForObject: realObject]; theName = [doc nameForObject: realObject];
NSLog(@"Found name = %@ for realObject = %@", theName, realObject); NSDebugLog(@"Found name = %@ for realObject = %@", theName, realObject);
} }
else else
{ {
NSLog(@"realObject = %@ has no name in document", realObject); NSDebugLog(@"realObject = %@ has no name in document", realObject);
continue; continue;
} }
@ -262,14 +276,15 @@
parentClassName = @"NSObject"; parentClassName = @"NSObject";
} }
NSLog(@"Adding customClassName = %@ with parent className = %@", customClassName, parentClassName); NSDebugLog(@"Adding customClassName = %@ with parent className = %@", customClassName,
parentClassName);
[classManager addClassNamed: customClassName [classManager addClassNamed: customClassName
withSuperClassNamed: parentClassName withSuperClassNamed: parentClassName
withActions: nil withActions: nil
withOutlets: nil withOutlets: nil
isCustom: YES]; isCustom: YES];
NSLog(@"Assigning %@ as customClass = %@", theName, customClassName); NSDebugLog(@"Assigning %@ as customClass = %@", theName, customClassName);
[classManager setCustomClass: customClassName [classManager setCustomClass: customClassName
forName: theName]; forName: theName];
} }
@ -291,19 +306,16 @@
id dest = [o destination]; id dest = [o destination];
id src = [o source]; id src = [o source];
if ([src isKindOfClass: [GormObjectProxy class]]) // Replace files owner with the document files owner for loading...
{ dest = [self _replaceProxyInstanceWithRealObject: dest];
NSString *className = [src className]; src = [self _replaceProxyInstanceWithRealObject: src];
if ([className isEqualToString: @"NSApplication"])
{
src = nibFilesOwner;
[o setSource: src];
}
}
NSLog(@"connector = %@", o); // Reset them...
[o setDestination: dest];
[o setSource: src];
NSDebugLog(@"connector = %@", o);
// NSString *dest_name = [doc nameForObject: dest];
if([o isKindOfClass: [NSNibControlConnector class]]) if([o isKindOfClass: [NSNibControlConnector class]])
{ {
NSString *tag = [o label]; NSString *tag = [o label];
@ -316,34 +328,19 @@
[o setLabel: (id)newTag]; [o setLabel: (id)newTag];
} }
// For control connectors these roles are reversed...
[o setSource: dest];
[o setDestination: src];
[classManager addAction: [o label] [classManager addAction: [o label]
forObject: src]; forObject: src];
} }
else if ([o isKindOfClass: [NSNibOutletConnector class]])
if ([o isKindOfClass: [NSNibOutletConnector class]])
{ {
[classManager addOutlet: [o label] [classManager addOutlet: [o label]
forObject: src]; forObject: src];
} }
if (dest == nibFilesOwner)
{
[o setDestination: [doc filesOwner]];
}
else if (dest == nil) // == firstResponder)
{
[o setDestination: [doc firstResponder]];
}
if (src == nibFilesOwner)
{
[o setSource: [doc filesOwner]];
}
else if (src == firstResponder)
{
[o setSource: [doc firstResponder]];
}
// check src/dest for window template... // check src/dest for window template...
if ([src isKindOfClass: [NSWindowTemplate class]]) if ([src isKindOfClass: [NSWindowTemplate class]])
{ {
@ -423,7 +420,6 @@
[obj setTarget: nil]; [obj setTarget: nil];
[obj setAction: NULL]; [obj setAction: NULL];
} }
return obj; return obj;
} }
@end @end