Re: Insert NSImage into NSTextView
Re: Insert NSImage into NSTextView
- Subject: Re: Insert NSImage into NSTextView
- From: Jeremy Dronfield <email@hidden>
- Date: Mon, 31 May 2004 21:02:09 +0100
On 31 May 2004, at 5:51 pm, Matt Ball wrote:
Although it does get
inserted, the app doesn't see the document as edited.
Methods which manipulate the text storage directly don't dirty the
document. Try sending your text view a -didChangeText after you append
your attributed string.
Secondly, and
this is probably a similar problem, the app will not let me drag the
image to other places in the textView to move it like I can with images
that have been dragged in. When I try to drag it, my Run window says:
-[NSTextView concludeDragOperation:]: Failed to read from drag
pasteboard. Drag operation failed.
I doubt if this will cure the problem, but it will simplify your code a
little. Instead of creating an attachment cell and then adding it to
your attachment, try this:
NSTextAttachment *attachment = [[NSTextAttachment alloc] init];
if ([(NSCell *)[attachment attachmentCell]
respondsToSelector:@selector(setImage:)])
[(NSCell *)[attachment attachmentCell] setImage:[imageView image]];
The NSCell cast will prevent a compiler warning, since the NSCell
method -setImage: isn't implemented in the NSTextAttachmentCell
protocol.
My guess as to what's going wrong with dragging is that the image
you're using is not a saved file. NSTextAttachment is set up to work
with attached files (-initWithFileWrapper: is the designated
initializer for NSTextAttachment). To get dragging to work with an
image without a file wrapper, you'll probably need to write the image
data to the pasteboard at the start of the drag operation.
Hope this helps. Regards,
-Jeremy
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.