Gorm now correctly pulls in objects and assigns them names.

This commit is contained in:
Gregory John Casamento 2021-04-28 19:03:27 -04:00
parent 3c81d4b83a
commit feb5608836
4 changed files with 162 additions and 80 deletions

View file

@ -1798,17 +1798,17 @@
// header file comments...
[headerFile appendString: @"/* All rights reserved */\n\n"];
[sourceFile appendString: @"/* All rights reserved */\n\n"];
[headerFile appendString: @"#include <AppKit/AppKit.h>\n\n"];
[sourceFile appendString: @"#include <AppKit/AppKit.h>\n"];
[headerFile appendString: @"#import <AppKit/AppKit.h>\n\n"];
[sourceFile appendString: @"#import <AppKit/AppKit.h>\n"];
if ([[headerPath stringByDeletingLastPathComponent]
isEqualToString: [sourcePath stringByDeletingLastPathComponent]])
{
[sourceFile appendFormat: @"#include \"%@\"\n\n",
[sourceFile appendFormat: @"#import \"%@\"\n\n",
[headerPath lastPathComponent]];
}
else
{
[sourceFile appendFormat: @"#include \"%@\"\n\n",
[sourceFile appendFormat: @"#import \"%@\"\n\n",
headerPath];
}
[headerFile appendFormat: @"@interface %@ : %@\n{\n", className,
@ -1818,7 +1818,7 @@
n = [outlets count];
for (i = 0; i < n; i++)
{
[headerFile appendFormat: @" id %@;\n", [outlets objectAtIndex: i]];
[headerFile appendFormat: @" IBOutlet id %@;\n", [outlets objectAtIndex: i]];
}
[headerFile appendFormat: @"}\n"];
@ -1826,17 +1826,16 @@
for (i = 0; i < n; i++)
{
actionName = [actions objectAtIndex: i];
[headerFile appendFormat: @"- (void) %@ (id)sender;\n", actionName];
[headerFile appendFormat: @"- (IBAction) %@ (id)sender;\n", actionName];
[sourceFile appendFormat:
@"\n"
@"- (void) %@ (id)sender\n"
@"- (IBAction) %@ (id)sender\n"
@"{\n"
@" /* insert your code here */\n"
@"}\n"
@"\n"
, [actions objectAtIndex: i]];
}
[headerFile appendFormat: @"@end\n"];
[headerFile appendFormat: @"\n@end\n"];
[sourceFile appendFormat: @"@end\n"];
headerData = [headerFile dataUsingEncoding:

View file

@ -534,9 +534,10 @@ static NSImage *fileImage = nil;
}
/**
* Attach anObject to the document with aParent.
* Attach anObject to the document with aParent specifying the name. To allow
* Gorm to generate the name pass in nil for aName parameter
*/
- (void) attachObject: (id)anObject toParent: (id)aParent
- (void) attachObject: (id)anObject toParent: (id)aParent withName: (NSString *)aName
{
NSArray *old;
BOOL newObject = NO;
@ -581,7 +582,7 @@ static NSImage *fileImage = nil;
if ([self nameForObject: anObject] == nil)
{
newObject = YES;
[self setName: nil forObject: anObject];
[self setName: aName forObject: anObject];
}
/*
@ -668,7 +669,7 @@ static NSImage *fileImage = nil;
// will become the main menu.
if([self objectForName: @"NSMenu"] == nil)
{
[self setName: @"NSMenu" forObject: menu];
[self setName: @"NSMenu" forObject: menu];
[objectsView addObject: menu];
[topLevelObjects addObject: menu];
isMainMenu = YES;
@ -855,6 +856,16 @@ static NSImage *fileImage = nil;
}
}
/**
* Attach an object to parent object in document letting Gorm generate the name
*/
- (void) attachObject: (id)object toParent: (id)parent
{
[self attachObject: object
toParent: parent
withName: nil];
}
/**
* Attach all objects in anArray to the document with aParent.
*/

View file

@ -47,6 +47,12 @@ IB_EXTERN NSString *IBWillCloseDocumentNotification;
*/
- (NSArray*) allConnectors;
/**
* Attach object to document with a specified name. Pass nil to
* aName to have Gorm assign a name to it. (GS extension)
*/
- (void) attachObject: (id)anObject toParent: (id)aParent withName: (NSString *)aName;
/**
* Attaches an object to the document and makes the association
* with the parent.

View file

@ -34,6 +34,14 @@
*/
@class GormNSWindow;
/*
* This allows us to retrieve the customClasses from the XIB unarchiver.
*/
@interface NSKeyedUnarchiver (Private)
- (NSArray *) customClasses;
- (NSDictionary *) decoded;
@end
/*
* Xib loader...
*/
@ -52,13 +60,13 @@
GormPalettesManager *palettesManager = [(id<Gorm>)NSApp palettesManager];
NSDictionary *substituteClasses = [palettesManager substituteClasses];
NSString *subClassName = nil;
GormClassManager *classManager = [document classManager];
if ([super loadFileWrapper: wrapper
withDocument: doc] &&
[wrapper isDirectory] == NO)
{
NSData *data = [wrapper regularFileContents];
GormClassManager *classManager = [document classManager];
id docFilesOwner;
// turn off custom classes...
@ -121,7 +129,9 @@
IBConnectionRecord *cr = nil;
NSArray *rootObjects = nil;
id firstResponder = nil;
// IBObjectRecord *or = nil;
// NSLog(@"%@", [container customClassNames]);
// NSLog(@"%@", container);
rootObjects = [u decodeObjectForKey: @"IBDocument.RootObjects"];
nibFilesOwner = [rootObjects objectAtIndex: 0];
@ -137,10 +147,9 @@
}
//
// add objects...
// add root objects...
//
en = [rootObjects objectEnumerator];
// [container objectRecordEnumerator];
id obj = nil;
while ((obj = [en nextObject]) != nil)
{
@ -154,7 +163,7 @@
}
//
// If it's NSApplication (most likely the File's Owner
// If it's NSApplication (most likely the File's Owner)
// skip it...
//
if ([obj isKindOfClass: [GormObjectProxy class]])
@ -213,28 +222,57 @@
}
}
/* FIXME: Should use IBDocument.Classes
//
// Add custom classes...
//
classesTable = [container classes];
classKeys = NSAllMapTableKeys(classesTable);
en = [classKeys objectEnumerator];
while((o = [en nextObject]) != nil)
{
NSString *name = [document nameForObject: o];
NSString *customClass = NSMapGet(classesTable, o);
if(name != nil && customClass != nil)
{
[classManager setCustomClass: customClass forName: name];
}
else
{
NSLog(@"Name %@ or class %@ for object %@ is nil.", name, customClass, o);
}
}
*/
NSArray *customClasses = [u customClasses];
NSEnumerator *en = [customClasses objectEnumerator];
NSDictionary *customClassDict = nil;
NSDictionary *decoded = [u decoded];
NSDebugLog(@"customClasses = %@", customClasses);
while ((customClassDict = [en nextObject]) != nil)
{
NSString *theId = [customClassDict objectForKey: @"id"];
NSString *customClassName = [customClassDict objectForKey: @"customClassName"];
NSString *className = [customClassDict objectForKey: @"parentClassName"];
id realObject = [decoded objectForKey: theId];
NSString *theName = nil;
if ([document containsObject: realObject])
{
theName = [document nameForObject: realObject];
NSLog(@"Found name = %@ for realObject = %@", theName, realObject);
}
else
{
NSLog(@"realObject = %@ has no name in document", realObject);
continue;
}
if (![className isEqualToString: @"NSCustomObject"] &&
![className isEqualToString: @"NSCustomObject5"] &&
![className isEqualToString: @"NSApplication"] &&
![className isEqualToString: @"FirstResponder"] &&
![className isEqualToString: @"NSWindowTemplate"])
{
// Add the class if it is not already known to gorm
if ([classManager isKnownClass: customClassName] == NO)
{
NSLog(@"Adding customClassName = %@ with parent className = %@", customClassName, className);
[classManager addClassNamed: customClassName
withSuperClassNamed: className
withActions: nil
withOutlets: nil
isCustom: YES];
}
NSLog(@"Assigning %@ as customClass = %@", theName, customClassName);
[classManager setCustomClass: customClassName
forName: theName];
}
}
//
// add connections...
//
@ -242,48 +280,76 @@
while ((cr = [en nextObject]) != nil)
{
IBConnection *conn = [cr connection];
NSNibConnector *o = [conn nibConnector];
id dest = [o destination];
id src = [o source];
if (dest == nibFilesOwner)
{
[o setDestination: [document filesOwner]];
}
else if (dest == firstResponder)
{
[o setDestination: [document firstResponder]];
}
if (src == nibFilesOwner)
{
[o setSource: [document filesOwner]];
}
else if (src == firstResponder)
{
[o setSource: [document firstResponder]];
}
// check src/dest for window template...
if ([src isKindOfClass: [NSWindowTemplate class]])
{
id win = [src realObject];
[o setSource: win];
}
if ([dest isKindOfClass: [NSWindowTemplate class]])
{
id win = [dest realObject];
[o setDestination: win];
}
// skip any help connectors...
if ([o isKindOfClass: [NSIBHelpConnector class]])
{
continue;
}
[document addConnector: o];
}
if ([conn respondsToSelector: @selector(nibConnector)])
{
NSNibConnector *o = [conn nibConnector];
if (o != nil)
{
id dest = [o destination];
id src = [o source];
if([o isKindOfClass: [NSNibControlConnector class]])
{
NSString *tag = [o label];
NSRange colonRange = [tag rangeOfString: @":"];
NSUInteger location = colonRange.location;
// NSString *cc = [classManager customClassForObject: [o target]];
if(location == NSNotFound)
{
NSString *newTag = [NSString stringWithFormat: @"%@:",tag];
[o setLabel: (id)newTag];
}
[classManager addAction: [o label] forObject: [o destination]];
}
if ([o isKindOfClass: [NSNibOutletConnector class]])
{
}
if (dest == nibFilesOwner)
{
[o setDestination: [document filesOwner]];
}
else if (dest == firstResponder)
{
[o setDestination: [document firstResponder]];
}
if (src == nibFilesOwner)
{
[o setSource: [document filesOwner]];
}
else if (src == firstResponder)
{
[o setSource: [document firstResponder]];
}
// check src/dest for window template...
if ([src isKindOfClass: [NSWindowTemplate class]])
{
id win = [src realObject];
[o setSource: win];
}
if ([dest isKindOfClass: [NSWindowTemplate class]])
{
id win = [dest realObject];
[o setDestination: win];
}
// skip any help connectors...
if ([o isKindOfClass: [NSIBHelpConnector class]])
{
continue;
}
[document addConnector: o];
}
}
}
// turn on custom classes.
[NSClassSwapper setIsInInterfaceBuilder: NO];