Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSFilePromisePboardType




On Dec 14, 2004, at 5:23 PM, Fredrik Olsson wrote:

Is there sample code anywhere where NSFilePromisePboardType is used?

I believe there was for Session 411 at WWDC 2004...

In brief:

In your view class you implement -mouseDragged: and -namesOfPromisedFilesDroppedAtDestination:.

For example, to support dragging a PDF file from a view:

- (void)mouseDragged:(NSEvent *)theEvent
{
	//...
   	[self dragPromisedFilesOfTypes:[NSArray arrayWithObject:@"pdf"]
			fromRect:imageLocation
			source:self
			slideBack:YES
			event:dragEvent];
	// dragEvent is the event that initiated the drag
	// e.g. a copy of the event in -mouseDown:
	//...
}



- (NSArray *)namesOfPromisedFilesDroppedAtDestination:(NSURL *)dropDestination
{


    NSString *filename = [self filenameForPath:[dropDestination path]];

    // Create the data representation of the view
    NSData *data = [self dataWithPDFInsideRect:[self bounds]];

    // Write the data to a file located in the given drop destination.
    NSURL *fileURL = [[NSURL alloc] initWithString:filename
						relativeToURL:dropDestination];
    [data writeToURL:fileURL atomically:YES];
    [fileURL release];
	
    // Return an array of file names for the created files
    return [NSArray arrayWithObject: filename];
}


As a user-friendly feature, -filenameForPath: takes the drop destination path, determines the required filename, looks to see if a file of that name already exists at the drop destination; if it does, adds a suffix (e.g. "filename-1"), repeats if necessary ("filename-2", "filename-3"...); then returns a string representing filename.


mmalc
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/email@hidden

This email sent to email@hidden
References: 
 >NSFilePromisePboardType (From: Fredrik Olsson <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.