Bug in 10.6 NSPasteboard API? (was: 10.6 NSPasteboard API mixes up types?)
Bug in 10.6 NSPasteboard API? (was: 10.6 NSPasteboard API mixes up types?)
- Subject: Bug in 10.6 NSPasteboard API? (was: 10.6 NSPasteboard API mixes up types?)
- From: Peter <email@hidden>
- Date: Mon, 27 Feb 2012 09:44:32 +0100
I am still very much puzzled by the issue I described below, so I still hope to find a taker for it.
While the OS 10.5 API cleanly separated pasteboard types, the 10.6 API converts NSURL data to strings and adds it to any existing string data - i.e. when pasting the data into e.g. a text view in 10.6 I get
file://localhost/Users/peterjhartmann/Desktop/Eigene Bilder/jan.jpg
file://localhost/Users/peterjhartmann/Desktop/Eigene Bilder/Nob.jpg
jan
Nob
instead of
jan
Nob
which is the result using the 10.5 API. As described, this happens no matter wether I use writeObjects: or setString: and no matter wether I write the URLs before or after the strings.
I consider this to be a bug. Am I wrong? If so, what am I doing wrong?
Does anybody use the 10.6 pasteboard API? Judging from my web searches it seems that almost nobody does.
One member contacted my privately stating ...
> Not sure if you've fixed this or had any other replies, but in reading it through, I notice you're not declaring the pasteboard type ([pb declareTypes:...]) within this block. Does this explain the symptoms?
but declareTypes belongs to the old API. Mixing this with the new API is discouraged on p. 33 of Apple's PasteboardGuide106.pdf.
I'd be very happy about any pointers into the right direction.
My original post is here:
Am 19.02.2012 um 21:24 schrieb Peter:
> I am using the following code:
>
> NSPasteboard *pb = [NSPasteboard generalPasteboard];
>
> if (floor(NSAppKitVersionNumber) <= NSAppKitVersionNumber10_5) {
> //linesArray contains file paths as NSStrings
> //namesArray contains file names as NSStrings
> [pb declareTypes:[NSArray arrayWithObjects:NSFilenamesPboardType, NSStringPboardType, nil] owner:nil];
> [pb setPropertyList:linesArray forType:NSFilenamesPboardType];
> [pb setString:[namesArray componentsJoinedByString:@"\n"] forType:NSStringPboardType];
> }
> else { // >= 10.6
> //linesArray contains NSURLs
> //namesArray contains file names as NSStrings
> [pb clearContents];
> [pb setString:[namesArray componentsJoinedByString:@"\n"] forType:NSPasteboardTypeString];
> //[pb writeObjects:namesArray];
> [pb writeObjects:linesArray]; // write the URLs
> }
>
> The 10.5 code results in distinct entities for both of the pasteboard types as I expected.
>
> type: 'public.utf8-plain-text'
> 'aaa.bbb.ccc'
>
> The 10.6 code results in the following:
>
> type: 'public.utf8-plain-text'
> 'aaa.bbb.ccc.file'
> '://localhost/Use'
> 'rs/peterjhartman'
> 'n/Desktop/aaa.fl'
> 'v.file://localho'
> 'st/Users/peterjh'
> 'artmann/Desktop/'
> 'bbb.flv.file://l'
> 'ocalhost/Users/p'
> 'eterjhartmann/De'
> 'sktop/ccc.flv'
>
> For reasons beyond my comprehension the NSURLs are converted to string data behind my back and added to the existing string data, no matter wether I use writeObjects or setString.
>
> NSFilenamesPboardType contains identical property list of three file paths for this example in both code branches.
>
> '<?xml version="1'
> '.0" encoding="UT'
> 'F-8"?>.<!DOCTYPE'
> ' plist PUBLIC "-'
> '//Apple//DTD PLI'
> 'ST 1.0//EN" "htt'
> 'p://www.apple.co'
> 'm/DTDs/PropertyL'
> 'ist-1.0.dtd">.<p'
> 'list version="1.'
> '0">.<array>..<st'
> 'ring>/Users/pete'
> 'rjhartmann/Deskt'
> 'op/aaa.flv</stri'
> 'ng>..<string>/Us'
> 'ers/peterjhartma'
> 'nn/Desktop/bbb.f'
> 'lv</string>..<st'
> 'ring>/Users/pete'
> 'rjhartmann/Deskt'
> 'op/ccc.flv</stri'
> 'ng>..<string></s'
> 'tring>..<string>'
> '</string>.</arra'
> 'y>.</plist>.'
>
> Interestingly, I see file paths where I would expect file urls on 10.6.
>
> What am I possibly doing wrong?
> How could I avoid this?
>
> Thank you for any pointers!
>
> Peter
> _______________________________________________
>
> Cocoa-dev mailing list (email@hidden)
>
> Please do not post admin requests or moderator comments to the list.
> Contact the moderators at cocoa-dev-admins(at)lists.apple.com
>
> Help/Unsubscribe/Update your Subscription:
>
> This email sent to email@hidden
>
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden