Custom attachment in a text view
Custom attachment in a text view
- Subject: Custom attachment in a text view
- From: David Sinclair <email@hidden>
- Date: Tue, 6 Nov 2007 13:59:38 -0800
Goal: drag a table row into a text view as a custom attachment.
Sounds simple, but it seems harder than it should be. It's easy
enough to create a custom attachment via a NSTextAttachmentCell
subclass, and dragging that (or programmatically inserting it) into
the text view is also easy... but that leaves two problems: dragging/
copying it gives an exception, and persisting it via Core Data makes
it vanish.
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.
I've searched the archives, and found several people with similar
questions, but no answers. If anyone has any advice or can point me
to sample code for this, I'd much appreciate it.
--
David Sinclair, Dejal Systems, LLC - email@hidden
Dejal blog - http://www.dejal.com/blog/
Cocoa code - http://www.dejal.com/developer/
Now on Twitter - http://twitter.com/dejal/
Attachment:
smime.p7s
Description: S/MIME cryptographic signature
_______________________________________________
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