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 (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to