Re: NSTokenField bug in 10.5.2?
Re: NSTokenField bug in 10.5.2?
- Subject: Re: NSTokenField bug in 10.5.2?
- From: Tom Bunch <email@hidden>
- Date: Wed, 12 Mar 2008 14:55:31 -0700
It looks like the answer here is that there's no great workaround.
Linked against 10.4, NSTokenField will not preserve your whitespace.
The delegate method:
- (id)tokenField:(NSTokenField *)tokenField
representedObjectForEditingString:(NSString *)editingString
is not called with an editingString that contains nothing but
whitespace. If I'm recalling my results correctly, if editingString
ought to be " xx ", the leading whitespace is trimmed but not the
trailing. This means that you cannot implement an interface like
System Preferences->International->Custom Formats, link against the
10.4 sdk, and expect it to work properly on Leopard.
The workaround I came up with is not entirely satisfactory, but I
think it will work for users for the time being. I wound up
implementing another delegate method:
- (BOOL)control:(NSControl *)control isValidObject:(id)object
and replacing whitespace characters in object with something I didn't
really expect to see (I think I chose an Ethiopic wordspace). Then,
in representedObjectForEditingString:, I check for that character in
editingString. If I get it, I just make an instance of a trivial
token class that only exists to turn strings in to tokens. Finally,
if I don't return NSDefaultTokenStyle from
tokenField:styleForRepresentedObject:, entering and exiting the token
field will cause the space to be re-trimmed and the token to go away,
even though no editing took place (and control:isValidObject: and
controlTextDidChange: are not called). So I do that. My whitespace
characters are thus each turned into a single space (I could probably
encode different whitespace characters as different obscure
characters, but I don't care quite that much) and show up in the token
field w/ a lozenge around them.
The test app at http://people.omnigroup.com/tom/NSTokenField.zip has
been modified w/ the workaround.
-Tom
On Mar 10, 2008, at 3:00 PM, Tom Bunch wrote:
Hey developers,
I've been grappling with a problem very similar to this month's
earlier thread with the same subject line. The consensus there was
that in 10.4 NSTokenField always trims off whitespace before the
input it tokenized. In fact, my experience is the opposite. In
OmniPlan we have an interface much like the custom formats in System
Preferences -> International -> Formats – you can drag in tokens and
add text to delimit between them. Built against the 10.4 SDK and
run on 10.4, this accepts spaces in the token field and passes them
on to me, but when the same binary is run on Leopard, the spaces are
just gone. You get dates like "January2008", unless you delimit w/
non-whitespace.
I've cobbled together a very simple test app and put the source up
at http://people.omnigroup.com/tom/NSTokenField.zip. It just
prepopulates an NSTextField w/ a couple of tokens and logs the
objectValue if you edit the field.
Run this on Tiger, put some spaces in between tokens and hit tab,
you get a log like this:
2008-03-10 14:03:16.929 NSTokenField[239] token field objectValue =
(<Token: 0x343f60>, " ", <Token: 0x344140>)
On Leopard, you get:
2008-03-10 14:03:16.929 NSTokenField[239] token field objectValue =
(<Token: 0x343f60>, <Token: 0x344140>)
This is pretty easy to fix if I target 10.5, but this build needs to
target 10.4 and hopefully still behave on 10.5.
In the earlier thread, Aki Inoue confirmed that:
The logic to determine whether or not to apply the auto whitespace
trimming is:
- trims if linked against 10.4.x binary
That seems to be true... linked against 10.4 and run on 10.5, but
it's not consistent with the behavior linked against 10.4 and run on
10.4, so it doesn't really solve the binary compatibility problem.
Any suggestions for a workaround would be appreciated!
Thanks!
-Tom Bunch
Omni
_______________________________________________
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
_______________________________________________
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