Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

NSAttributedString with NSTextTable Can not save with NSArchiver Suggestions



Hello, and thank you for reading my post.

I am currently writing some That will save the
contents of a NSTextView to a file for reloading at a
later time.

I am trying to use NSArchiver to do this because i am
using NSTextTables with 	100% width.  Here is a
snippet of the code to generate the table to give you
a better idea of what i am doing:

	NSTextTableBlock *cell = [blocks lastObject];
	//[cell setBackgroundColor:[NSColor redColor]];
	NSTextTable *table = [cell table];
	[table setContentWidth:100.00
type:NSTextBlockPercentageValueType];


This will export to html nicely. But there is no way
that i can find to read it back into the view. 
Attempts to reload it form html result in the table
loading as fixed values. Reloading the data from rtf
will give width of 250%.

After Finding that thsi would not work i atempted to
NSArchiver to just save the object for relaoding
later.  To my dismay reloading reloadin the data
resulted in the table being compltyly omited.  all
other formating is perserved jut the tabes are
missing.
Here is a snippit of the code am useing to do this:

- (void) wrtiefile:(NSTextView*) view
{
	NSTextStorage *text = [view textStorage];
 
	NSAttributedString *string =
[NSMutableAttributedString alloc];
	[string initWithAttributedString:[view textStorage]];

	[NSArchiver archiveRootObject:string
toFile:@"/Users/ken_the_stp/Desktop/file.dat"];
	[string release];

}


- (void) readfile:(NSTextView*) view
{


	NSAttributedString *string =  [NSUnarchiver
unarchiveObjectWithFile:@"/Users/ken_the_stp/Desktop/file.dat"];
	NSTextStorage *myTextStorage = [view textStorage];
	NSRange charRange = [view rangeForUserTextChange];
	

	if ([view isEditable] && charRange.location !=
NSNotFound) 
	{
        if ([view shouldChangeTextInRange:charRange
replacementString:nil]) 
        {
			[myTextStorage replaceCharactersInRange:charRange
withAttributedString:string];
			[view
setSelectedRange:NSMakeRange(charRange.location, 0)
affinity:NSSelectionAffinityUpstream
stillSelecting:NO];
			[view didChangeText];
		}
	}
	
}


Any one Know what i am doing wrong.

_______________________________________________

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:
http://lists.apple.com/mailman/options/cocoa-dev/email@hidden

This email sent to email@hidden



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.