On 15. Nov 2006, at 00:10, Jay Soffian wrote:
[...] I've almost got this working. I've setup an NSArrayController that I'm populating via tm_dialog. I've bound the NSPopUpButtons's contentValues to the NSArray Controller. However, whenever I edit the text field it ends up updating the drop-down. Doh.
I don’t think there is any solution to that.
Also, I want to give this window working Cancel/Okay buttons.
Is this doable? Do I need to use IB Connections instead of bindings to tie the pop-up to the text field?
The cancel button, you can connect to the window’s performClose: or similar, i.e. hold control down, click the cancel button and hold left mouse button down, drag the connection line to the window object in the instances window, now release the mouse button and select performClose: in the target / action tab of the inspector window.
For the Okay button, you can either do what is described here [1] or, if you have a recent version of the plug-in, for the Okay button bind the target to the NSController object with model key being ‘controller’, then set selector to returnArgument: (the colon is important!).
You would then bind the argument also to the NSController, with the model key being that of the text being edited (or perhaps bind it to the array controller, and key being selected object or similar).
Note you can actually give it more than one argument, but you need to edit the selector name if you bind multiple arguments so that there is a «name»: for each argument in the name. Try open the New Project nib in the Xcode bundle to inspect the bindings there.
A nice thing about this approach is that one can bind many controls to the shared user defaults controller, then the value is stored in user defaults, and thus are sticky, and then bind these defaults values as arguments, so they will be available in the result of tm_dialog -- this is why the latest version of tm_dialog has an argument to set initial user defaults values.
[1] http://lists.macromates.com/pipermail/textmate/2006-October/ 014364.html