On Apr 27, 2019, at 10:26 , Richard Charles <rcharles...@gmail.com> wrote:
> 
> Contrary to the documentation NSTextField does not support the NSEditor 
> protocol.

Well, I apologize for not researching my answer better when I answered before. 
However, be careful of what you assume from the documentation. NSTextField may 
not conform to the new *format* NSEditor protocol, but that doesn’t stop it 
from conforming to the informal protocol, if that’s what it always did.

In that regard, you can see this discussed here:

https://developer.apple.com/library/archive/documentation/Cocoa/Conceptual/CocoaBindings/Concepts/HowDoBindingsWork.html#//apple_ref/doc/uid/20002373-200965
 
<https://developer.apple.com/library/archive/documentation/Cocoa/Conceptual/CocoaBindings/Concepts/HowDoBindingsWork.html#//apple_ref/doc/uid/20002373-200965>

That’s a very old document (Leopard era), and it says this:

> NSEditor/NSEditorRegistration
> 
> Together the NSEditorRegistration and NSEditor protocols allow views to 
> notify a controller that an edit is underway and to ensure that any pending 
> edits are committed as and when necessary.
> 
> The NSEditorRegistration informal protocol is implemented by controllers to 
> provide an interface for a view—the editor—to inform the controller when it 
> has uncommitted changes. When an edit is initiated, the view sends the 
> controller an objectDidBeginEditing: message. When the edit is complete (for 
> example when the user presses Return) the view sends an objectDidEndEditing: 
> message.
> 
> The controller is responsible for tracking which editors have uncommitted 
> changes and requesting that they commit or discard any pending edits when 
> appropriate—for example, if the user closes the window or quits the 
> application. The request takes the form of a commitEditing or 
> discardEditingmessage, defined by the NSEditor informal protocol. 
> NSController provides an implementation of this protocol, ***as do the 
> Application Kit user interface elements that support binding***.

(my emphasis in that last sentence)

I can also confirm, from having relied on this behavior for a decade or more, 
binding a text field to a NSObjectController *does* result in the text field 
committing editing when the controller asks it to.

In general, the NSObjectController, which implements both NSEditorRegistration 
and NSEditor, presents itself as a single editor to its “owning” controller, 
such as a NSDocument or NSViewController — but unfortunately not 
NSWindowController. When told to commit or discard its edits, the 
NSObjectController translates that into commit or discard messages for the 
NSEditor objects it owns).

On Apr 27, 2019, at 10:26 , Richard Charles <rcharles...@gmail.com> wrote:
> 
> Sending the array controller bound to the text field a discardEditing message 
> does’t work either.

I’m a bit confused by this. Why would you have a text field bound to an array 
controller? Are you talking about text fields in table view cells, where the 
table content is bound to an array controller? That’s a more complex scenario.

Describing these scenarios in words doesn’t seem to shedding much light on the 
subject. Maybe this is something you could put into a test project?
_______________________________________________

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to