I'd like to be able to type in text and drag readonly elements (tokens) into a NSTokenField to create a custumizable string format. Like in Apple iWorks Numers' customize cell format. The user can drag readonly NSTokenCells into a NSTokenTextField (remaining NSRoundedTokenStyle) and type in plain text (remaining NSPlainTextTokenStyle). I Subclassed NSTokenFieldCell to a claas FormatToken so that I can filter out plain text tokens and my FormatToken by using isKindOfClass: [FormatToken class] (see code below). I'm able to add my predefined token showing up as a RoundedTokens and add plan text showing up as PlainTextTokens. The problem is that when I double click the FormatToken token, NSTokenField jumps to the editing mode and makes it a normal plain text string. My FormatToken is being replaced by a NSTokenFieldCell and remains displayed as NSPlainTextTokenStyle. I did set the setEditable:NO for my FormatToken but it seems when the NSTokenField is editable, all the Cell are forced editable. Does anyone know how to fix this problem?

- (NSString *)tokenField:(NSTokenField *)tokenField displayStringForRepresentedObject:(id)representedObject{

        NSString * string;

        if ([representedObject isKindOfClass: [FormatToken class]]) {

        FormatToken * token = representedObject;

        string = [token text];

        } else

                string = representedObject;

        return string;

}


- (NSTokenStyle)tokenField:(NSTokenField *)tokenField styleForRepresentedObject:(id)representedObject{

        if ([representedObject isKindOfClass: [FormatToken class]])

                return NSRoundedTokenStyle;

        else return NSPlainTextTokenStyle;

}


- (IBAction)addReadOnlyFromatToken: (id)sender;{

SMutableArray * array = [NSMutableArray arrayWithArray:[tokens objectValue]];

        FormatToken * token = [[FormatToken alloc] init];
        [token setText: @"Readonly Token"];

        [token setEditable: NO]

        [array addObject:token];

        [tokens setObjectValue: array];

}
_______________________________________________

Cocoa-dev mailing list ([email protected])

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 [email protected]

Reply via email to