NSAttributedString with NSTextTable Can not save with NSArchiver Suggestions
NSAttributedString with NSTextTable Can not save with NSArchiver Suggestions
- Subject: NSAttributedString with NSTextTable Can not save with NSArchiver Suggestions
- From: Kenneth Lichtenberger <email@hidden>
- Date: Sat, 17 Mar 2007 17:52:21 -0700 (PDT)
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:
This email sent to email@hidden