Xcode NSPopup binding


(Jonas Whale) #1

I’m able, in a Xcode project, to bind to the Shared User Default Controller the status of matrices, text fields and checkboxes but can’t find how to do the same for a popup menu.

What’s the trick?

(Shane Stanley) #2

If you want a binding for the item selected, bind to its Selected Value.

(Jonas Whale) #3

Ok for the selected item. But how to bind the contents?

The popup menu items are stored in a pref file shared by several scripts.
In those scripts, I’m using NSUserDefault to build the popup menu at launch.
I could use the same approch for this app…
I have made a button to build the menu when I need to update it.
Now I want to bind the menu items (and separators) list.
I tried content, content objects and content values but the menu is always empty at relaunch.
What I’m missing?

(Shane Stanley) #4

It works with content values. You say several scripts share the same pref file, but I don’t see how that’s compatible with the Share User Defaults Controller.

(Jonas Whale) #5

I’m not talking about Share User Defaults Controller but NSUserDefault.
In the scripts I’m using:

 current application's NSUserDefaults's alloc()'s initWithSuiteName:"com.ionah.sharedprefs.plist"

Which gives me access to the same pref file in a dozen of scripts and apps.
I know that it can be a problem with signed apps, but those scripts are only for my personal use and will never be ported for another system.

The Xcode app was built that way but I wanted to learn bindings to Share User Defaults Controller.

Here are my settings:

(Shane Stanley) #6

Then I’m confused. Your first message said you were, no?

(Jonas Whale) #7

It’s not you. I’m limited with my poor english.

I have a Xcode app (named Export PDF) that, well… exports PDFs from Indesign!
Based on several parameters chosen by user, it creates an e-mail, adding the pdf as attachement.
One of those parameters is the recipient of the mail, picked up from a client list, displayed as popup.

The client list is stored in a shared plist file (“com.ionah.sharedprefs.plist”)
I’m using NSUserDefaults to get the client list from this “external” pref file and update the popup menu.
This is done at launch in the applicationWillFinishLaunching: handler.

Now I want to learn how to use bindings to store the popup’s content in the Xcode app’s plist file.
So I made a button to update the popup menu (from the external pref) when it’s needed.
I thought that the popup contents would be automatically saved with bindings like I set them (see previous post).

But the popup content is lost at every launch.
I’m sure there’s something obvious I’m missing.

(Shane Stanley) #8

If I understand correctly, I don’t think you can use bindings in that case. If you’re pushing a button to update them, you can store them in user defaults there.

(Jonas Whale) #9

Ok. I will revert to the NSUserDefaults version and get rid of all that mess!
Thank you for trying to understand all that gibberish.