From ddf77c01c510e5c4f1f8d493d02091bc7a5eef12 Mon Sep 17 00:00:00 2001 From: Fred Kiefer Date: Mon, 13 Jun 2011 22:22:29 +0000 Subject: [PATCH] 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 --- ChangeLog | 4 ++ Source/NSFileWrapper.m | 107 +++++++++++++++++++++++------------------ 2 files changed, 65 insertions(+), 46 deletions(-) diff --git a/ChangeLog b/ChangeLog index ee1ffca25..35ef915b7 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2011-06-14 Fred Kiefer + + * Source/NSFileWrapper.m: Add keyed coding. + 2011-06-13 Eric Wasylishen * Source/NSBitmapImageRep.m: Reduce floating-point error in the diff --git a/Source/NSFileWrapper.m b/Source/NSFileWrapper.m index 8a6ab3433..a67d3aa4a 100644 --- a/Source/NSFileWrapper.m +++ b/Source/NSFileWrapper.m @@ -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; }