Skip navigation.
 
mlRe: Custom attachment in a text view
FROM : Douglas Davidson
DATE : Tue Nov 06 23:09:28 2007

On Nov 6, 2007, at 1:59 PM, David Sinclair wrote:

> For the first problem, the recommended solution seems to be to 
> subclass NSTextView to override -readablePasteboardTypes, -
> writablePasteboardTypes, -readSelectionFromPasteboard:type:, etc to 
> add the new pasteboard type.  Which works, mostly, except my 
> implementation mangles the text if dragging a block of text 
> containing my custom attachment, as opposed to the attachment by 
> itself (which works fine).  I'm not sure how to handle the former 
> case.
>
> I haven't solved the second problem, of my custom attachments 
> vanishing when the text is saved to the data store.  Looking at the 
> NSTextStorage contents after inserting it, the attachment is there, 
> but it seems to be stripped out when saving (by encoding as data for 
> a binary Core Data attribute).  Inserting an image attachment is 
> saved correctly, though.  Which makes me think I need to encode the 
> attachment somehow, but an -encodeWithCoder: method in the cell 
> isn't called.  Do I need to create a temporary file and use a file 
> wrapper (the attachment currently passes nil for -
> initWithFileWrapper:)?  That didn't seem to help, but maybe I didn't 
> do it right.


Here's what I sent to this list in response to another question 
earlier today:

"The issue here has to do with the formats used to store text on the 
pasteboard.  Copy/paste can potentially take place between any two 
applications, so the pasteboard generally uses application-independent 
formats for the interchange of data.  In this case, attachments are 
stored for pasteboard purposes as file contents.  One option for you 
is to decide on a file format to represent the contents of your custom 
attachments, and use that as the contents of the file wrapper for copy/
paste purposes.  In this, you should consider what you want to happen 
when text is copied and pasted from your application to another 
application--is there some suitable representation for your custom 
attachments that other applications would understand?  Your 
application could then recognize these files by some means--by 
contents, or perhaps by extension--when they are pasted in, and 
substitute your custom attachment."

This would be applicable to your question about dragging or copy/
pasting a block of text containing your custom attachment.  Your 
second question is probably the same problem, since it has to do with 
the storage of text in persistent formats.

Douglas Davidson

Related mailsAuthorDate
mlCustom attachment in a text view David Sinclair Nov 6, 22:59
mlRe: Custom attachment in a text view Douglas Davidson Nov 6, 23:09
mlRe: Custom attachment in a text view David Sinclair Nov 13, 06:37