Re: return press and edit text

2016-12-01 Thread J.E. Schotsman

> On 30 Nov 2016, at 22:04, Quincey Morris wrote:
> 
> The problem is that NSWindowController doesn’t implement the other informal 
> protocol (NSEditorRegistration) that is the way that editors are supposed to 
> be kept track of. The easiest way to get around this is for your OK button 
> action to invoke “commitEditing” on the text field.

Except it’s called   endEditing(_:)

Jan E.

___

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: return press and edit text

2016-11-30 Thread J.E. Schotsman

> On 30 Nov 2016, at 22:04, Quincey Morris 
>  wrote:
> 
> For #2, you shouldn’t need to use any delegates. Instead, you need to get the 
> text field to commit its edit. There is an informal protocol for this 
> (NSEditor), which text fields conform to.
> 
> The problem is that NSWindowController doesn’t implement the other informal 
> protocol (NSEditorRegistration) that is the way that editors are supposed to 
> be kept track of. The easiest way to get around this is for your OK button 
> action to invoke “commitEditing” on the text field. Alternatively, invoke 
> “commitEditing” from the window delegate's “windowWillClose” method (normally 
> in the window controller).

This is my main (utility) window so it’s never closed and I don’t use a window 
controller either.
Looks like I need to keep track of the active text field myself.
commitEditing sounds better than the insertNewLine trick.
Thanks!

Jan E.
___

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: return press and edit text

2016-11-30 Thread Quincey Morris
On Nov 30, 2016, at 10:41 , J.E. Schotsman  wrote:
> 
> a hit on return acts on both the default button and a text field that is 
> being edited in the same window.
> 
> The text field gets the event first, then the OK button, which is probably 
> what the user wants.

I must admit I don’t remember the sequence of “events” for this case, but the 
above doesn’t sound correct. The text field and the button are in different 
responder chains, so even if the event (i.e. NSEvent) isn’t consumed by one, it 
never gets passed to the other. I assume the default button behavior is 
actually mediated via the window.

In any case …

> If I click on OK instead the text edits are ignored (which is not what I want 
> if the text field contains a setting for a job started by the OK press).
> 
> I can see two solutions:
> 
> 1. Make the OK button inactive while any text field is edited
> 2. Make sure hitting the OK button triggers the end of any text editing first.
> 
> Which is to be preferred?

#1 doesn’t sound right, unless perhaps you really wish the user to press Return 
twice to close the dialog (via the keyboard).

For #2, you shouldn’t need to use any delegates. Instead, you need to get the 
text field to commit its edit. There is an informal protocol for this 
(NSEditor), which text fields conform to.

The problem is that NSWindowController doesn’t implement the other informal 
protocol (NSEditorRegistration) that is the way that editors are supposed to be 
kept track of. The easiest way to get around this is for your OK button action 
to invoke “commitEditing” on the text field. Alternatively, invoke 
“commitEditing” from the window delegate's “windowWillClose” method (normally 
in the window controller).

Strangely, NSViewController *does* implement NSEditor/NSEditorRegistration, so 
if your text field is in a view that has a view controller — the window 
controller’s contentViewController, if this is all coming from a storyboard — 
you can instead issue the “commitEditing” to the view controller, and it will 
commit *all* editors. That’s more convenient if you have multiple text fields, 
and/or you don’t want to have to write code with explicit references to them.

___

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