Re: Drag to Finder and create a file
Re: Drag to Finder and create a file
- Subject: Re: Drag to Finder and create a file
- From: Lorenzo <email@hidden>
- Date: Mon, 11 Apr 2005 18:43:57 +0200
Hi.
Yes I have already seen those 2 "little" articles in the FAQ section.
> 1. How Do I Set a Custom Drag Image When Doing an HFS Promise Drag in
> Cocoa?
> 2. How Do I Add Other Pasteboard Types to an HFS Promise Drag in Cocoa?
But they say almost nothing. And it's not what I need to know because my
pasteboard has already the NSFilesPromisePboardType. I do that here:
- (BOOL)outlineView:(NSOutlineView*)olv writeItems:(NSArray*)items
toPasteboard:(NSPasteboard*)pboard
{
NSArray *myType = [NSArray arrayWithObject:NSFilesPromisePboardType];
[pboard declareTypes:myType owner:self];
NSArray *prom = [NSArray arrayWithObjects:@"ObjectFile.objf", nil];
[pboard setPropertyList:prom forType:NSFilesPromisePboardType];
}
And yes, if everything was easy, the life should be boring, you are right,
but it should be even sweeter and nicer because when you solve a problem in
a short time, you have time to do something else, so it's not boring... ;-)
Think about I am trying to address this issue for 3 days, unsuccessfully.
> The doc for that method says "The source may or may not have created
> the files by the time this method returns." So I assume there *is* a
> way to create them elsewhere/later, but I've never used promised drags
> so I'm not sure.
But, who should create the file? Me by myself as I have shown in the
namesOfPromisedFilesDroppedAtDestination call? Or the Finder automatically
because I pass it the proper flavour? This is not explained anywhere.
Think about, if I declare a pasterboard type NSTIFFPboardType, the Finder
creates a file automatically. Fine.
myTypes = [NSArray arrayWithObjects:NSTIFFPboardType, nil];
[pboard declareTypes:myTypes owner:self];
- (void)pasteboard:(NSPasteboard*)sender
provideDataForType:(NSString*)type
{
if([type compare:NSTIFFPboardType] == NSOrderedSame){
[sender setData:[mImage TIFFRepresentation]
forType:NSTIFFPboardType];
}
}
So why should I get crazy if I want to simply save NSData to a file with my
own filename?
Is anyone who knows more about Drag and Drop HFS Promised Files?
Or, can Apple include a magic wand together with the documentation? It
should help a lot of developers, I suppose. :-)
Best Regards
--
Lorenzo
email: email@hidden
> From: Serge Meynard <email@hidden>
> Date: Mon, 11 Apr 2005 10:27:30 -0400
> To: Lorenzo <email@hidden>
> Subject: Re: Drag to Finder and create a file
>
> On Apr 11, 2005, at 08:29, Lorenzo wrote:
>> Yes, thank you,
>> but how to implement "promised drags" properly?
>> I am getting crazy with that. There is no documentation about it.
>
> Yes there is, but unfortunately Apple's doc sometimes buries critical
> nuggets of info in dusty corners :)
>
>> So I did that and now the only place I can write the item data to a
>> file in
>> the Finder, seems to be within
>>
>> -(NSArray*)namesOfPromisedFilesDroppedAtDestination:
>> (NSURL*)dropDestination
>> {
>> // ...
>> NSData *itemData = [selectedItem GetItemData];
>> NSString *filename = [[dropDestination path]
>> stringByAppendingPathComponent:[selectedItem
>> objectName]];
>>
>> [itemData writeToFile:filename atomically:YES];
>>
>> return [NSArray arrayWithObject:[selectedItem objectName]];
>> }
>>
>> Even if this seems to be the only place where I can get the
>> destination URL,
>> it sounds so strange that I have to write the item-file within an API
>> returning namesOfPromisedFiles.... Or is it right?
>
> The doc for that method says "The source may or may not have created
> the files by the time this method returns." So I assume there *is* a
> way to create them elsewhere/later, but I've never used promised drags
> so I'm not sure.
>
>> Also, when I drag an item from the outlineView, if the destination is
>> the
>> outlineView itself, I don't have to create a file. I have just to move
>> the
>> item within the outline view. BUT, since I call
>> dragPromisedFilesOfTypes:
>> (see here above) to let the user drag the item to the Finder too, now
>> every
>> time I start a drag I see a white file icon and I cannot drag the item
>> within the outline view anymore. I can only drag it to the Finder.
>> Moreover, the API draggingSourceOperationMaskForLocal doesn't give me
>> any
>> info about the draggingPasteboard, so even if I override it, I cannot
>> change
>> the behaviour of the drag on the fly depending on the object is
>> overriding
>> the Finder or the object is overriding the outline view itself.
>> Amazing!
>
> The FAQ section in "Drag And Drop" has two short sections that you want
> to read:
>
> ³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?²
>
>> I am sure I am missing something important. But what?
>
> Hopefully the points above were it.
>
>> Why does this simple task is made so complicated?
>
> Because if everything was simple, life would be boring? ;)
>
> Serge
>
_______________________________________________
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