Initializing NSDecimalTabStopType returns NSRightTabStopType

  • I've filed a bug on this (5757951) but I hope there's a workaround.
    The initializer for creating a NSTextTab of type NSDecimalTabStopType
    is initWithAlignment:(NSTextAlignment)alignment location:
    (CGFloat)location options:(NSDictionary *)options. There is no
    NSTextAlignment for dec tabs, so you use NSRightTextAlignment, and the
    initializer apparently figures out that you want a decimal tab by
    looking in the options dictionary.

    But usually I get a right-aligned textTab even though I've requested a
    decimal-aligned textTab. Sometimes an incantation can help:

    // Create an options dictionary to be used in creating a decimal
    NSTextTab:
    NSCharacterSet *charSet = [NSCharacterSet
    characterSetWithCharactersInString:@"."];
    NSDictionary *optionsDict = [NSDictionary
    dictionaryWithObject:charSet
    forKey:NSTabColumnTerminatorsAttributeName];

    // try to create a decimal NSTextTab using that options dict:
    NSTextTab *textTab1 = [[NSTextTab alloc]
    initWithTextAlignment:NSRightTextAlignment
                                                             location:location
                                                             options:optionsDict];
    NSLog(@"tabStopType is %i", [textTab1 tabStopType]);
    // Doesn't work; tabStopType is 1 (right)

    // Create and release a default decimal NSTextTab:
    NSTextTab *dummyTab = [[NSTextTab alloc]
    initWithType:NSDecimalTabStopType location:location];
    [dummyTab release];

    // Now try again to create the decimal NSTextTab using the same
    options dict:
    NSTextTab *textTab2 = [[NSTextTab alloc]
    initWithTextAlignment:NSRightTextAlignment
                                                             location:location
                                                             options:optionsDict];
    NSLog(@"tabStopType is %i", [textTab2 tabStopType]);
    // It works; tabStopType is 3 (decimal)

    but sometimes I get the right-aligned textTab no matter what.

    Any ideas on a sure-fire way to initialize a decimal NSTextTab?

    Ross
  • Ross,

    Thank you for filing the bug.

    Indeed there is a bug in NSTextTab.

    Fortunately, it only affects -tabStopType method.  The actual instance
    created works as a decimal tab.

    Aki

    On 2008/02/21, at 14:30, Ross Carter wrote:
    > I've filed a bug on this (5757951) but I hope there's a workaround.
    > The initializer for creating a NSTextTab of type
    > NSDecimalTabStopType is initWithAlignment:(NSTextAlignment)alignment
    > location:(CGFloat)location options:(NSDictionary *)options. There is
    > no NSTextAlignment for dec tabs, so you use NSRightTextAlignment,
    > and the initializer apparently figures out that you want a decimal
    > tab by looking in the options dictionary.
    >
    > But usually I get a right-aligned textTab even though I've requested
    > a decimal-aligned textTab. Sometimes an incantation can help:
    >
    > // Create an options dictionary to be used in creating a decimal
    > NSTextTab:
    > NSCharacterSet *charSet = [NSCharacterSet
    > characterSetWithCharactersInString:@"."];
    > NSDictionary *optionsDict = [NSDictionary
    > dictionaryWithObject:charSet
    > forKey:NSTabColumnTerminatorsAttributeName];
    >
    > // try to create a decimal NSTextTab using that options dict:
    > NSTextTab *textTab1 = [[NSTextTab alloc]
    > initWithTextAlignment:NSRightTextAlignment
    > location:location
    > options:optionsDict];
    > NSLog(@"tabStopType is %i", [textTab1 tabStopType]);
    > // Doesn't work; tabStopType is 1 (right)
    >
    > // Create and release a default decimal NSTextTab:
    > NSTextTab *dummyTab = [[NSTextTab alloc]
    > initWithType:NSDecimalTabStopType location:location];
    > [dummyTab release];
    >
    > // Now try again to create the decimal NSTextTab using the same
    > options dict:
    > NSTextTab *textTab2 = [[NSTextTab alloc]
    > initWithTextAlignment:NSRightTextAlignment
    > location:location
    > options:optionsDict];
    > NSLog(@"tabStopType is %i", [textTab2 tabStopType]);
    > // It works; tabStopType is 3 (decimal)
    >
    > but sometimes I get the right-aligned textTab no matter what.
    >
    > Any ideas on a sure-fire way to initialize a decimal NSTextTab?
    >
    > Ross
  • Thanks, Aki. That's exactly what I needed. This now works:

    NSTextTabType tabType = [textTab tabStopType];
    if (tabType == NSRightTabStopType && [[textTab options]
    objectForKey:NSTabColumnTerminatorsAttributeName] != nil) tabType =
    NSDecimalTabStopType;

    Ross

    On Feb 21, 2008, at 5:48 PM, Aki Inoue wrote:

    > Ross,
    >
    > Thank you for filing the bug.
    >
    > Indeed there is a bug in NSTextTab.
    >
    > Fortunately, it only affects -tabStopType method.  The actual
    > instance created works as a decimal tab.
    >
    > Aki
    >
    > On 2008/02/21, at 14:30, Ross Carter wrote:
    >> I've filed a bug on this (5757951) but I hope there's a workaround.
    >> The initializer for creating a NSTextTab of type
    >> NSDecimalTabStopType is initWithAlignment:
    >> (NSTextAlignment)alignment location:(CGFloat)location options:
    >> (NSDictionary *)options. There is no NSTextAlignment for dec tabs,
    >> so you use NSRightTextAlignment, and the initializer apparently
    >> figures out that you want a decimal tab by looking in the options
    >> dictionary.
    >>
    >> But usually I get a right-aligned textTab even though I've
    >> requested a decimal-aligned textTab. Sometimes an incantation can
    >> help:
    >>
    >> // Create an options dictionary to be used in creating a decimal
    >> NSTextTab:
    >> NSCharacterSet *charSet = [NSCharacterSet
    >> characterSetWithCharactersInString:@"."];
    >> NSDictionary *optionsDict = [NSDictionary
    >> dictionaryWithObject:charSet
    >> forKey:NSTabColumnTerminatorsAttributeName];
    >>
    >> // try to create a decimal NSTextTab using that options dict:
    >> NSTextTab *textTab1 = [[NSTextTab alloc]
    >> initWithTextAlignment:NSRightTextAlignment
    >> location:location
    >> options:optionsDict];
    >> NSLog(@"tabStopType is %i", [textTab1 tabStopType]);
    >> // Doesn't work; tabStopType is 1 (right)
    >>
    >> // Create and release a default decimal NSTextTab:
    >> NSTextTab *dummyTab = [[NSTextTab alloc]
    >> initWithType:NSDecimalTabStopType location:location];
    >> [dummyTab release];
    >>
    >> // Now try again to create the decimal NSTextTab using the same
    >> options dict:
    >> NSTextTab *textTab2 = [[NSTextTab alloc]
    >> initWithTextAlignment:NSRightTextAlignment
    >> location:location
    >> options:optionsDict];
    >> NSLog(@"tabStopType is %i", [textTab2 tabStopType]);
    >> // It works; tabStopType is 3 (decimal)
    >>
    >> but sometimes I get the right-aligned textTab no matter what.
    >>
    >> Any ideas on a sure-fire way to initialize a decimal NSTextTab?
    >>
    >> Ross
    >
    >
previous month february 2008 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    
Go to today