How do I remove all formatting (setUsesRuler:NO does not work) from an NSTextView?

  • I have an NSTextView that alternately displays RTF data and ASCII data.
    When the RTF data has been displayed, some aspects of it linger, mainly
    the ruler. When I display pure ASCII the text displays indented.

    I tried:

    [__inspectView setRichText:NO];
    [__inspectView setUsesRuler:NO];
    [__inspectView setFont:__fixedFont];

    but to no avail, the ASCII text is displayed indented. What am I missing
    here?

    Thanks,

    G
    _______________________________________________
    cocoa-dev mailing list | <cocoa-dev...>
    Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
    Do not post admin requests to the list. They will be ignored.
  • On Friday, September 20, 2002, at 04:25  pm, Gerben Wierda wrote:

    > I have an NSTextView that alternately displays RTF data and ASCII data.
    > When the RTF data has been displayed, some aspects of it linger, mainly
    > the ruler. When I display pure ASCII the text displays indented.
    >
    > I tried:
    >
    > [__inspectView setRichText:NO];
    > [__inspectView setUsesRuler:NO];
    > [__inspectView setFont:__fixedFont];
    >
    > but to no avail, the ASCII text is displayed indented. What am I
    > missing here?

    If I understand your problem correctly, replacing the above code with
    the following, which restores the default alignment
    (NSNaturalTextAlignment), ought to solve it:

    NSParagraphStyle *paraStyle = [NSParagraphStyle defaultParagraphStyle];

    [[__inspectView textStorage] addAttribute:NSParagraphStyleAttributeName
    value:paraStyle range:NSMakeRange(0, [[__inspectView string] length])];

    Note, it will only work if there is text in the view, but it should be
    easy enough to overcome this limitation. Hope this helps.
    -Jeremy

    ========================================
    <jeremy.dronfield...>  //  <jcdronfield...>
    The Alchemy Pages:
    - fractious fiction at http://freespace.virgin.net/jeremy.dronfield
    ========================================
    _______________________________________________
    cocoa-dev mailing list | <cocoa-dev...>
    Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
    Do not post admin requests to the list. They will be ignored.
  • On Friday, September 20, 2002, at 08:25  AM, Gerben Wierda wrote:

    > I have an NSTextView that alternately displays RTF data and ASCII
    > data. When the RTF data has been displayed, some aspects of it linger,
    > mainly the ruler. When I display pure ASCII the text displays > indented.
    >
    > I tried:
    >
    > [__inspectView setRichText:NO];
    > [__inspectView setUsesRuler:NO];
    > [__inspectView setFont:__fixedFont];
    >
    > but to no avail, the ASCII text is displayed indented. What am I
    > missing here?

    Specifically what you are missing is the paragraph style; however,
    there are other attributes you may wish to consider.  Here is the
    relevant method from the TextEdit example, which in addition to what
    you are doing, also applies a default set of attributes to the entire
    text (and sets them as the typing attributes), and removes any
    attachments:

    - (void)setRichText:(BOOL)flag {
        NSTextView *view = [self firstTextView];
        NSDictionary *textAttributes;

        isRichText = flag;

        if (!isRichText) [self removeAttachments];

        [view setRichText:isRichText];
        [view setUsesRuler:isRichText];    /* If NO, this correctly gets rid
    of the ruler if it was up */
        if (isRichText && [[Preferences objectForKey:ShowRuler] boolValue])
    [view setRulerVisible:YES];    /* Show ruler if rich, and desired */
        [view setImportsGraphics:isRichText];

        textAttributes = [self defaultTextAttributes:isRichText];

        if ([textStorage length]) {
            [textStorage setAttributes:textAttributes range: NSMakeRange(0,
    [textStorage length])];
        }
        [view setTypingAttributes:textAttributes];
    }

    Douglas Davidson
    _______________________________________________
    cocoa-dev mailing list | <cocoa-dev...>
    Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
    Do not post admin requests to the list. They will be ignored.
previous month september 2002 next month
MTWTFSS
            1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30            
Go to today