Drag and drop onto the desktop?
Drag and drop onto the desktop?
- Subject: Drag and drop onto the desktop?
- From: Jesse Grosjean <email@hidden>
- Date: Thu, 6 Dec 2001 07:35:40 -0500
I'm trying to figure out what pastboard types the OS X desktop and
finder accepts. My application generates some NSData, i would like to
drag this data to the desktop and have it show up as a new file there.
My guess is that i should wrap the data in a NSFilewrapper and put that
on the pastboard, but that does not seem to work. Here is the code that
i'm using:
- (void)mouseDown:(NSEvent *)theEvent {
if ([self image] != nil) {
NSPasteboard *pboard = [NSPasteboard pasteboardWithName:NSDragPboard];
[pboard declareTypes:[NSArray
arrayWithObjects:NSFileContentsPboardType, NSFilenamesPboardType, nil]
owner:self];
[self dragImage:[self createDragImage]
at:NSMakePoint(0, 0)
offset:NSMakeSize(0, 0)
event:theEvent
pasteboard:pboard
source:self
slideBack:YES];
}
}
- (void)pasteboard:(NSPasteboard *)sender provideDataForType:(NSString
*)type {
if ([type isEqual:NSFileContentsPboardType]) { // never gets called.
NSData *data = [self createData];
NSFileWrapper *wrapper = [[[NSFileWrapper alloc]
initRegularFileWithContents:data] autorelease];
[wrapper setPreferredFilename:@"draggedData"];
[sender writeFileWrapper:wrapper];
} if ([type isEqual:NSFileContentsPboardType]) { // never gets
called.
// do same as above, but write out the file wrapper to a temp
directory
}
}
//- (unsigned int)draggingSourceOperationMaskForLocal:(BOOL)flag {
return NSDragOperationCopy;
}
Thanks for any help!
Jesse Grosjean