mirror of
https://github.com/gnustep/apps-gorm.git
synced 2025-04-23 06:20:47 +00:00
Initial fix for gorm<->xib xib<->gorm conversion...
This commit is contained in:
parent
f5d7f25044
commit
4c2abb1303
5 changed files with 143 additions and 95 deletions
|
@ -859,73 +859,14 @@ NSImage *browserImage = nil;
|
|||
*/
|
||||
- (id) instantiateClass: (id)sender
|
||||
{
|
||||
NSString *object = [self selectedClassName];
|
||||
GSNibItem *item = nil;
|
||||
NSString *className = [self selectedClassName];
|
||||
NSString *theName = nil;
|
||||
|
||||
if([object isEqualToString: @"FirstResponder"])
|
||||
theName = [document instantiateClassNamed: className];
|
||||
if (theName == nil)
|
||||
{
|
||||
return nil;
|
||||
}
|
||||
|
||||
if([classManager canInstantiateClassNamed: object] == NO)
|
||||
{
|
||||
return nil;
|
||||
}
|
||||
|
||||
if([classManager isSuperclass: @"NSView" linkedToClass: object] ||
|
||||
[object isEqual: @"NSView"])
|
||||
{
|
||||
Class cls;
|
||||
NSString *className = object;
|
||||
BOOL isCustom = [classManager isCustomClass: object];
|
||||
id instance;
|
||||
|
||||
if(isCustom)
|
||||
{
|
||||
className = [classManager nonCustomSuperClassOf: object];
|
||||
}
|
||||
|
||||
// instantiate the object or it's substitute...
|
||||
cls = NSClassFromString(className);
|
||||
if([cls respondsToSelector: @selector(allocSubstitute)])
|
||||
{
|
||||
instance = [cls allocSubstitute];
|
||||
}
|
||||
else
|
||||
{
|
||||
instance = [cls alloc];
|
||||
}
|
||||
|
||||
// give it some initial dimensions...
|
||||
if([instance respondsToSelector: @selector(initWithFrame:)])
|
||||
{
|
||||
instance = [instance initWithFrame: NSMakeRect(10,10,380,280)];
|
||||
}
|
||||
else
|
||||
{
|
||||
instance = [instance init];
|
||||
}
|
||||
|
||||
// add it to the top level objects...
|
||||
[document attachObject: instance toParent: nil];
|
||||
|
||||
// we want to record if it's custom or not and act appropriately...
|
||||
if(isCustom)
|
||||
{
|
||||
NSString *name = [document nameForObject: instance];
|
||||
[classManager setCustomClass: object
|
||||
forName: name];
|
||||
}
|
||||
|
||||
[document changeToViewWithTag: 0];
|
||||
NSLog(@"Instantiate NSView subclass %@",object);
|
||||
}
|
||||
else
|
||||
{
|
||||
item = [[GormObjectProxy alloc] initWithClassName: object];
|
||||
[document attachObject: item toParent: nil];
|
||||
[document changeToViewWithTag: 0];
|
||||
}
|
||||
|
||||
return self;
|
||||
}
|
||||
|
|
|
@ -238,6 +238,12 @@
|
|||
*/
|
||||
- (id) instantiateClass: (id)sender;
|
||||
|
||||
/**
|
||||
* Instantiate the class specified by the parameter className and
|
||||
* returns the reference name within the document
|
||||
*/
|
||||
- (NSString *) instantiateClassNamed: (NSString *)className;
|
||||
|
||||
/**
|
||||
* Generate the class files for the selected class
|
||||
*/
|
||||
|
|
|
@ -1488,6 +1488,84 @@ static NSImage *fileImage = nil;
|
|||
return [classesView instantiateClass: sender];
|
||||
}
|
||||
|
||||
/**
|
||||
* Instantiate the class specified by the parameter className
|
||||
*/
|
||||
- (NSString *) instantiateClassNamed: (NSString *)className
|
||||
{
|
||||
NSString *theName = nil;
|
||||
GSNibItem *item = nil;
|
||||
|
||||
if([className isEqualToString: @"FirstResponder"])
|
||||
{
|
||||
return nil;
|
||||
}
|
||||
|
||||
if([classManager canInstantiateClassNamed: className] == NO)
|
||||
{
|
||||
return nil;
|
||||
}
|
||||
|
||||
if([classManager isSuperclass: @"NSView" linkedToClass: className] ||
|
||||
[className isEqualToString: @"NSView"])
|
||||
{
|
||||
Class cls;
|
||||
BOOL isCustom = [classManager isCustomClass: className];
|
||||
id instance;
|
||||
|
||||
// Replace with NON custom class, since we don't have the compiled version
|
||||
// of the custom class available to us in Gorm.
|
||||
if(isCustom)
|
||||
{
|
||||
className = [classManager nonCustomSuperClassOf: className];
|
||||
}
|
||||
|
||||
// instantiate the object or it's substitute...
|
||||
cls = NSClassFromString(className);
|
||||
if([cls respondsToSelector: @selector(allocSubstitute)])
|
||||
{
|
||||
instance = [cls allocSubstitute];
|
||||
}
|
||||
else
|
||||
{
|
||||
instance = [cls alloc];
|
||||
}
|
||||
|
||||
// give it some initial dimensions...
|
||||
if([instance respondsToSelector: @selector(initWithFrame:)])
|
||||
{
|
||||
instance = [instance initWithFrame: NSMakeRect(10,10,380,280)];
|
||||
}
|
||||
else
|
||||
{
|
||||
instance = [instance init];
|
||||
}
|
||||
|
||||
// add it to the top level objects...
|
||||
[self attachObject: instance toParent: nil];
|
||||
|
||||
// we want to record if it's custom or not and act appropriately...
|
||||
if(isCustom)
|
||||
{
|
||||
theName = [self nameForObject: instance];
|
||||
[classManager setCustomClass: className
|
||||
forName: theName];
|
||||
}
|
||||
|
||||
[self changeToViewWithTag: 0];
|
||||
NSLog(@"Instantiate NSView subclass %@",className);
|
||||
}
|
||||
else
|
||||
{
|
||||
item = [[GormObjectProxy alloc] initWithClassName: className];
|
||||
[self attachObject: item toParent: nil];
|
||||
[self changeToViewWithTag: 0];
|
||||
theName = [self nameForObject: item];
|
||||
}
|
||||
|
||||
return theName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove a class from the classes view
|
||||
*/
|
||||
|
|
|
@ -76,19 +76,10 @@ static BOOL _isInInterfaceBuilder = NO;
|
|||
@end
|
||||
|
||||
@interface NSObject (GormPrivate)
|
||||
// + (void) poseAsClass: (Class)aClassObject;
|
||||
+ (BOOL) canSubstituteForClass: (Class)origClass;
|
||||
@end
|
||||
|
||||
@implementation NSObject (GormPrivate)
|
||||
/*
|
||||
+ (void) poseAsClass: (Class)aClassObject
|
||||
{
|
||||
// disable poseAs: while in Gorm.
|
||||
class_pose_as(self, aClassObject);
|
||||
NSLog(@"WARNING: poseAs: called in Gorm.");
|
||||
}
|
||||
*/
|
||||
|
||||
+ (BOOL) canSubstituteForClass: (Class)origClass
|
||||
{
|
||||
|
@ -113,6 +104,7 @@ static BOOL _isInInterfaceBuilder = NO;
|
|||
|
||||
return NO;
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@implementation GormObjectProxy
|
||||
|
|
|
@ -33,7 +33,7 @@
|
|||
/*
|
||||
* Forward declarations for classes
|
||||
*/
|
||||
@class GormNSWindow;
|
||||
@class GormNSWindow, GormNSMenu;
|
||||
|
||||
/*
|
||||
* This allows us to retrieve the customClasses from the XIB unarchiver.
|
||||
|
@ -56,10 +56,11 @@
|
|||
|
||||
- (id) _replaceProxyInstanceWithRealObject: (id)obj
|
||||
classManager: (GormClassManager *)classManager
|
||||
withID: (NSString *)theId
|
||||
{
|
||||
NSString *className = [obj className];
|
||||
|
||||
if ([obj isKindOfClass: [GormObjectProxy class]])
|
||||
if ([obj isKindOfClass: [NSCustomObject class]])
|
||||
{
|
||||
if ([className isEqualToString: @"NSApplication"])
|
||||
{
|
||||
|
@ -82,7 +83,7 @@
|
|||
else if ([obj respondsToSelector: @selector(className)])
|
||||
{
|
||||
NSString *cn = [obj className];
|
||||
NSLog(@"className = %@", cn);
|
||||
NSDebugLog(@"className = %@", cn);
|
||||
}
|
||||
else if (obj == nil)
|
||||
{
|
||||
|
@ -134,16 +135,20 @@
|
|||
//
|
||||
// Special internal classes
|
||||
//
|
||||
/*
|
||||
[u setClass: [GormObjectProxy class]
|
||||
forClassName: @"NSCustomObject"];
|
||||
[u setClass: [GormObjectProxy class]
|
||||
forClassName: @"NSCustomObject5"];
|
||||
forClassName: @"NSCustomObject5"];
|
||||
*/
|
||||
[u setClass: [GormCustomView class]
|
||||
forClassName: @"NSCustomView"];
|
||||
[u setClass: [GormWindowTemplate class]
|
||||
forClassName: @"NSWindowTemplate"];
|
||||
[u setClass: [GormNSWindow class]
|
||||
forClassName: @"NSWindow"];
|
||||
[u setClass: [GormNSMenu class]
|
||||
forClassName: @"NSMenu"];
|
||||
[u setClass: [IBUserDefinedRuntimeAttribute class]
|
||||
forClassName: @"IBUserDefinedRuntimeAttribute5"];
|
||||
|
||||
|
@ -183,7 +188,7 @@
|
|||
//
|
||||
// set the current class on the File's owner...
|
||||
//
|
||||
if ([_nibFilesOwner isKindOfClass: [GormObjectProxy class]])
|
||||
if ([_nibFilesOwner isKindOfClass: [NSCustomObject class]])
|
||||
{
|
||||
[docFilesOwner setClassName: [_nibFilesOwner className]];
|
||||
}
|
||||
|
@ -210,7 +215,7 @@
|
|||
// If it's NSApplication (most likely the File's Owner)
|
||||
// skip it...
|
||||
//
|
||||
if ([obj isKindOfClass: [GormObjectProxy class]])
|
||||
if ([obj isKindOfClass: [NSCustomObject class]])
|
||||
{
|
||||
if ([[obj className] isEqualToString: @"NSApplication"])
|
||||
{
|
||||
|
@ -233,14 +238,15 @@
|
|||
|
||||
// make the object deferred/visible...
|
||||
o = [obj nibInstantiate];
|
||||
|
||||
NSDebugLog(@"Decoding window as %@", o);
|
||||
|
||||
[doc setObject: o isDeferred: isDeferred];
|
||||
[doc setObject: o isVisibleAtLaunch: isVisible];
|
||||
|
||||
// Add to the document...
|
||||
// Add to the document...
|
||||
[doc attachObject: o
|
||||
toParent: nil];
|
||||
|
||||
toParent: nil];
|
||||
|
||||
// record the custom class...
|
||||
if ([classManager isCustomClass: className])
|
||||
{
|
||||
|
@ -254,17 +260,15 @@
|
|||
NSLog(@"obj = %@",obj);
|
||||
if ([obj respondsToSelector: @selector(className)])
|
||||
{
|
||||
NSString *className = nil;
|
||||
|
||||
className = [obj className];
|
||||
if ([className isEqualToString: @"NSFontManager"])
|
||||
if ([obj isKindOfClass: [NSCustomObject class]])
|
||||
{
|
||||
NSLog(@"Skipping NSCustomObject %@ -- adding custom class using GormDocument methods...", obj);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
[doc attachObject: obj
|
||||
toParent: nil];
|
||||
toParent: nil];
|
||||
}
|
||||
|
||||
if (customClassName != nil)
|
||||
|
@ -295,8 +299,24 @@
|
|||
id realObject = [decoded objectForKey: theId];
|
||||
NSString *theName = nil;
|
||||
|
||||
// Set the file's owner correctly...
|
||||
if ([theId isEqualToString: @"-2"]) // The File's Owner node...
|
||||
{
|
||||
[[doc filesOwner] setClassName: customClassName];
|
||||
continue;
|
||||
}
|
||||
|
||||
// these are preset values
|
||||
if ([theId isEqualToString: @"-1"]
|
||||
|| [theId isEqualToString: @"-3"]
|
||||
|| [customClassName isEqualToString: @"NSFontManager"])
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
realObject = [self _replaceProxyInstanceWithRealObject: realObject
|
||||
classManager: classManager];
|
||||
classManager: classManager
|
||||
withID: theId];
|
||||
NSDebugLog(@"realObject = %@", realObject);
|
||||
|
||||
if ([doc containsObject: realObject])
|
||||
|
@ -307,7 +327,7 @@
|
|||
else
|
||||
{
|
||||
NSDebugLog(@"realObject = %@ has no name in document", realObject);
|
||||
continue;
|
||||
// continue;
|
||||
}
|
||||
|
||||
if ([parentClassName isEqualToString: @"NSCustomObject5"])
|
||||
|
@ -317,16 +337,23 @@
|
|||
|
||||
NSLog(@"Adding customClassName = %@ with parent className = %@", customClassName,
|
||||
parentClassName);
|
||||
|
||||
[classManager addClassNamed: customClassName
|
||||
withSuperClassNamed: parentClassName
|
||||
withActions: nil
|
||||
withOutlets: nil
|
||||
isCustom: YES];
|
||||
|
||||
|
||||
// If the name of the object does not exist, then create it...
|
||||
if (theName == nil)
|
||||
{
|
||||
theName = [doc instantiateClassNamed: customClassName];
|
||||
}
|
||||
|
||||
/*
|
||||
NSDebugLog(@"Assigning %@ as customClass = %@", theName, customClassName);
|
||||
[classManager setCustomClass: customClassName
|
||||
forName: theName];
|
||||
*/
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -345,13 +372,17 @@
|
|||
{
|
||||
id dest = [o destination];
|
||||
id src = [o source];
|
||||
|
||||
NSString *destId = [document nameForObject: dest];
|
||||
NSString *srcId = [document nameForObject: src];
|
||||
|
||||
// Replace files owner with the document files owner for loading...
|
||||
dest = [self _replaceProxyInstanceWithRealObject: dest
|
||||
classManager: classManager];
|
||||
src = [self _replaceProxyInstanceWithRealObject: src
|
||||
classManager: classManager];
|
||||
classManager: classManager
|
||||
withID: destId];
|
||||
|
||||
src = [self _replaceProxyInstanceWithRealObject: src
|
||||
classManager: classManager
|
||||
withID: srcId];
|
||||
|
||||
// Reset them...
|
||||
[o setDestination: dest];
|
||||
|
|
Loading…
Reference in a new issue