NSTokenField Drag and Drop not updating value immediately via bindings?

  • This post is also on my blog:
    <http://clickablebliss.com/blog/2006/10/31/nstokenfield_drag_and_drop_not_up
    dating_value_immediately_via_bindings/
    >

    ---

    I'm hopeful to take advantage of `NSTokenField` in my app and to help better
    understand them I created a simple test application that mimics the UI found
    in System Preferences > International > Formats (tab) > Customize Date
    Formats (button/sheet).

    ![TokenSample](http://media.clickablebliss.com/blog/images/TokenSample.png
    "TokenSample")

    Basically instead of listing a table of tokens like '%d' and '%a' and asking
    the user to type out the format they want, they are presented with visual
    tokens that they can drag into the format editor and then use the context on
    the token to choose the specific format of that token, like the day of the
    week.

    So far my sample code works fairly well, but there is one bug and another
    hack (that I'd like to replace.)

    First, the UI in my sample app is all set up with bindings, so as you type
    in the main editor you'll see the two results fields below update as you
    type. However when you drag a token from one of the stationary token fields
    (or even a token's position in the editor) change notifications aren't sent
    and I'm not 100% sure the array the field is bound to is being updated
    "continuously" as I've set it up. How do I make sure that drag and drops
    cause value changes?

    Second is an aspect of the app I have working but seems wrong. When a user
    chooses one of the context menu options for a token I call
    `[mainEditorTokenField setObjectValue:[mainEditorTokenField objectValue]];`
    which I've seen in some other NSTokenField sample code. This basically makes
    sure that when they change from "Thursday" to "Thur" the token's display is
    updated. If I leave this out the display inside the token is not updated,
    though I do believe the value is changed, as if you choose a new token value
    using a context menu (with that code commented out) and then start typing at
    the end of the field you'll see the new value in the results.

    The project is online at:

    http://media.clickablebliss.com/code/TokenSample.zip

    If anyone with NSTokenField experience could take a look and/or offer me
    some suggestions I'd be appreciative.

    ~ Mike
    --
    Work: http://ClickableBliss.com
    Play: http://MikeZornek.com
previous month november 2006 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