Re: NSFilePromisePboardType
Re: NSFilePromisePboardType
- Subject: Re: NSFilePromisePboardType
- From: The Karl Adam <email@hidden>
- Date: Wed, 15 Dec 2004 01:44:09 -0500
You can put the files on the pasteboard and declare the
NSFilesPBoardType IF you read the docs correctly, but here is some
code that works in one of my apps. The first part puts the "files" on
the pasteboard the second set override some of the default drag
handling, if you find bugs/make improvements feel free to drop me an
email. This code was orignally written to add support for these
features to Table/OutlineViews so you'll have to copy/paste the
innards of the first method.
- (BOOL) outlineView:(NSOutlineView *)inOutlineView
writeItems:(NSArray *)inItems toPasteboard:(NSPasteboard
*)inPasteboard {
NSLog ( @"Array - %@\nPasteboard - %@", inItems, inPasteboard );
NSMutableArray *fileTypes = [NSMutableArray arrayWithCapacity:[inItems count]];
NSEnumerator *typeEnum = [inItems objectEnumerator];
id filename = nil;
while ( filename = [typeEnum nextObject] ) {
if ( [filename isKindOfClass:[NSArray class]] ) filename = [filename
objectAtIndex:0];
NSString *type = [[(DCSearchResponse *)filename filename] pathExtension];
if ( [type length] == 0 ) type = NSFileTypeForHFSTypeCode( 'fold' );
[fileTypes addObject:type];
}
[inPasteboard declareTypes:[NSArray
arrayWithObjects:NSFilesPromisePboardType, nil] owner:self];
[inPasteboard setPropertyList:fileTypes forType:NSFilesPromisePboardType];
return YES;
}
----- This is from the View subclass I have
#pragma mark Dragging Overloads to support interapp drops and File Promises
- (unsigned int) draggingSourceOperationMaskForLocal:(BOOL)isLocal {
return NSDragOperationNone|NSDragOperationCopy|NSDragOperationLink|NSDragOperationGeneric;
}
- (void)dragImage:(NSImage *)anImage at:(NSPoint)imageLoc
offset:(NSSize)mouseOffset event:(NSEvent *)theEvent
pasteboard:(NSPasteboard *)pboard source:(id)sourceObject
slideBack:(BOOL)slideBack {
// FINALLY!!
// Okay HFS File promises work through a bit of black magic,
// I have h4x0red into it without revealing too much of it's workings here
// I should edit this later to maintain whatever other info was on the pboard
if ( [[pboard types] containsObject:NSFilesPromisePboardType] ) {
NSArray *promisedTypes = [[pboard
propertyListForType:NSFilesPromisePboardType] retain];;
NSFilePromiseDragSource *aFSource = [[[NSFilePromiseDragSource
alloc] initWithSource:sourceObject] autorelease];
[pboard declareTypes:[NSArray
arrayWithObjects:NSFilesPromisePboardType, @"CorePasteboardFlavorType
0x70686673", @"CorePasteboardFlavorType 0x66737350",
@"NSPromiseContentsPboardType", nil] owner:aFSource];
// Construct the HFS Flavor for the Finder to use on Drop
PromiseHFSFlavor aFlavor;
memset( &aFlavor, 0, sizeof(aFlavor) );
if ( [promisedTypes containsObject:@"'fold'"] ) aFlavor.fileType = 'fold';
aFlavor.fileCreator = '????';
aFlavor.promisedFlavor = 'fssP';
NSData *flavorData = [NSData dataWithBytes:&aFlavor length:14];
[pboard setPropertyList:promisedTypes forType:NSFilesPromisePboardType];
[pboard setData:flavorData forType:@"CorePasteboardFlavorType 0x70686673"];
// Cleanup
[promisedTypes release];
}
//NSLog( @"data from CFPBTypes: %@, %@, %@", [pboard
dataForType:@"CorePasteboardFlavorType 0x70686673"], [pboard
dataForType:@"CorePasteboardFlavorType 0x66737350"],
NSStringFromClass( [[pboard
dataForType:@"NSPromiseContentsPboardType"] class] ) );
[super dragImage:anImage at:imageLoc offset:mouseOffset
event:theEvent pasteboard:pboard source:sourceObject
slideBack:slideBack];
}
-Karl
On Tue, 14 Dec 2004 18:43:10 -0700, Nick Zitzmann <email@hidden> wrote:
>
> On Dec 14, 2004, at 6:23 PM, Fredrik Olsson wrote:
>
> > 1. Finder do not not accept drops at all, that goes for other targets
> > as well that should accepts simple string drops.
> > 2. namesOfPromisedFilesDroppedAtDestination: i never invoked.
> >
> > Is there sample code anywhere where NSFilePromisePboardType is used?
>
> Not that I'm aware of. Are you trying to set a pasteboard to use the
> NSFilePromisePboardType as one of its declared types? If so, that won't
> work; you _must_ use the -dragPromisedFilesOfTypes:... method provided
> by NSView to initiate a file-promise drag. I hope you're not using a
> table view as a drag source...
>
> Can you show us what you're trying to do?
>
> Nick Zitzmann
> <http://www.chronosnet.com/>
>
> _______________________________________________
> 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
>
_______________________________________________
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