NSTextAttachment

  • Is there any way to have an NSTextView to hold text and custom data-widgets that are unrelated to filewrappers? I don't want NSTextAttachmentCell I think, because without a file it doesn't work, without tricking around it does not go in and out of the pasteboard, and NSTokenAttachment is some private API thing. I need to be able to have placeholder fields in a textview that are based on NSCell or can be own views. Is there really nothing available? I don't have the capacity to write an entire layout editor like pages for that neither.

    Thanks
  • On Jul 16, 2012, at 2:15 PM, Alexander Reichstadt <lxr...> wrote:

    > Is there any way to have an NSTextView to hold text and custom data-widgets that are unrelated to filewrappers? I don't want NSTextAttachmentCell I think, because without a file it doesn't work

    I have used NSTextAttachmentCell for things that are not files. Note the comment in NSTextAttachment.h that says "An NSTextAttachment *usually* has a fileWrapper" (emphasis mine). It doesn't *have* to have one.

    Unfortunately it's been enough years that I don't remember the details. It may be that you can initialize an NSTextAttachment with a nil fileWrapper, or to set the fileWrapper property to nil after initialization. If not, you may just be able to pass in an arbitrary path to some file, and then the NSTextAttachmentCell methods such that they don't care what the file is.

    —Jens
  • There is a blog that outlines how to do this with help of Douglas Davidson:
    http://www.dejal.com/blog/2007/11/cocoa-custom-attachment-text-view

    The suggestion here is to use a textStorage delegate to insert the custom attachment cell into the text. It actually relies on what seems like a bug:

    if ([attachment isKindOfClass:[NSTextAttachment class]] &&
                    ![[attachment attachmentCell] isKindOfClass:[TATextAttachmentCell class]])
                {


    This is happening in

    - (void)textStorageWillProcessEditing:(NSNotification *)note

    What I don't understand is that before it's a TATextAttachment with a TATextAttachmentCell, being my subclasses, and afterwards when pasting/dropping and looking at the debugger, the objects become NSTextAttachment and its cell respectively. Why? And how can I make it stop it from turning my subclasses into their superclasses?

    Am 16.07.2012 um 23:51 schrieb Jens Alfke:

    >
    > On Jul 16, 2012, at 2:15 PM, Alexander Reichstadt <lxr...> wrote:
    >
    >> Is there any way to have an NSTextView to hold text and custom data-widgets that are unrelated to filewrappers? I don't want NSTextAttachmentCell I think, because without a file it doesn't work
    >
    > I have used NSTextAttachmentCell for things that are not files. Note the comment in NSTextAttachment.h that says "An NSTextAttachment *usually* has a fileWrapper" (emphasis mine). It doesn't *have* to have one.
    >
    > Unfortunately it's been enough years that I don't remember the details. It may be that you can initialize an NSTextAttachment with a nil fileWrapper, or to set the fileWrapper property to nil after initialization. If not, you may just be able to pass in an arbitrary path to some file, and then the NSTextAttachmentCell methods such that they don't care what the file is.
    >
    > —Jens
previous month july 2012 next month
MTWTFSS
            1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31          
Go to today