Add keyed coding. This is still rather useless until we get a proper

implementation for -serializedRepresentation.


git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@33294 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Fred Kiefer 2011-06-13 22:22:29 +00:00
parent af6f2c29bc
commit ddf77c01c5
2 changed files with 65 additions and 46 deletions

View file

@ -579,59 +579,74 @@
- (void) encodeWithCoder: (NSCoder*)aCoder
{
[aCoder encodeValueOfObjCType: @encode(int) at: &_wrapperType];
// Dont store the file name
[aCoder encodeObject: _preferredFilename];
[aCoder encodeObject: _fileAttributes];
[aCoder encodeObject: _wrapperData];
[aCoder encodeObject: _iconImage];
if ([aCoder allowsKeyedCoding])
{
[aCoder encodeObject: [self serializedRepresentation] forKey: @"NSFileWrapperData"];
}
else
{
[aCoder encodeValueOfObjCType: @encode(int) at: &_wrapperType];
// Dont store the file name
[aCoder encodeObject: _preferredFilename];
[aCoder encodeObject: _fileAttributes];
[aCoder encodeObject: _wrapperData];
[aCoder encodeObject: _iconImage];
}
}
- (id) initWithCoder: (NSCoder*)aDecoder
{
int wrapperType;
NSString *preferredFilename;
NSDictionary *fileAttributes;
id wrapperData;
NSImage *iconImage;
[aDecoder decodeValueOfObjCType: @encode(int) at: &wrapperType];
// Dont restore the file name
preferredFilename = [aDecoder decodeObject];
fileAttributes = [aDecoder decodeObject];
wrapperData = [aDecoder decodeObject];
iconImage = [aDecoder decodeObject];
switch (wrapperType)
if ([aDecoder allowsKeyedCoding])
{
case GSFileWrapperRegularFileType:
{
self = [self initRegularFileWithContents: wrapperData];
break;
}
case GSFileWrapperSymbolicLinkType:
{
self = [self initSymbolicLinkWithDestination: wrapperData];
break;
}
case GSFileWrapperDirectoryType:
{
self = [self initDirectoryWithFileWrappers: wrapperData];
break;
}
NSData *data = [aDecoder decodeObjectForKey: @"NSFileWrapperData"];
return [self initWithSerializedRepresentation: data];
}
if (preferredFilename != nil)
else
{
[self setPreferredFilename: preferredFilename];
}
if (fileAttributes != nil)
{
[self setFileAttributes: fileAttributes];
}
if (iconImage != nil)
{
[self setIcon: iconImage];
int wrapperType;
NSString *preferredFilename;
NSDictionary *fileAttributes;
id wrapperData;
NSImage *iconImage;
[aDecoder decodeValueOfObjCType: @encode(int) at: &wrapperType];
// Dont restore the file name
preferredFilename = [aDecoder decodeObject];
fileAttributes = [aDecoder decodeObject];
wrapperData = [aDecoder decodeObject];
iconImage = [aDecoder decodeObject];
switch (wrapperType)
{
case GSFileWrapperRegularFileType:
{
self = [self initRegularFileWithContents: wrapperData];
break;
}
case GSFileWrapperSymbolicLinkType:
{
self = [self initSymbolicLinkWithDestination: wrapperData];
break;
}
case GSFileWrapperDirectoryType:
{
self = [self initDirectoryWithFileWrappers: wrapperData];
break;
}
}
if (preferredFilename != nil)
{
[self setPreferredFilename: preferredFilename];
}
if (fileAttributes != nil)
{
[self setFileAttributes: fileAttributes];
}
if (iconImage != nil)
{
[self setIcon: iconImage];
}
}
return self;
}