diff --git a/Headers/gnustep/gui/NSPasteboard.h b/Headers/gnustep/gui/NSPasteboard.h index 4b9e8fe92..11348ecfe 100644 --- a/Headers/gnustep/gui/NSPasteboard.h +++ b/Headers/gnustep/gui/NSPasteboard.h @@ -35,6 +35,7 @@ @class NSString; @class NSArray; @class NSData; +@class NSFileWrapper; // // Pasteboard Type Globals @@ -113,6 +114,7 @@ extern NSString *NSPasteboardCommunicationException; - (BOOL)setString:(NSString *)string forType:(NSString *)dataType; - (BOOL)writeFileContents:(NSString *)filename; +- (BOOL)writeFileWrapper:(NSFileWrapper *)wrapper; // // Determining Types @@ -128,6 +130,7 @@ extern NSString *NSPasteboardCommunicationException; - (id)propertyListForType:(NSString *)dataType; - (NSString *)readFileContentsType:(NSString *)type toFile:(NSString *)filename; +- (NSFileWrapper *)readFileWrapper; - (NSString *)stringForType:(NSString *)dataType; // diff --git a/Source/NSPasteboard.m b/Source/NSPasteboard.m index 31a9cf9a2..ecdfd657b 100644 --- a/Source/NSPasteboard.m +++ b/Source/NSPasteboard.m @@ -31,6 +31,7 @@ #include #include #include +#include #include #include #include @@ -564,6 +565,36 @@ static NSMapTable *mimeMap = NULL; return ok; } +- (BOOL)writeFileWrapper:(NSFileWrapper *)wrapper +{ + NSString *filename = [wrapper preferredFilename]; + NSData *data; + NSString *type; + BOOL ok = NO; + + if (filename == nil) + [NSException raise: NSInvalidArgumentException + format: @"Cannot put file on pastboard with no preferred filename"]; + + data = [wrapper serializedRepresentation]; + type = NSCreateFileContentsPboardType([filename pathExtension]); + NS_DURING + { + ok = [target setData: data + forType: type + isFile: YES + oldCount: changeCount]; + } + NS_HANDLER + { + ok = NO; + [NSException raise: NSPasteboardCommunicationException + format: @"%@", [localException reason]]; + } + NS_ENDHANDLER + return ok; +} + /* * Determining Types */ @@ -672,6 +703,9 @@ static NSMapTable *mimeMap = NULL; type = NSCreateFileContentsPboardType([filename pathExtension]); } d = [self dataForType: type]; + if (d == nil) + d = [self dataForType: NSFileContentsPboardType]; + if ([d writeToFile: filename atomically: NO] == NO) { return nil; @@ -679,6 +713,16 @@ static NSMapTable *mimeMap = NULL; return filename; } +- (NSFileWrapper *)readFileWrapper +{ + NSData *d = [self dataForType: NSFileContentsPboardType]; + + if (d == nil) + return nil; + + return AUTORELEASE([[NSFileWrapper alloc] initWithSerializedRepresentation: d]); +} + - (NSString*) stringForType: (NSString*)dataType { return [self propertyListForType: dataType];