Various fixed to gmodel loading and improvements.

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/apps/gorm/trunk@20348 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Gregory John Casamento 2004-11-12 23:09:54 +00:00
parent 59aa176c14
commit 22cce81380
7 changed files with 173 additions and 47 deletions

View file

@ -1,3 +1,17 @@
2004-11-12 17:08 Gregory John Casamento <greg_casamento@yahoo.com>
* GModelDecoder.m: Changes to improve loading of .gmodel files.
* GormClassManager.[hm]: Changed name of setCustomClass:forObject:
to setCustomClass:forName: and also removeCustomClassforObject: to
removeCustomClassForName:
* GormCustomClassInspector.m: Changes to accomodate the new method
name.
* GormDocument.m: Changes to accomodate the new method name.
* GormFilesOwner.m: Corrected an issue with changing the class
for the file's owner. Added code which checks both the actions
and outlets attached to see if it's necessary to prompt before
destroying connections.
2004-11-09 09:08 Gregory John Casamento <greg_casamento@yahoo.com>
* Palettes/2Controls/GormNSStepperInspector.gorm: Changed

View file

@ -69,6 +69,10 @@ static BOOL gormFileOwnerDecoded;
}
@end
@interface NSWindow (GormNSWindowPrivate)
- (unsigned int) _styleMask;
@end
@implementation GModelApplication
- (id)initWithModelUnarchiver:(GMUnarchiver*)unarchiver
@ -183,7 +187,6 @@ static BOOL gormFileOwnerDecoded;
@end
@implementation GormDocument (GModel)
/* Try to define a possibly custom class that's in the gmodel
@ -192,20 +195,20 @@ static BOOL gormFileOwnerDecoded;
is, and at best, we could search the connections to see what
outlets and actions are used.
*/
- (void) defineClass: (id)object inFile: (NSString *)path
- (void) defineClass: (id)className inFile: (NSString *)path
{
NSString *classname = [object className];
int result;
NSString *header;
NSFileManager *mgr;
NSRange notFound = NSMakeRange(NSNotFound, 0);
if ([classManager isKnownClass: classname])
if ([classManager isKnownClass: className])
return;
/* Can we parse a header in this directory? */
mgr = [NSFileManager defaultManager];
path = [path stringByDeletingLastPathComponent];
header = [path stringByAppendingPathComponent: classname];
header = [path stringByAppendingPathComponent: className];
header = [header stringByAppendingPathExtension: @"h"];
if ([mgr fileExistsAtPath: header])
{
@ -213,7 +216,7 @@ static BOOL gormFileOwnerDecoded;
NSRunAlertPanel(_(@"GModel Loading"),
_(@"Parse %@ to define unknown class %@?"),
_(@"Yes"), _(@"No"), _(@"Choose File"),
header, classname, nil);
header, className, nil);
}
else
{
@ -221,7 +224,7 @@ static BOOL gormFileOwnerDecoded;
NSRunAlertPanel(_(@"GModel Loading"),
_(@"Unknown class %@. Parse header file to define?"),
_(@"Yes"), _(@"No"), nil,
classname, nil);
className, nil);
if (result == NSAlertDefaultReturn)
result = NSAlertOtherReturn;
}
@ -240,22 +243,30 @@ static BOOL gormFileOwnerDecoded;
}
// make a guess and warn the user
// cheesy attempt to determine superclass..
if (result != NSAlertDefaultReturn)
{
NSString *superClass = nil;
BOOL added = NO;
if(superClass == nil &&
[object isKindOfClass: [GormCustomView class]])
if(superClass == nil && [className isEqual: @"GormCustomView"])
{
superClass = @"NSView";
}
else if(NSEqualRanges(notFound,[className rangeOfString: @"Window"]) == NO)
{
superClass = @"NSWindow";
}
else if(NSEqualRanges(notFound,[className rangeOfString: @"Panel"]) == NO)
{
superClass = @"NSPanel";
}
else
{
superClass = @"NSObject";
}
added = [classManager addClassNamed: classname
added = [classManager addClassNamed: className
withSuperClassNamed: superClass
withActions: [NSMutableArray array]
withOutlets: [NSMutableArray array]];
@ -263,11 +274,11 @@ static BOOL gormFileOwnerDecoded;
// inform the user...
if(added)
{
NSLog(@"Added class %@ with superclass of %@.", classname, superClass);
NSLog(@"Added class %@ with superclass of %@.", className, superClass);
}
else
{
NSLog(@"Failed to add class %@ with superclass of %@.", classname, superClass);
NSLog(@"Failed to add class %@ with superclass of %@.", className, superClass);
}
}
else
@ -289,6 +300,63 @@ static BOOL gormFileOwnerDecoded;
return object;
}
- (NSDictionary *) processModel: (NSMutableDictionary *)model
inPath: (NSString *)path
{
NSMutableDictionary *customMap = nil;
NSEnumerator *en = [model objectEnumerator];
id obj;
NSLog(@"Processing model...");
while((obj = [en nextObject]) != nil)
{
if([obj isKindOfClass: [NSDictionary class]])
{
NSString *objIsa = [obj objectForKey: @"isa"];
Class cls = NSClassFromString(objIsa);
// NSLog(@"isa = %@",objIsa);
if([classManager isKnownClass: objIsa] == NO &&
[objIsa isEqual: @"IMControlConnector"] == NO &&
[objIsa isEqual: @"IMOutletConnector"] == NO &&
[objIsa isEqual: @"IMCustomObject"] == NO &&
[objIsa isEqual: @"IMCustomView"] == NO &&
cls == nil)
{
NSString *superClass;
NSLog(@"%@ is not a known class",objIsa);
[self defineClass: objIsa inFile: path];
superClass = [classManager superClassNameForClassNamed: objIsa];
[obj setObject: superClass forKey: @"isa"];
// guess at name which will be given in the nameTable...
/*
if([superClass isEqual: @"NSMenu"])
name = @"GormNSMenu";
else if([superClass isEqual: @"NSWindow"])
name = @"GormNSWindow";
else if([superClass isEqual: @"NSPanel"])
name = @"GormNSPanel";
else if([superClass isEqual: @"NSBrowser"])
name = @"GormNSBrowser";
else if([superClass isEqual: @"NSTableView"])
name = @"GormNSTableView";
else if([superClass isEqual: @"NSOutlineView"])
name = @"GormNSOutlineView";
else if([superClass isEqual: @"NSPopUpButton"])
name = @"GormNSPopUpButton";
else if([superClass isEqual: @"NSPopUpButtonCell"])
name = @"GormNSPopUpButtonCell";
else if([superClass isEqual: @"NSOutlineView"])
name = @"GormNSOutlineView";
*/
}
}
}
return customMap;
}
/* importing of legacy gmodel files.*/
- (id) openGModel: (NSString *)path
@ -301,6 +369,7 @@ static BOOL gormFileOwnerDecoded;
NSArray *gmconnections;
Class u = gmodel_class(@"GMUnarchiver");
NSString *delegateClass = nil;
NSMutableDictionary *model;
NSLog (@"Loading gmodel file %@...", path);
gormNibOwner = nil;
@ -321,7 +390,12 @@ static BOOL gormFileOwnerDecoded;
[u decodeClassName: @"NSPopUpButtonCell" asClassName: @"GormNSPopUpButtonCell"];
[u decodeClassName: @"NSOutlineView" asClassName: @"GormNSOutlineView"];
unarchiver = RETAIN([u unarchiverWithContentsOfFile: path]);
// process the model to take care of any custom classes...
model = [NSMutableDictionary dictionaryWithContentsOfFile: path];
[self processModel: model inPath: path];
// initialize with the property list...
unarchiver = RETAIN([[u alloc] initForReadingWithPropertyList: [[model description] propertyList]]);
if (!unarchiver)
{
NSLog(@"Failed to load gmodel file %@!!",path);
@ -344,7 +418,7 @@ static BOOL gormFileOwnerDecoded;
if (gormNibOwner)
{
[self defineClass: gormNibOwner inFile: path];
[self defineClass: [gormNibOwner className] inFile: path];
[filesOwner setClassName: [gormNibOwner className]];
}
@ -356,12 +430,25 @@ static BOOL gormFileOwnerDecoded;
while ((obj = [enumerator nextObject]))
{
if (obj != gormNibOwner)
[self setName: nil forObject: obj];
{
[self attachObject: obj toParent: nil];
}
if([obj isKindOfClass: [GormObjectProxy class]])
{
NSLog(@"processing... %@",[obj className]);
[self defineClass: obj inFile: path];
if([[obj className] isEqual: @"NSFontManager"])
{
// if it's the font manager, take care of it...
[self setName: @"NSFont" forObject: obj];
[self attachObject: obj toParent: nil];
// RELEASE(item);
fontManager = obj;
}
else
{
NSLog(@"processing... %@",[obj className]);
[self defineClass: [obj className] inFile: path];
}
}
}
@ -430,21 +517,39 @@ static BOOL gormFileOwnerDecoded;
if ([gormRealObject isKindOfClass: [GModelApplication class]])
{
enumerator = [[gormRealObject windows] objectEnumerator];
while ((obj = [enumerator nextObject]))
if([gormRealObject respondsToSelector: @selector(windows)])
{
if ([self nameForObject: obj] == nil)
[self setName: nil forObject: obj];
}
if ([gormRealObject mainMenu])
{
[self setName: @"NSMenu" forObject: [gormRealObject mainMenu]];
enumerator = [[gormRealObject windows] objectEnumerator];
while ((obj = [enumerator nextObject]))
{
if([obj isKindOfClass: [NSWindow class]])
{
if([obj _styleMask] == 0)
{
// Skip borderless window. Borderless windows are
// sometimes used as temporary objects in nib files,
// they will show up unless eliminated.
continue;
}
}
[self attachObject: obj toParent: nil];
}
if([gormRealObject respondsToSelector: @selector(mainMenu)])
{
if ([gormRealObject mainMenu])
{
[self attachObject: [gormRealObject mainMenu] toParent: nil];
}
}
}
}
else
{
/* Here we need to addClass:... (outlets, actions). */
//[self defineClass: [gormRealObject className] inFile: path];
// Here we need to addClass:... (outlets, actions). */
[self defineClass: [gormRealObject className] inFile: path];
NSLog(@"Don't understand real object %@", gormRealObject);
}

View file

@ -109,9 +109,9 @@
- (NSString *) customClassForName: (NSString *)name;
- (void) setCustomClass: (NSString *)className
forObject: (id)object;
forName: (NSString *)object;
- (void) removeCustomClassForObject: (id) object;
- (void) removeCustomClassForName: (NSString *) object;
- (NSMutableDictionary *) customClassMap;
- (void) setCustomClassMap: (NSMutableDictionary *)dict;
- (BOOL) isCustomClassMapEmpty;

View file

@ -1632,12 +1632,12 @@
}
- (void) setCustomClass: (NSString *)className
forObject: (id)object
forName: (NSString *)object
{
[customClassMap setObject: className forKey: object];
}
- (void) removeCustomClassForObject: (id) object
- (void) removeCustomClassForName: (NSString *)object
{
[customClassMap removeObjectForKey: object];
}

View file

@ -168,11 +168,11 @@
if (![stringValue isEqualToString: classForObject])
{
[_classManager setCustomClass: stringValue
forObject: nameForObject];
forName: nameForObject];
}
else
{
[_classManager removeCustomClassForObject: nameForObject];
[_classManager removeCustomClassForName: nameForObject];
}
[self _replaceCellClassForObject: [self object]

View file

@ -465,11 +465,19 @@ static NSImage *fileImage = nil;
[anObject setReleasedWhenClosed: NO];
}
}
/*
* Check if it's a font manager.
*/
else if([anObject isKindOfClass: [NSFontManager class]])
{
// if someone tries to attach a font manager, we must attach
// the proxy instead.
[self _instantiateFontManager];
}
/*
* Add the current menu and any submenus.
*/
if ([anObject isKindOfClass: [NSMenu class]] == YES)
else if ([anObject isKindOfClass: [NSMenu class]] == YES)
{
BOOL isMainMenu = NO;
@ -508,13 +516,12 @@ static NSImage *fileImage = nil;
[[anObject window] setFrameTopLeftPoint: origin];
}
}
/*
* if this a scrollview, it is interesting to add its contentview
* if it is a tableview or a textview
*/
if (([anObject isKindOfClass: [NSScrollView class]] == YES)
&& ([(NSScrollView *)anObject documentView] != nil))
else if (([anObject isKindOfClass: [NSScrollView class]] == YES)
&& ([(NSScrollView *)anObject documentView] != nil))
{
if ([[anObject documentView] isKindOfClass:
[NSTableView class]] == YES)
@ -1102,13 +1109,13 @@ static NSImage *fileImage = nil;
{
// remove from custom class map...
NSDebugLog(@"Delete from custom class map -> %@",name);
[cm removeCustomClassForObject: name];
[cm removeCustomClassForName: name];
if([anObject isKindOfClass: [NSScrollView class]] == YES)
{
NSView *subview = [anObject documentView];
NSString *objName = [self nameForObject: subview];
NSDebugLog(@"Delete from custom class map -> %@",objName);
[cm removeCustomClassForObject: objName];
[cm removeCustomClassForName: objName];
}
// remove from name table...
@ -1722,7 +1729,7 @@ static NSImage *fileImage = nil;
{
NSString *name = [self nameForObject: instance];
[classManager setCustomClass: object
forObject: name];
forName: name];
}
[selectionBox setContentView: scrollView];

View file

@ -191,11 +191,11 @@
* Create list of existing connections for selected object.
*/
array = [[(id<IB>)NSApp activeDocument] connectorsForSource: object
ofClass: [NSNibControlConnector class]];
ofClass: [NSNibOutletConnector class]];
if ([array count] > 0)
hasConnections = YES;
array = [[(id<IB>)NSApp activeDocument] connectorsForSource: object
ofClass: [NSNibOutletConnector class]];
array = [[(id<IB>)NSApp activeDocument] connectorsForDestination: object
ofClass: [NSNibControlConnector class]];
if ([array count] > 0)
hasConnections = YES;
@ -230,15 +230,15 @@
unsigned i;
array = [doc connectorsForSource: object
ofClass: [NSNibControlConnector class]];
ofClass: [NSNibOutletConnector class]];
for (i = 0; i < [array count]; i++)
{
id<IBConnectors> con = [array objectAtIndex: i];
[doc removeConnector: con];
}
array = [doc connectorsForSource: object
ofClass: [NSNibOutletConnector class]];
array = [doc connectorsForDestination: object
ofClass: [NSNibControlConnector class]];
for (i = 0; i < [array count]; i++)
{
id<IBConnectors> con = [array objectAtIndex: i];