• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
NSAttributedString with NSTextTable Can not save with NSArchiver Suggestions
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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

  • Prev by Date: Re: Does willChange:valuesAtIndexes:forKey: work correctly?
  • Next by Date: Plugin Architecture + Core Data, Undo Manager
  • Previous by thread: Re: Getting NSException on NSManagedObjectContext save:
  • Next by thread: Plugin Architecture + Core Data, Undo Manager
  • Index(es):
    • Date
    • Thread