Added two missing methods for file wrapper

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@6808 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Fred Kiefer 2000-06-26 19:56:33 +00:00
parent b4bce295ca
commit 69e4d7875e
2 changed files with 47 additions and 0 deletions

View file

@ -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;
//

View file

@ -31,6 +31,7 @@
#include <AppKit/NSPasteboard.h>
#include <AppKit/NSApplication.h>
#include <AppKit/NSWorkspace.h>
#include <AppKit/NSFileWrapper.h>
#include <Foundation/NSArray.h>
#include <Foundation/NSData.h>
#include <Foundation/NSDictionary.h>
@ -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];