Re: How to control the commit of text edit field with binding?
Re: How to control the commit of text edit field with binding?
- Subject: Re: How to control the commit of text edit field with binding?
- From: James Bucanek <email@hidden>
- Date: Fri, 5 May 2006 14:28:07 -0700
Brian Stern wrote on Friday, May 5, 2006:
>At 8:25 AM -0700 5/5/06, James Bucanek wrote:
>>I have a NSUserDefaults string property (the name the user is registed
>>as). This is displayed in four places and edited in two. Simple, right?
>>Just create a binding in all four places to the defaults controller and
>>I'm done.
>>
>>However, one of the places that the name is editable is in a modal sheet
>>where the user can edit several properties then click on OK or Cancel. If
>>I bind that text field to the defaults controller, edits to the name are
>>commmited immediately. I don't want the changes to the field to be
>>propogated until the user clicks the Save button, and ignored if they
>>click Cancel.
>
>The way I've dealt with this is to:
>
>Save the value of the field before showing the sheet
>If the user clicks Save do nothing (it's already saved)
>If the user clicks Cancel: restore the value in the user defaults
>controller with the saved value.
In this particular (possible rare) instance I can't do that. The value in the model is used by background tasks that could potentially start at any time. If I allowed the modal dialog to store half-edited or invalid values in the model, one of those background processes could start with invalid data.
>You might imagine doing it the other way around but I don't know how to
>intercept the editing that is committed through the bindings.
I guess this is what I was trying to do. So far I don't know of any way of doing that.
>Are you settingAppliesImmediately to NO? You might be able to use the
>various methods that are enabled with that setting to control this.
Ah ha! I think this might be my solution -- at least for NSUserDefaultsController values. It would seem that I can turn off propogation of model changes to the actual NSUserDefaults object, then manually save: or revert: those changes at the end of the dialog. Sadly, it doesn't appear that this metaphor applies to other NSController classes.
Thanks!
James
--
James Bucanek
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden