Re: Replacing the standard NSTextAttachmentCell in an NSTextView
Re: Replacing the standard NSTextAttachmentCell in an NSTextView
- Subject: Re: Replacing the standard NSTextAttachmentCell in an NSTextView
- From: Andre <email@hidden>
- Date: Wed, 7 Nov 2007 09:22:40 +0900
Thank you Douglas for your reply.
On 平成 19/11/07, at 2:10, Douglas Davidson wrote:
On Nov 6, 2007, at 6:34 AM, email@hidden 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.
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.
Well, since I am using Core Data to represent the attachments in the
text view, I have decided to copy the URI's of the objects to the clip
board (one for each text attachment) using the delegate method
textView:writeCell:atIndex:toPasteboard:type:. The objects will have a
string value, so I'm thinking I can, when pasting to the pasteboard,
paste the URL and its text value, then when pasting back, I can read
the URI and check if its a coredata URI (NSURL).
The tricky part for me is, when geting the pasteboard data, when its
pasted back (copy and paste into the same custom text view), I would
like to make sure those coredata objects are represented with my
special NSCell subclass. So what I'm curious is: in
readSelectionFromPasteboard:type: , does it call this for each
attachment, or once on a per-paste operation basis?
What I'm hoping I can do is, when the text is pasted back, I can do
the following:
Ignore plain text and let the text view paste it in
When it encounters an attachment, it calls
readSelectionFromPasteboard:type: for each attachment
I can then call -rangeForUserTextChange and insert each NSCell at the
given insertion point for the attachment....
Ideally, a finer grained method such as:
- (NSCell *)textView:(NSTextView *)aTextView
customCellRepresentingItemFromPBoard:(NSPasteboard *)pboard ofType:
(NSString *)type atIndex:(NSUInteger)charIndex
Would be ideal........
Thanks for all you help. Its appreciated.
Andre
Douglas Davidson
_______________________________________________
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