• 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
Newbie, How to drag from a view to editors and the finder
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Newbie, How to drag from a view to editors and the finder


  • Subject: Newbie, How to drag from a view to editors and the finder
  • From: Nestor Cardozo <email@hidden>
  • Date: Thu, 21 Apr 2005 08:23:47 +0200

I am trying to implement a view as a dragging source. I want it to save to the pdf pasteboard when dragging to editor applications like text edit, keynote, etc., and to promise files when dragging to the finder.

I followed the documentation about how to do this, specially the notes:

“How Do I Set a Custom Drag Image When Doing an HFS Promise Drag in Cocoa?”
“How Do I Add Other Pasteboard Types to an HFS Promise Drag in Cocoa?”

In this notes, it is recommended to override <x-tad-bigger>dragImage:at:offset:event:pastboard:source:slideback: </x-tad-bigger> to set a custom image and to add other pasteboard types to an hfs promise drag. This is how my code looks:

- (void)dragImage:(NSImage *)anImage at:(NSPoint)imageLoc offset:(NSSize)mouseOffset
event:(NSEvent *)theEvent pasteboard:(NSPasteboard *)pboard

source:(id)sourceObject slideBack:(BOOL)slideBack
{
NSPasteboard *pb = [NSPasteboard pasteboardWithName:NSDragPboard];
[pb declareTypes:
[NSArray arrayWithObjects:NSPDFPboardType, NSFilesPromisePboardType, nil]
owner:self];
NSRect r = [self bounds];
NSData *data = [self dataWithPDFInsideRect:r];
[pb setData:data forType:NSPDFPboardType];
// Do I need to set or write the data from NSFilesPromisePboardType?
NSImage *theImage = [[[NSImage alloc] initWithSize:[self bounds].size] autorelease];
[theImage lockFocus];
[self drawRect:[self bounds]];
[theImage unlockFocus];
//
NSSize s = [theImage size];
s.width = s.width/4;
s.height = s.height/4;
[theImage setScalesWhenResized:YES];
[theImage setSize:s];
//
NSPoint p = [self convertPoint:[theEvent locationInWindow] fromView:nil];
p.x = p.x - s.width/2;
p.y = p.y - s.height/2;
//
[super dragImage:theImage
at:p

offset:NSMakeSize(0)
event:theEvent
pasteboard:pb
source:self
slideBack:YES];
}

Two questions:

Do I need to declare NSFilesPromisePboardType in my pasteboard? do I need to set the data or write the data to for the NSFilesPromisePboardType? as I did it for the NSPDFPasteboardType? If the latter is true, how do you do it?

I then override the mouseDragged: method. This is how the code looks:

- (void)mouseDragged:(NSEvent *)theEvent
{
//
NSImage *anImage = [[[NSImage alloc] initWithSize:[self bounds].size] autorelease];
//
NSSize s = [anImage size];
s.width = s.width/4;
s.height = s.height/4;
[anImage setSize:s];
//
NSPoint p = [self convertPoint:[theEvent locationInWindow] fromView:nil];
//
NSRect imageLocation;
imageLocation.origin = p;
imageLocation.size = s;
//
[self dragPromisedFilesOfTypes:[NSArray arrayWithObject:@"pdf"]
fromRect:imageLocation
source:self
slideBack:YES
event:theEvent];
}

which I think it is pretty standard. The <x-tad-bigger>dragPromisedFilesOfTypes:fromRect:source:slideBack:event: </x-tad-bigger>invokes the <x-tad-bigger>namesOfPromisedFilesDroppedAtDestination: </x-tad-bigger>method. This is how my view implements this method:

- (NSArray *)namesOfPromisedFilesDroppedAtDestination:(NSURL *)dropDestination
{
return[NSArray arrayWithObject:@"backstrip"];
}

The true is that I have no idea what to put in the array the <x-tad-bigger>namesOfPromisedFilesDroppedAtDestination: </x-tad-bigger>returns. What I want is that when I drag the file to the finder it creates a pdf file with the name backstrip. How do you do that? What should I include in the array (a string, a URL?). I found no documentation about this.

Currently I can drag the contents of my view to textedit, to illustrator, to easycrop, etc. (but not to keynote, do I need to do something special for that?). I can´t drag contents to the finder. I know I am missing something, I would really appreciate if you can help me. This seems to be obvious to many.

thanks for your help
 _______________________________________________
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

  • Follow-Ups:
    • Re: Newbie, How to drag from a view to editors and the finder
      • From: Nick Zitzmann <email@hidden>
  • Prev by Date: Re: Category or Protocol? (sidetrack)
  • Next by Date: problem with floats/floatForKey
  • Previous by thread: Re: OT: Which list to ask SearchKit usage questions?
  • Next by thread: Re: Newbie, How to drag from a view to editors and the finder
  • Index(es):
    • Date
    • Thread