NSTokenField fails to tokenize with mixed text
NSTokenField fails to tokenize with mixed text
- Subject: NSTokenField fails to tokenize with mixed text
- From: "Kyle Sluder" <email@hidden>
- Date: Mon, 17 Nov 2008 01:33:32 -0500
Hi list,
I'm writing an Automator action that will allow users to insert
properties of the input object into a format string to produce new
strings. So, for example, if the input to the action is a list of
iTunes tracks, the user can generate filenames of the pattern
"«artist» - «album» - «name».mp3". The logical choice for the UI is
an NSTokenField, in which certain tokens are displayed as plain text,
while others are displayed as default tokens.
Unfortunately, the only way to determine the represented object for a
token is by examining the editing string, so the only way to tell if a
user's input is a token is by some form of sentinel -- I have chosen @
for now because it's simple. So when the user enters text and hits
Return, the NSTokenField sends its delegate
-tokenField:representedObjectForEditingString:, which just returns the
token as-is to avoid the whitespace-chomping behavior on 10.5.2+.
Then the delegate gets -tokenField:styleForRepresentedObject:, which
just does the following:
-(NSTokenStyle)tokenField:(NSTokenField *)tokenField
styleForRepresentedObject:(NSString *)representedObject {
if([representedObject hasPrefix:@"@"])
return NSDefaultTokenStyle;
else
return NSPlainTextTokenStyle;
}
Now, if a user's first token is plain text (does not begin with @),
the user can't enter any more tokens, because the NSTokenField doesn't
see the @ as part of a new token. This happens even if the user
explicitly hits the Return key to tokenize the plain text input they
have already entered. What's worse is that I must include the @
character in the editing representation, and if the user deletes it
(which is easy to do because it's part of the selection when the user
double-clicks a token to edit it), it becomes part of the plain text
in the field with no way to convert it back into a token.
Does anyone have a solution to this issue?
Thanks,
--Kyle Sluder
_______________________________________________
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