Added logic to load and save .gorm directories. Maintained backwards

compatibility with old .gorm files.


git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/apps/gorm/trunk@14893 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Gregory John Casamento 2002-10-31 15:00:17 +00:00
parent 4d7ac746c7
commit a68a1a1426
3 changed files with 134 additions and 18 deletions

View file

@ -1,3 +1,14 @@
2002-10-31 Gregory John Casamento <greg_casamento@yahoo.com>
* GormDocument.m: -[GormDocument saveDocument:] made changes to allow
saving of .gorm files as directories. -[GormDocument loadDocument:]
made necessary modifications to load .gorm directory contents. Also
made certain that old gorm files are loaded properly and converted
when saved.
* GormClassManager.m: Made modifications to allow NSSecureTextField
to substitute for NSTextField and NSPanel to substitute for NSWindow.
Also made changes to allow FirstResponder to modified.
2002-10-29 Adam Fedor <fedor@gnu.org>
* GormMatrixEditor.m (-_constrainedFrame:framewithEvent:andKnob:knob):

View file

@ -649,8 +649,9 @@ NSString *IBClassNameChangedNotification = @"IBClassNameChangedNotification";
[self loadFromFile: path];
customClasses = RETAIN([NSMutableArray arrayWithCapacity: 1]);
customClassMap = RETAIN([NSMutableDictionary dictionaryWithCapacity: 10]);
// NSCreateMapTableWithZone(NSNonRetainedObjectMapKeyCallBacks,
// NSObjectMapValueCallBacks, 128, [self zone]);
// add first responder so that it may be edited.
[customClasses addObject: @"FirstResponder"];
}
}
@ -683,6 +684,17 @@ NSString *IBClassNameChangedNotification = @"IBClassNameChangedNotification";
[self allSubclassesOf: superClass
referenceClassList: customClasses
intoArray: array];
// add known allowable subclasses to the list.
if([superClass isEqualToString: @"NSWindow"])
{
[array addObject: @"NSPanel"];
}
else if([superClass isEqualToString: @"NSTextField"])
{
[array addObject: @"NSSecureTextField"];
}
return array;
}
@ -935,17 +947,22 @@ NSString *IBClassNameChangedNotification = @"IBClassNameChangedNotification";
{
NSDictionary *classInfo = [dict objectForKey: key];
NSMutableDictionary *newInfo;
NSMutableDictionary *oldInfo;
id obj;
newInfo = [NSMutableDictionary new];
oldInfo = [classInformation objectForKey: key];
[classInformation setObject: newInfo forKey: key];
RELEASE(newInfo);
obj = [classInfo objectForKey: @"Super"];
if (obj != nil)
{
[newInfo setObject: obj forKey: @"Super"];
}
// outlets
obj = [classInfo objectForKey: @"Outlets"];
if (obj != nil)
{
@ -954,6 +971,8 @@ NSString *IBClassNameChangedNotification = @"IBClassNameChangedNotification";
[newInfo setObject: obj forKey: @"Outlets"];
RELEASE(obj);
}
// actions
obj = [classInfo objectForKey: @"Actions"];
if (obj != nil)
{
@ -966,11 +985,17 @@ NSString *IBClassNameChangedNotification = @"IBClassNameChangedNotification";
return YES;
}
- (void) _convertDictionary: (NSMutableDictionary *)dict
{
NSMutableArray *array = [classInformation allKeys];
[dict removeObjectsForKeys: array];
}
// this method will load the custom classes and merge them with the
// Class information loaded at initialization time.
- (BOOL)loadCustomClasses: (NSString *)path
{
NSDictionary *dict;
NSMutableDictionary *dict;
NSLog(@"Load custom classes from file %@",path);
@ -990,11 +1015,12 @@ NSString *IBClassNameChangedNotification = @"IBClassNameChangedNotification";
if([[dict allKeys] containsObject: @"NSObject"])
{
NSLog(@"The file being loaded is in the old .classes format. Updating..");
[self _convertDictionary: dict];
}
[customClasses addObjectsFromArray: [dict allKeys]];
[classInformation addEntriesFromDictionary: dict];
return YES;
}

View file

@ -1570,8 +1570,31 @@ static NSImage *classesImage = nil;
id <IBConnectors> con;
NSString *name;
NSString *ownerClass;
NSFileManager *mgr = [NSFileManager defaultManager];
BOOL isDir = NO;
data = [NSData dataWithContentsOfFile: aFile];
if([mgr fileExistsAtPath: aFile isDirectory: &isDir])
{
// if the data is in a directory, then load from objects.gorm in the directory
if(isDir == NO)
{
data = [NSData dataWithContentsOfFile: aFile];
NSDebugLog(@"Loaded data from file...");
}
else
{
NSString *newFileName = [aFile stringByAppendingPathComponent: @"objects.gorm"];
data = [NSData dataWithContentsOfFile: newFileName];
NSDebugLog(@"Loaded data from %@...",newFileName);
}
}
else
{
// no file exists...
data = nil;
}
// check the data...
if (data == nil)
{
NSRunAlertPanel(NULL,
@ -1614,13 +1637,27 @@ static NSImage *classesImage = nil;
@"OK", NULL, NULL);
return nil;
}
if (![classManager loadCustomClasses: [[aFile stringByDeletingPathExtension]
stringByAppendingPathExtension: @"classes"]])
if(isDir == NO)
{
NSRunAlertPanel(NULL, @"Could not open the associated classes file.\n"
@"You won't be able to edit connections on custom classes",
@"OK", NULL, NULL);
if (![classManager loadCustomClasses: [[aFile stringByDeletingPathExtension]
stringByAppendingPathExtension: @"classes"]])
{
NSRunAlertPanel(NULL, @"Could not open the associated classes file.\n"
@"You won't be able to edit connections on custom classes",
@"OK", NULL, NULL);
}
}
else
{
if (![classManager loadCustomClasses: [aFile stringByAppendingPathComponent: @"data.classes"]])
{
NSRunAlertPanel(NULL, @"Could not open the associated classes file.\n"
@"You won't be able to edit connections on custom classes",
@"OK", NULL, NULL);
}
}
[classesView reloadData];
/*
@ -2182,6 +2219,11 @@ static NSImage *classesImage = nil;
BOOL archiveResult;
NSArchiver *archiver;
NSMutableData *archiverData;
NSString *gormPath;
NSString *classesPath;
NSFileManager *mgr = [NSFileManager defaultManager];
BOOL isDir;
BOOL fileExists;
if (documentPath == nil)
{
@ -2195,6 +2237,10 @@ static NSImage *classesImage = nil;
NSDebugLog(@"nametable : %@", nameTable);
NSDebugLog(@"connections : %@", connections);
// set up the necessary paths...
gormPath = [documentPath stringByAppendingPathComponent: @"objects.gorm"];
classesPath = [documentPath stringByAppendingPathComponent: @"data.classes"];
archiverData = [NSMutableData dataWithCapacity: 0];
archiver = [[NSArchiver alloc] initForWritingWithMutableData: archiverData];
@ -2235,13 +2281,46 @@ static NSImage *classesImage = nil;
intoClassName: @"NSMenuTemplate"];
[archiver encodeRootObject: self];
archiveResult = [archiverData writeToFile: documentPath atomically: YES];
//archiveResult = [NSArchiver archiveRootObject: self toFile: documentPath];
RELEASE(archiver);
if (archiveResult)
archiveResult = [classManager saveToFile:
[[documentPath stringByDeletingPathExtension]
stringByAppendingPathExtension: @"classes"]];
fileExists = [mgr fileExistsAtPath: documentPath isDirectory: &isDir];
if(fileExists)
{
if(isDir == NO)
{
NSString *saveFilePath = [documentPath stringByAppendingPathExtension: @"save"];
// move the old file to something...
if(![mgr movePath: documentPath toPath: saveFilePath handler: nil])
{
NSLog(@"Error moving old %@ file to %@",documentPath,saveFilePath);
}
// create the new directory..
archiveResult = [mgr createDirectoryAtPath: documentPath attributes: nil];
}
else
{
// set to yes since the directory is already present.
archiveResult = YES;
}
}
else
{
// create the directory...
archiveResult = [mgr createDirectoryAtPath: documentPath attributes: nil];
}
if(archiveResult)
{
// save the data...
archiveResult = [archiverData writeToFile: gormPath atomically: YES];
RELEASE(archiver);
if (archiveResult)
{
// save the custom classes.. and we're done...
archiveResult = [classManager saveToFile: classesPath];
}
}
[self endArchiving];