views:

109

answers:

1

I'm just starting to mess with bindings. I've started implementing a preference dialog, binding some NSColorWell's to the shared defaults controller. That's working perfectly. My values are encoded and saved correctly.

However, what's not working is canceling out of the dialog. If I cancel out, the values are still saved.

It seems like I should be binding the cancel button to the NSUserDefaultController's "revert," but of course if I do that, I can't bind it to to "performClose" (unless there's a way to bind a button to multiple actions that I'm not aware of).

What should I be binding the cancel button to both revert the changes and close the window. Obviously I could do it by writing an action method that does both, but it seems like should be possible in just IB.

+3  A: 

Two things:

First, by convention, preferences on Mac OS X are applied immediately when the change is made. There's no "cancel" or "apply" for preferences changes (as in Windows). It's not at all unusual to have a "defaults" button, which resets the preferences, but no cancel as changes are applied immediately. Making your app's preferences work otherwise is a bit weird as it doesn't follow conventions.

Second, because you're directly changing these values via bindings (same as if you'd used the target / action mechanism), you're not leaving yourself the opportunity to back out of changes. The best thing to do here is to create a dictionary controller whose contents is a copy of your app's preferences. The editing will occur on that dictionary. If the user cancels, you merely discard the dictionary. If the user accepts the changes, you'd copy the settings in the dictionary to the actual app preferences, then discard it. If you must "buffer" your app settings, this is a good way of doing it while still using Bindings for wiring the UI to the prefs, but you're still responsible for applying the changes when the user accepts.

Joshua Nozzi
That first paragraph is _very_ good.
Georg