RE: NSTextView - custom pasteboard types and text table issues
RE: NSTextView - custom pasteboard types and text table issues
- Subject: RE: NSTextView - custom pasteboard types and text table issues
- From: Keith Blount <email@hidden>
- Date: Mon, 23 Jan 2006 11:31:14 -0800 (PST)
This is driving me nuts. Very clearly, the usual
NSAttributedString and NSText RTFD/RTF methods cause
issues when copying and pasting parts of a text table,
so NSTextView must do some extra stuff in its paste
methods to get around this, but I have no idea what.
To see what I mean, subclass NSTextView and override
-writeSelectionToPasteboard:type: as follows:
- (BOOL)writeSelectionToPasteboard:(NSPasteboard
*)pboard type:(NSString *)type
{
if (![type isEqualToString:NSRTFDPboardType] &&
![type isEqualToString:NSRTFPboardType])
return [super writeSelectionToPasteboard:pboard
type:type];
NSData *pboardData;
if ([type isEqualToString:NSRTFDPboardType])
{
pboardData = [[self textStorage] RTFDFromRange:[self
selectedRange]
documentAttributes:nil];
}
else
{
pboardData = [[self textStorage] RTFFromRange:[self
selectedRange]
documentAttributes:nil];
}
return [pboard setData:pboardData forType:type];
}
(Yes, I know you wouldn't normally want to do this,
but I need to customise RTFD and RTF copying to deal
with custom attributes that can be pasted as footnotes
and comments.)
Now add a table to the document. Copy the text from
one of the cells and paste it into another cell (or
anywhere for that matter). Compare that with the
default behaviour in TextEdit. Very strange.
For anyone kind enough to check this out, here is a
sample project showing this:
http://www.rumramruf.com/ScrivenerBeta/TextPasteTest.zip
(This also shows the problem whereby border
information can be lost when archiving and unarchiving
text with a table in it, leading me to suspect that
NSCoding has not been fully implemented for the new
text table parts of NSAttributedString...)
I'll file a bug with Apple, but given that this is
something that is unlikely to be fixed any time soon,
I would be very grateful to anybody who could point me
in the direction of a "fix" to get default behaviour
when using my own custom paste types.
Many thanks in advance,
Keith
---- ORIGINAL MESSAGE ----
Hi,
I've implemented my own custom pasteboard type for
NSTextView by subclassing it and overriding
-writeSelectionToPasteboard:type:,
-readSelectionFromPasteboard:type: and the other
relevant methods, but it seems that no matter what I
do, tables get screwed up (by "tables", I mean the
text tables introduced in 10.4 which can be added via
-orderFrontTablePanel:). I'm adding my own custom
pasteboard type because I use several custom
attributes - however, these attributes don't have to
exist for the problems I am seeing to arise.
To add to the pasteboard, all I am doing is getting an
attributed substring of the text storage based on the
selection range (or ranges) and then adding it to the
pasteboard as data. Problems:
- If I just archive the attributed string using
NSKeyedArchiver, the border attributes of tables get
lost, so that when I paste it again, the table has
white borders except for the bottom one. Strange.
- Even if I use -RTFDFromRange:documentAttributes: to
store my string (as an experiment to see if I was
missing something obvious), I get weird results -
table cell data seems to get copied, so that if I copy
some text from a table cell and pass it into another
table cell, a newline gets added, or I get a cell
within a cell. Given that this doesn't happen in the
default implementation, I am guessing that NSTextView
does some extra magic to maybe strip table attributes
in these methods (?).
I don't really know what's going on here. These
problems only arise when a table is present in the
text. Given that tables were only introduced in Tiger,
maybe there's still some screwiness there...? If
anyone has any ideas, I would be very grateful.
Many thanks in advance for your help,
Keith
__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com
_______________________________________________
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