Drag&Drop programming 3 : More accurate explanation on NSCreateFilenamePboardType()

Information mentioned before, especially in a post, Drag&Drop Programming 2 : Difference between Cocoa app and Carbon app, is not explained in Apple’s document.

Although the returned string,NSFilenamesPboardType:mov, by NSCreateFilenamePboardType(@”mov”), looks similar to NSFilenamesPboardType, it seems that its purpose is totally different. It creates no flavors, while NSFilenamesPboardType creates ‘fURL‘ and ‘hfs‘ flavors from a given file URL.

Using NSCreateFileContentsPboardType() function in Dragging File Contents makes people think that NSCreateFilenamePboardType() is for narrowing down the usage of NSFilenamesPboardType to a specific type. But actually it is not.

Then how to solve the problem shown in my previous post?
The file path, described in the documentation, sounds a general term. So, it can be “/Volumes/Users/….”. If this path is used for NSFilenamesPboardType, it generates a correct ‘fURL’, but there is no type information for ‘hfs’ data.
Then.. what’s wrong? There is no way to add or modify flavors in Cocoa. Furthermore, flavor related Carbon calls are deprecated.

It turned out that the correct file path form was “file://localhost/Volumes/…”. Then it generates correct ‘hfs’ as well as ‘fURL’.

Sample code is shown below.

NSArray *pboardTypes = [NSArray arrayWithObject:NSFilenamesPboardType];

[pboard declareTypes:[NSArray arrayWithObject:NSFilenamesPboardType] owner:nil];

[pboard setPropertyList:[NSArray arrayWithObject:@"file://localhost/Volumes/"] forType:NSFilenamesPboardType];

Lots of things are being changed for D&D in Carbon, so less-changing Cocoa is a better option to take in my own opinion, and it was good to figure out how to use it correctly.
I hope Apple would write more accurate and less-ambiguous document.


Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: