09 January 2008

Cocoa Screen Saver Prefs and Bindings (or Not)

In my latest work on my Visionary Saver screen saver, I had tried switching all my preferences to use Cocoa Bindings, to make it super easy to manage the prefs. After doing this, and having it appear to work, I realized that it does not.

The problem is that screen savers are supposed to use the ScreenSaverDefaults class to manage their preferences. This is a special Defaults class that namespaces a screen savers defaults/preferences within the defaults system, given that a screen saver is a bundle, and works within System Preferences (as opposed to being its own application). The reason it doesn't work with bindings is that you can't tell the Bindings system about ScreenSaverDefaults (to my knowledge), in the same way as you can bind to the Shared Defaults Controller. ScreenSaverDefaults requires a module name, and so on. If there's a workaround, I'd love to hear it.

I thus had to go back to manually getting and setting the preferences for Visionary. This did simplify one thing, which is the preferences settings for an NSPopUpButton, where the content values come from an array, yet the selection and setting should go to preferences. Personally, NSPopUpButtons, for simple use, are a real pain. I'm not an Interface Builder expert, but it's odd that you can set up to 3 values into an NSPopUpButton in the UI, as generic text, but if you want more, you have to setup the whole NSArrayController and its content array, and so on, then bind that to the popup, etc, etc. It's not awful, but the documentation is pretty weak in terms of a straight forward use of something like this. I suspect many other folks don't have complicated data models behind the values for some of their popup buttons, and a cleaner way to do all this would be nice.

Anyway, it's all good now, or well, it's all fixed up, and there's a new version of Visionary Saver out.

2 comments:

k. said...

"but it's odd that you can set up to 3 values into an NSPopUpButton in the UI"

In the popup button, you can duplicate any one of those three items to create more, or you can drag in a menu item from the library.

Chris said...

k, thanks! Sheesh, how obvious - drag in another menu item, uh, duh. Sometimes it's so simple, that it's over my head :) I suppose I ought to really spend the time to fully learn IB...