More improvements to GModel import.

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/apps/gorm/trunk@20350 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Gregory John Casamento 2004-11-13 05:06:15 +00:00
parent 22cce81380
commit c09be7be05
7 changed files with 100 additions and 46 deletions

View file

@ -1,3 +1,12 @@
2004-11-13 00:03 Gregory John Casamento <greg_casamento@yahoo.com>
* GModelDecoder.m: Added GModelMenuTemplate to allow decoding
of .gmodels which contain the menu template class.
* GormClassManager.m: Changed the allClassNames method to not prepend
NSObject now that NSObject is part of the classInformation plist.
* GormFunctions.[hm]: Added parameter to pass in the current list of
classes from the calling document.
2004-11-12 17:08 Gregory John Casamento <greg_casamento@yahoo.com>
* GModelDecoder.m: Changes to improve loading of .gmodel files.

View file

@ -31,6 +31,7 @@
#include "GormPrivate.h"
#include "GormCustomView.h"
#include "GormDocument.h"
#include "GormFunctions.h"
static Class gmodel_class(NSString *className);
@ -38,6 +39,23 @@ static id gormNibOwner;
static id gormRealObject;
static BOOL gormFileOwnerDecoded;
@interface NSWindow (GormPrivate)
- (void) gmSetStyleMask: (unsigned int)mask;
@end
@implementation NSWindow (GormPrivate)
// private method to change the Window style mask on the fly
- (void) gmSetStyleMask: (unsigned int)mask
{
_styleMask = mask;
[GSServerForWindow(self) stylewindow: mask : [self windowNumber]];
}
@end
@interface NSWindow (GormNSWindowPrivate)
- (unsigned int) _styleMask;
@end
@interface GModelApplication : NSObject
{
id mainMenu;
@ -56,23 +74,6 @@ static BOOL gormFileOwnerDecoded;
@end
@interface NSWindow (GormPrivate)
- (void) gmSetStyleMask: (unsigned int)mask;
@end
@implementation NSWindow (GormPrivate)
// private method to change the Window style mask on the fly
- (void) gmSetStyleMask: (unsigned int)mask
{
_styleMask = mask;
[GSServerForWindow(self) stylewindow: mask : [self windowNumber]];
}
@end
@interface NSWindow (GormNSWindowPrivate)
- (unsigned int) _styleMask;
@end
@implementation GModelApplication
- (id)initWithModelUnarchiver:(GMUnarchiver*)unarchiver
@ -126,8 +127,32 @@ static BOOL gormFileOwnerDecoded;
@end
@implementation GormObjectProxy (GModel)
@interface GModelMenuTemplate : NSObject
{
NSString *menuClassName;
id realObject;
}
+ (id)createObjectForModelUnarchiver:(GMUnarchiver*)unarchiver;
- (id)initWithModelUnarchiver:(GMUnarchiver*)unarchiver;
@end
@implementation GModelMenuTemplate
- (id)initWithModelUnarchiver:(GMUnarchiver*)unarchiver
{
menuClassName = [unarchiver decodeObjectWithName:@"menuClassName"];
realObject = [unarchiver decodeObjectWithName: @"realObject"];
// RELEASE(self);
return realObject;
}
+ (id)createObjectForModelUnarchiver:(GMUnarchiver*)unarchiver
{
return AUTORELEASE([[GModelMenuTemplate alloc] init]);
}
@end
@implementation GormObjectProxy (GModel)
+ (id)createObjectForModelUnarchiver:(GMUnarchiver*)unarchiver
{
return AUTORELEASE([[self alloc] init]);
@ -143,8 +168,8 @@ static BOOL gormFileOwnerDecoded;
realObject = [unarchiver decodeObjectWithName: @"realObject"];
//real = [unarchiver representationForName: @"realObject" isLabeled: &label];
if (!gormFileOwnerDecoded)
if (!gormFileOwnerDecoded ||
[realObject isKindOfClass: [GModelApplication class]])
{
gormFileOwnerDecoded = YES;
gormNibOwner = self;
@ -152,12 +177,10 @@ static BOOL gormFileOwnerDecoded;
}
return self;
}
@end
@implementation GormCustomView (GModel)
+ (id)createObjectForModelUnarchiver:(GMUnarchiver*)unarchiver
{
return AUTORELEASE([[self alloc] initWithFrame: NSMakeRect(0,0,10,10)]);
@ -184,7 +207,6 @@ static BOOL gormFileOwnerDecoded;
return self;
}
@end
@implementation GormDocument (GModel)
@ -243,12 +265,14 @@ static BOOL gormFileOwnerDecoded;
}
// make a guess and warn the user
// cheesy attempt to determine superclass..
if (result != NSAlertDefaultReturn)
{
NSString *superClass = nil;
NSString *superClass = promptForClassName([NSString stringWithFormat: @"Superclass: %@",className],
[classManager allClassNames]);
BOOL added = NO;
RETAIN(superClass);
// cheesy attempt to determine superclass..
if(superClass == nil && [className isEqual: @"GormCustomView"])
{
superClass = @"NSView";
@ -376,26 +400,27 @@ static BOOL gormFileOwnerDecoded;
gormRealObject = nil;
gormFileOwnerDecoded = NO;
/* GModel classes */
[u decodeClassName: @"NSApplication" asClassName: @"GModelApplication"];
[u decodeClassName: @"IMCustomView" asClassName: @"GormCustomView"];
[u decodeClassName: @"IMCustomObject" asClassName: @"GormObjectProxy"];
[u decodeClassName: @"NSApplication" asClassName: @"GModelApplication"];
[u decodeClassName: @"IMCustomView" asClassName: @"GormCustomView"];
[u decodeClassName: @"IMCustomObject" asClassName: @"GormObjectProxy"];
/* Gorm classes */
[u decodeClassName: @"NSMenu" asClassName: @"GormNSMenu"];
[u decodeClassName: @"NSWindow" asClassName: @"GormNSWindow"];
[u decodeClassName: @"NSPanel" asClassName: @"GormNSPanel"];
[u decodeClassName: @"NSBrowser" asClassName: @"GormNSBrowser"];
[u decodeClassName: @"NSTableView" asClassName: @"GormNSTableView"];
[u decodeClassName: @"NSOutlineView" asClassName: @"GormNSOutlineView"];
[u decodeClassName: @"NSPopUpButton" asClassName: @"GormNSPopUpButton"];
[u decodeClassName: @"NSMenu" asClassName: @"GormNSMenu"];
[u decodeClassName: @"NSWindow" asClassName: @"GormNSWindow"];
[u decodeClassName: @"NSPanel" asClassName: @"GormNSPanel"];
[u decodeClassName: @"NSBrowser" asClassName: @"GormNSBrowser"];
[u decodeClassName: @"NSTableView" asClassName: @"GormNSTableView"];
[u decodeClassName: @"NSOutlineView" asClassName: @"GormNSOutlineView"];
[u decodeClassName: @"NSPopUpButton" asClassName: @"GormNSPopUpButton"];
[u decodeClassName: @"NSPopUpButtonCell" asClassName: @"GormNSPopUpButtonCell"];
[u decodeClassName: @"NSOutlineView" asClassName: @"GormNSOutlineView"];
[u decodeClassName: @"NSOutlineView" asClassName: @"GormNSOutlineView"];
[u decodeClassName: @"NSMenuTemplate" asClassName: @"GModelMenuTemplate"];
// 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]]);
unarchiver = [[u alloc] initForReadingWithPropertyList: [[model description] propertyList]];
if (!unarchiver)
{
NSLog(@"Failed to load gmodel file %@!!",path);
@ -546,14 +571,19 @@ static BOOL gormFileOwnerDecoded;
}
}
else
else if(gormRealObject != nil)
{
// Here we need to addClass:... (outlets, actions). */
[self defineClass: [gormRealObject className] inFile: path];
}
else
{
NSLog(@"Don't understand real object %@", gormRealObject);
}
[self rebuildObjToNameMapping];
// RELEASE(unarchiver);
return self;
}
@end

View file

@ -119,6 +119,7 @@ Gorm_RESOURCE_FILES = \
Images/LeftArr.tiff \
Images/RightArr.tiff \
Images/GormTesting.tiff \
Resources/GormClassPanel.gorm \
Resources/GormPrefColors.gorm \
Resources/GormViewSizeInspector.gorm \
Resources/GormCustomClassInspector.gorm \
@ -174,7 +175,8 @@ Gorm_HEADERS = \
GormColorsPref.h \
GormPalettesPref.h \
GormSoundView.h \
GormFilePrefsManager.h
GormFilePrefsManager.h \
GormClassPanelController.h
Gorm_OBJC_FILES = \
main.m \
@ -222,7 +224,8 @@ Gorm_OBJC_FILES = \
GormColorsPref.m \
GormPalettesPref.m \
GormSoundView.m \
GormFilePrefsManager.m
GormFilePrefsManager.m \
GormClassPanelController.m
-include GNUmakefile.preamble

View file

@ -697,9 +697,7 @@
- (NSArray*) allClassNames
{
NSArray *array = [NSArray arrayWithObject: @"NSObject"];
return [array arrayByAddingObjectsFromArray:
[[classInformation allKeys] sortedArrayUsingSelector: @selector(compare:)]];
return [[classInformation allKeys] sortedArrayUsingSelector: @selector(compare:)];
}
- (NSArray*) allOutletsForObject: (id)obj
@ -1801,4 +1799,10 @@
(unsigned long)self,
customClassMap];
}
/** Helpful for debugging */
- (NSString *) dumpClassInformation
{
return [classInformation description];
}
@end

View file

@ -194,10 +194,9 @@ static NSImage *fileImage = nil;
NSRect mainRect = {{20, 0}, {320, 188}};
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
// initialize...
openEditors = [NSMutableArray new];
classManager = [[GormClassManager alloc] initWithDocument: self];
// classEditor = [[GormClassEditor alloc] initWithDocument: self];
/*
* NB. We must retain the map values (object names) as the nameTable

View file

@ -64,4 +64,7 @@ NSArray *systemSoundsList();
// compute the gorm version
int appVersion(long a, long b, long c);
// prompt for a class name. Used mainly for gmodel loading...
NSString *promptForClassName(NSString *title, NSArray *classes);
#endif

View file

@ -30,6 +30,7 @@
#include <Foundation/NSFileManager.h>
#include <Foundation/NSPathUtilities.h>
#include <Foundation/NSString.h>
#include "GormClassPanelController.h"
// find all subitems for the given items...
void findAllWithArray(id item, NSMutableArray *array)
@ -273,3 +274,8 @@ int appVersion(long a, long b, long c)
return (((a) << 16)+((b) << 8) + (c));
}
NSString *promptForClassName(NSString *title, NSArray *classes)
{
GormClassPanelController *cpc = AUTORELEASE([[GormClassPanelController alloc] initWithTitle: title classList: classes]);
return [cpc runModal];
}