• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Drag and drop onto the desktop?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


  • Prev by Date: NSNotificationCoalescingOnName | NSNotificationCoalescingOnSender
  • Next by Date: Re: Finder Show Info Comments
  • Previous by thread: NSNotificationCoalescingOnName | NSNotificationCoalescingOnSender
  • Next by thread: Re: Drag and drop onto the desktop?
  • Index(es):
    • Date
    • Thread