> On 19 Oct 2016, at 08:01, Quincey Morris > <quinceymor...@rivergatesoftware.com> wrote: > > On Oct 18, 2016, at 22:33 , Gerriet M. Denkmann <g...@mdenkmann.de> wrote: >> >> I have just done this (can send it to you if you are interested). > > I’d be interested at looking at it, if you can email it to me. > >> Bug4: changes not keep on quit >> Check: change a TextField; do not use CR or leave the TextField; quit >> the app. Start it again. >> Maybe this is the way it should be. But in the age of autoSave >> it feels a bit strange though. > > I’m pretty sure this is nothing to do with KVO or user defaults. > > An edited text field won’t get “committed” back to the data model until you > end editing (Tab or Return) unless you arrange for it to happen. There’s are > two *informal* protocols (NSEditor and NSEditorRegistration) that bridge > between editors and controllers. Both NSDocument and NSViewController > implement both of these, but that would only work if the view controller > registered itself with the document, but it doesn’t. In effect the > NSWindowController intervenes between the document and view controller, but > it *doesn’t* implement those protocols, so it breaks the chain. > > One way around this is to use a NSObjectController bound between the text > field and the data model (user defaults in this case). NSObjectController > implements the editor protocols, so this covers the case where the window > closes while an edit is in progress. However, IIRC it doesn’t help when a > document “save” occurs or when the app quits, for separate reasons.
I've had to deal with the issue of lost data on save/autosave recently and came up with the following solutions: Solution A: bind the text field's value directly to a property of the NSDocument so it is the model controller, the text editor get's registered and NSDocument commits changes on active editors before saving as documented in NSDocument.h Solution B: bind the text field's value to a custom NSController and vent the NSEditorRegistration calls up to NSDocument. Both of these work, but you have to keep track of other instances where you bind to objects, that do not implement NSEditorRegistration, e.g. I used objectValue for NSViews in a NSTableViews to bind values. This required a custom NSViews to get editors registered in NSDocument. > Anyway, my point is that I think this is an unrelated problem. ___m i c h a e l s t a r k e____ geschäftsführer HicknHack Software GmbH www.hicknhack-software.com ___k o n t a k t____ +49 (170) 3686136 cont...@hicknhack.com ___H i c k n H a c k S o f t w a r e G m b H____ geschäftsführer - maik lathan | andreas reischuck | michael starke bayreuther straße 32 01187 dresden amtsgericht dresden HRB 30351 sitz - dresden _______________________________________________ Cocoa-dev mailing list (Cocoafirstname.lastname@example.org) 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: https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com