Re: paragraph styles in NSTextView--help
Re: paragraph styles in NSTextView--help
- Subject: Re: paragraph styles in NSTextView--help
- From: Martin Wierschin <email@hidden>
- Date: Tue, 30 Dec 2008 13:44:31 -0800
I want to use different combinations of paragraph styles in
nstextview .
for example : combination of linespacing, paragraphspacing,
headindent and
tailindent . These all styles must be activated in a single
operation ,such
as in a single buttonclick etc.
You'll want to work with the text storage of the text view and apply
the paragraph styles to the text as necessary. Before you modify any
attributes of the storage you'll want to call
"shouldChangeTextInRange:replacementString:" and afterwards
"didChangeText" if you want undo and editing restrictions handled for
you. A single change would look something like this:
NSTextView* tv = GetMyTextView();
NSTextStorage* ts = [tv textStorage];
NSRange applyRange = NSMakeRange(0, [ts length]);
if( [tv shouldChangeTextInRange:applyRange replacementString:nil] ) {
// configure paragraph styles as desired and apply
NSMutableParagraphStyle* paraStyle = [[[NSParagraphStyle
defaultParagraphStyle] mutableCopy] autorelease];
[paraStyle setHeadIndent:6];
[ts addAttribute:NSParagraphStyleAttributeName value:paraStyle
range:applyRange];
[tv didChangeText];
}
You can apply as many distinct styles to different paragraphs as you
see fit by changing the NSRange.
~Martin
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please 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