> On Apr 7, 2019, at 11:03 AM, Quincey Morris 
> <quinceymor...@rivergatesoftware.com> wrote:
> 
>> On Apr 5, 2019, at 20:55 , Richard Charles <rcharles...@gmail.com> wrote:
>> 
>> Sending the text field an abortEditing message does not work. How can 
>> changes to the text field be discarded?
> 
> Caveat: I don’t know the answer to what you’re asking, but I suspect you may 
> be asking the wrong question.
> 
> First of all, what does “does not work” mean?


Sending the text field an abortEditing message results in no changes to the 
text field. Nothing happens.


> Second, looking at the documentation here:
> 
> https://developer.apple.com/documentation/appkit/nscontrol
> 
> the “abortEditing” method is listed under “Managing the Field Editor”. I 
> suspect it’s actually used internally to manage the relationship between the 
> text field’s cell and the field editor, and not to manage the editing state 
> of the control as a while. This method is probably just the wrong hammer for 
> this nail.
> 
> Third, what I think you’re looking for is “discardEditing”, which is a part 
> of the NSEditor protocol, to which NSTextField conforms. However, I’m not 
> entirely sure about timing, whether it’s reasonable to invoke in response to 
> “attemptRecoveryFromError:…”. But maybe.


According to macOS 10.13 documentation (NSKeyValueBinding.h) discardEditing is 
implemented by controllers, CoreData's managed object contexts, and user 
interface elements.

However upon searching the macOS SDK, discardEditing is only implemented by by 
NSController and NSViewController. It is not implemented by any user interface 
elements. Testing has confirmed that NSTextField does not implement 
discardEditing.

Sending the array controller bound to the text field a discardEditing message 
does’t work either. Nothing happens. Switching back to a standard cocoa value 
binding and placing symbolic breakpoints on -[NSController discardEditing] and 
-[NSArrayController discardEditing] shows that when the user clicks "Discard 
Change" in the alert panel, discardEditing is never called. So the cocoa 
frameworks are using some other means to discard the change from the text field.


> Note that the documentation for NSEditor shows its methods as deprecated:
> 
> https://developer.apple.com/documentation/appkit/view_management/nseditor
> 
> I believe this is a documentation error. At some point, NSEditor was 
> converted from an informal protocol to a formal protocol (so it would 
> translate into Swift properly), and that causes this error in the 
> documentation. If you look at the actual header file (NSKeyValueBinding.h), 
> you can see that the formal NSEditor protocol has no deprecations:
> 
>> @protocol NSEditor <NSObject>
>> 
>> - (void)discardEditing;    // …
>> - (BOOL)commitEditing;    // …
> 
> as well as the deprecations of the information protocol methods:
> 
>> @interface NSObject (NSEditor)
>> - (void)discardEditing NS_DEPRECATED_MAC(10_0, API_TO_BE_DEPRECATED, "This 
>> is now a method of the NSEditor protocol.");
>> - (BOOL)commitEditing NS_DEPRECATED_MAC(10_0, API_TO_BE_DEPRECATED, "This is 
>> now a method of the NSEditor protocol.”);


In summary testing has shown that discardEditing messages are sent to 
controllers which are bound to a text field during normal operation. But when 
the user chooses "Discard Change" in an alert panel a discardEditing message is 
never sent. The frameworks are using some other means to discard the change 
from the text field.

So this all is a bit of a mystery how to programmatically discard a change from 
a text field bound to an array controller.

--Richard Charles

_______________________________________________

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