Custom NSAttachmentCell (save/copy/paste)
Custom NSAttachmentCell (save/copy/paste)
- Subject: Custom NSAttachmentCell (save/copy/paste)
- From: "Falko A." <email@hidden>
- Date: Thu, 14 Sep 2006 12:16:33 +0200
Hi,
first of all, thx for the answers on my previous question.
I'm trying to implement a custom NSAttachmentCell to insert a button
into a TextView.
Inserting and displaying the attachment (currently just a black rect)
works fine, but I don't know
what to do to be able to save the text or copy it to the clipboard.
I know I'd have to use a NSFileWrapper to store the data for an
attachment, but currently, it
doesn't contain any data that has to be displayed and it still can't
be copied, nor saved.
The file format is a NSDictionary containing the textStorage of the
NSTextView which is then
archived.
If I open the file, the text still seems to contain an attachment of
zero length, but it doesn't
recognize the type of the attachment... So, it doesn't display anything.
How can I save the attachment information in the file as an
AttributedString?
Also, why doesn't copy&paste work (all attachments are removed from
the inserted text)?
Since I'm not (yet) storing any data in the attachment, it should
work without a NSFileWrapper, shouldn't it?
When storing data in the attachment, how could the AttachmentCell
access the data in the FileWrapper?
I already searched the net, but couldn't find any info :(
Is there any sample code out there for doing such things?
Here's the code I'm currently using:
/* insert attachment: */
{
NSTextAttachment *attachment = [[NSTextAttachment alloc]
initWithFileWrapper:nil];
SimpleTag *aCell = [[SimpleTag alloc] init];
[attachment setAttachmentCell:cell];
[myTextView insertText:[NSAttributedString
attributedStringWithAttachment:attachment]];
[aCell release];
[attachment release];
}
/* the attachment cell: */
@implementation SimpleTag
- (NSRect)cellFrameForTextContainer:(NSTextContainer *)
textContainer proposedLineFragment:(NSRect)lineFrag glyphPosition:
(NSPoint)position characterIndex:(unsigned)charIndex
{
return NSMakeRect(0, 0, 10, 10);
}
- (void)drawWithFrame:(NSRect)cellFrame inView:(NSView *)
controlView characterIndex:(unsigned)charIndex layoutManager:
(NSLayoutManager *)layoutManager
{
[[NSColor blackColor] set];
NSRectFill(cellFrame);
}
@end
Thanks in advance,
Falko
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden