• 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
Re: NSFilePromisePboardType
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSFilePromisePboardType


  • Subject: Re: NSFilePromisePboardType
  • From: mmalcolm crawford <email@hidden>
  • Date: Tue, 14 Dec 2004 18:33:29 -0800


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:
This email sent to email@hidden


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

  • Prev by Date: Re: Kill other process's warning dialog
  • Next by Date: Prevent default alert when quitting app w/ many unsaved docs
  • Previous by thread: Re: NSFilePromisePboardType
  • Next by thread: Prevent default alert when quitting app w/ many unsaved docs
  • Index(es):
    • Date
    • Thread