Re: Saving ruler markers to defaults [SOLVED]
Re: Saving ruler markers to defaults [SOLVED]
- Subject: Re: Saving ruler markers to defaults [SOLVED]
- From: Jeremy Dronfield <email@hidden>
- Date: Tue, 20 Aug 2002 18:35:45 +0100
On Monday, August 19, 2002, at 10:01 pm, Douglas Davidson wrote:
On Monday, August 19, 2002, at 01:39 PM, Jeremy Dronfield wrote:
Well, I'm fine with archiving, if only I knew how get the paragraph
style in the first place. Sorry to be a pest about this, but I've been
through every attributed string, text, layout and view document I can
think of, and nowhere can I find a method which returns the paragraph
style of a piece of text. How do you do it?
It's the value of the NSParagraphStyleAttributeName attribute on an
attributed string--in particular, if you have an NSTextView, the
relevant attributed string is the text view's textStorage. If the
value of the attribute is nil, that means the default paragraph style
is in effect.
Thanks. I've hammered out some code which does the trick. It saves and
subsequently applies paragraph indents and tab settings. Just for the
record, since this seems to have been an unusual request and involves
concepts and methods which are spread over several thinly described
classes (and also in case you'd be kind enough to glance over it and
offer any criticisms), this is what I've done:
In -applicationWillTerminate,
NSRange effectiveRange = NSMakeRange(0, 0);
[prefs setObject:[NSArchiver archivedDataWithRootObject:[[textView
textStorage] attribute:NSParagraphStyleAttributeName
atIndex:NSMaxRange(effectiveRange) effectiveRange:&effectiveRange]]
forKey:@"Para Style"];
In -applicationDidFinishLaunching,
NSParagraphStyle *paraStyle;
paraStyle = [self paraStyleForKey:@"Para Style"];
[[textView textStorage] addAttribute:NSParagraphStyleAttributeName
value:paraStyle range:NSMakeRange(0, [[textView string] length])];
And my unarchiving method,
- (NSParagraphStyle *)paraStyleForKey:(NSString *)value
{
return [NSUnarchiver unarchiveObjectWith
Data:[prefs
dataForKey:value]];
}
Thanks again.
-Jeremy
=======================================
email@hidden // email@hidden
The Alchemy Pages:
- fractious fiction at
http://freespace.virgin.net/jeremy.dronfield
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.