Skip navigation.
 
mlRe: Replacing the standard NSTextAttachmentCell in an NSTextView
FROM : Douglas Davidson
DATE : Tue Nov 06 18:10:53 2007

On Nov 6, 2007, at 6:34 AM, <email_removed> wrote:

> I'm currently researching how to provide a custom NSCell to replace 
> the current NSTextAttachentCell in an NSTextView.
> The reason is that I want to have a different type of attachment not 
> just for images or file objects, but for actual objects in my 
> application.
> IOW, something similar to NSTokens (actually I'm using an 
> NSTokenFieldCell subclass) that can represent  actual "objects" in a 
> text field...
>
> So, I have insertion working, and the cell fulfills the basic 
> protocol for NSTextAttachment.
> The problem is, when cutting and pasting my object back into the 
> text field, it reverts to a standard NSTextAttachmentCell....
> How can I override this to insert my special cell?
> The problem I am running into is that the NSTextAttachment requires 
> an NSFileWrapper, but since I am not representing a file object, I 
> tested it out using:
> NSTextAttachment *textAttachment = [[NSTextAttachment alloc] 
> initWithFileWrapper:nil];
> In the above case, paste then doesn't even work....


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.

Douglas Davidson

Related mailsAuthorDate
mlReplacing the standard NSTextAttachmentCell in an NSTextView listposter Nov 6, 15:34
mlRe: Replacing the standard NSTextAttachmentCell in an NSTextView Douglas Davidson Nov 6, 18:10
mlRe: Replacing the standard NSTextAttachmentCell in an NSTextView Andre Nov 7, 01:22