Dear all, The problem, shorty: I cannot undo a bounded control's value in the KVO events chain
//////////////////////////////////////////////////////////// A) The situation (I'm not using a Mac right now, so some names might be wrong.) - multiple nibs, some controls with bounded values. They go to the "main" controller in the main nib using key paths like this: "preferences.component1.blabal1", "preferences.component1.blabal2", "preferences.component2.blabal1", "someOtherPreferences.component1.blabal1" (through "base nib object controller") - the main controller exposes methods like "preferences", "someOtherPreferences" through a "base binding controller" (NSUserDefaultsController ... see below) the binding controller isn't exposed to Interface Builder - can this be a problem ? - settings aren't to be saved to the application defaults, the binding controller knows better (the correct location) - modifying an exposed setting might require user interaction and possibly undo //////////////////////////////////// B) derived NSUserDefaultSController solution NSUserDefaultSController seemed to be the most promising solution (initialValues seemed to be great), but I succeded only by using some workarounds: - coudn't force the initialization using KVC (?): solution: enumerate de bindings from the view(s) and identify by prefix (preferences, someOtherPreferences) => setObjectValue - I managed to avoid the final synchronize (with the application defaults) only by catching the "application termination notification" and remove the bindings added in the meantime I can obtain the same behaviour by replacing NSUserDefaultSController with ... NSObject (and some NSMutableDictionarys, already necessary to load the initial settings) (:) and not checking "Validates immediately" which throws some message box with the error ... "Error") //////////////////////////////////// C) The Big Bad problem I cannot undo the modified value (in the user interface) if necessary => observeValueForKeyPath:ofObject:change:context: (or setValue:forKeyPath in the "base nib object controller") I have the new value and I managed to know the old one -calling explicitly setValue:forKeyPath changes the value in the controller (model), but not in the user-interface (I also managed to avoid the recursivity) -calling directly setObjectValue (yes, I managed to retrieve the NSControl itself) changes the user interface, with or without the previous step: - doesn't go through observeValue..., which is good - !!! ... but it skips the next user interface modification on the same binding The events path: 1) user changes something in NsControl A -> 2) setValue:forKeyPath get notified -> 3) observerValue... (the base controller) -> 4) [A setObjectValue:oldValue] (step 2 or 3) 5) user sees the old value in A, but changes again -> no 2) or 3) //////////////////////////////////// D) New solutions I can implement some setPreferences, setSomeOtherPreferences methods, but not in every nib controller for every setting. I can try to show the controls as 'disabled' and require the user interaction before => no undo will be generaly necessary, but: - an interface redesign is necessary - the situation can still appear in extreme cases A final very low solution: - get the bindings to a dictonary, unbind and setAction/setTarget (that's it ... eliminate the bindings for good) Thanks in advance, Liviu Andron _______________________________________________ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to [EMAIL PROTECTED]