Re: NSTextView & NSTextTable Archiving/Unarchiving
Re: NSTextView & NSTextTable Archiving/Unarchiving
- Subject: Re: NSTextView & NSTextTable Archiving/Unarchiving
- From: Douglas Davidson <email@hidden>
- Date: Mon, 9 Apr 2007 13:43:11 -0700
On Apr 9, 2007, at 1:13 PM, Brace, Andy (DEX-OMA) wrote:
I'm looking for a way to archive/unarchive an NSTextView with
text table data.
Currently I NSKeyedArchive/NSKeyedUnarchive the NSTextStorage of
the NSTextView. This restores the table data and some of the table
formatting (#columns, #rows, alignments, border color & background
color), but loses the border weight, cell widths/heights.
Is there another way of saving & restoring this data? Or am I
just missing something?
This is a known and previously discussed bug in NSTextBlock keyed
unarchiving that has been fixed in Leopard.
Here are some possible workarounds: (a) used non-keyed archiving;
(b) archive some additional data along with the blocks (e.g., add an
attribute whose value is an NSData, obtained by non-keyed archiving
the block) and use it to fix them up afterwards; (c) implement
something like the code shown below in a posing subclass (this should
be safe even after our fix makes it out).
Douglas Davidson
static NSLock *unarchivingTextBlockLock = nil;
static CFMutableSetRef unarchivingTextBlockSet = NULL;
- (id)initWithCoder:(NSCoder *)coder {
if (!unarchivingTextBlockLock) unarchivingTextBlockLock =
[[NSLock alloc] init];
[unarchivingTextBlockLock lock];
if (!unarchivingTextBlockSet) unarchivingTextBlockSet =
CFSetCreateMutable(NULL, 0, NULL);
CFSetAddValue(unarchivingTextBlockSet, (const void *)self);
[unarchivingTextBlockLock unlock];
self = [super initWithCoder:coder];
[unarchivingTextBlockLock lock];
CFSetRemoveValue(unarchivingTextBlockSet, (const void *)self);
[unarchivingTextBlockLock unlock];
return self;
}
- (void)_createFloatStorage {
BOOL create = YES;
if (_propVals) {
[unarchivingTextBlockLock lock];
if (unarchivingTextBlockSet && CFSetContainsValue
(unarchivingTextBlockSet, (const void *)self)) create = NO;
[unarchivingTextBlockLock unlock];
}
if (create) [super _createFloatStorage];
}
_______________________________________________
Cocoa-dev mailing list (email@hidden)
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