Re: NSTextField "Discard Change"

2019-04-27 Thread Gary L. Wade
From what you’ve described and shown, your expectations for discardEditing are 
not correct.  The method discardEditing is a method you implement, typically on 
your view controller that owns/manages your text field.  There’s not really any 
good sample source using discardEditing I could find to point you to, but this 
one seems to give as best as can be.

https://sourceforge.net/p/skim-app/mailman/message/22781851/ 


It sounds like you want to fill the field with the previous value that was in 
there, and while you could do it in a text field subclass, you’re probably 
better off managing that from its controller.  By the time your sheet shows up, 
your text field is no longer performing any editing since it’s no longer the 
first responder.
--
Gary L. Wade
http://www.garywade.com/ 

> On Apr 27, 2019, at 10:26 AM, Richard Charles  wrote:
> 
>> On Apr 9, 2019, at 9:40 AM, Sean McBride  wrote:
>> 
>> NSTextField in fact does *not* support commitEditing/discardEditing, as per 
>> this a decade ago:
>> 
>> 
>> 
>> I don't think I ever did find another solution to my problem other than to 
>> use an NSObjectController.
> 
> 
> My testing shows you are correct. Contrary to the documentation NSTextField 
> does not support the NSEditor protocol. No App Kit user interface elements 
> that I can find support this protocol. It is only supported by NSController 
> and NSViewController.
> 
> --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


Re: NSTextField "Discard Change"

2019-04-27 Thread Richard Charles
> On Apr 9, 2019, at 9:40 AM, Sean McBride  wrote:
> 
> NSTextField in fact does *not* support commitEditing/discardEditing, as per 
> this a decade ago:
> 
> 
> 
> I don't think I ever did find another solution to my problem other than to 
> use an NSObjectController.


My testing shows you are correct. Contrary to the documentation NSTextField 
does not support the NSEditor protocol. No App Kit user interface elements that 
I can find support this protocol. It is only supported by NSController and 
NSViewController.

--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


Re: NSTextField "Discard Change"

2019-04-27 Thread Richard Charles
> On Apr 7, 2019, at 11:03 AM, Quincey Morris 
>  wrote:
> 
>> On Apr 5, 2019, at 20:55 , Richard Charles  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 
>> 
>> - (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