Why are the simplest things the hardest?

2018-07-04 Thread Rick Mann
I'm writing a new macOS app. I started with the document-based app template (no 
core data). I have a custom window controller, and a hierarchy of custom 
NSViewControllers embedded in a split view controller (I even subclassed the 
split view controller).

I have a simple IBAction method that logs a debugging message, and I try to 
send that action from a menu item to the first responder. I want to implement 
that method in one of my view controllers, but it never seems to get called. 
I've tried adding the method to every view controller, the window controller, 
and the app delegate, but it never gets called. However, if I connect the menu 
item to the app delegate, it gets called.

What am I doing wrong?

Thanks.

-- 
Rick Mann
rm...@latencyzero.com


___

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: Why are the simplest things the hardest?

2018-07-04 Thread Ken Thomases
On Jul 4, 2018, at 9:08 PM, Rick Mann  wrote:
> 
> I'm writing a new macOS app. I started with the document-based app template 
> (no core data). I have a custom window controller, and a hierarchy of custom 
> NSViewControllers embedded in a split view controller (I even subclassed the 
> split view controller).
> 
> I have a simple IBAction method that logs a debugging message, and I try to 
> send that action from a menu item to the first responder. I want to implement 
> that method in one of my view controllers, but it never seems to get called. 
> I've tried adding the method to every view controller, the window controller, 
> and the app delegate, but it never gets called. However, if I connect the 
> menu item to the app delegate, it gets called.
> 
> What am I doing wrong?

Is one of your views actually the first responder?  Does the window have key or 
main status?  By default, it wouldn't be able to become key or main if it 
doesn't have a title bar and isn't resizable.  Is there a view that accepts 
first responder (has overridden -acceptsFirstResponder to return YES)?  (Of 
course, certain standard controls like NSTextField accept first responder 
without you having to subclass them.)

I assume you're running macOS 10.10 or newer.  If not, you would have to take 
special steps to include those controllers in the responder.

Regards,
Ken

___

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: Why are the simplest things the hardest?

2018-07-04 Thread Rick Mann



> On Jul 4, 2018, at 20:40 , Ken Thomases  wrote:
> 
> On Jul 4, 2018, at 9:08 PM, Rick Mann  wrote:
>> 
>> I'm writing a new macOS app. I started with the document-based app template 
>> (no core data). I have a custom window controller, and a hierarchy of custom 
>> NSViewControllers embedded in a split view controller (I even subclassed the 
>> split view controller).
>> 
>> I have a simple IBAction method that logs a debugging message, and I try to 
>> send that action from a menu item to the first responder. I want to 
>> implement that method in one of my view controllers, but it never seems to 
>> get called. I've tried adding the method to every view controller, the 
>> window controller, and the app delegate, but it never gets called. However, 
>> if I connect the menu item to the app delegate, it gets called.
>> 
>> What am I doing wrong?
> 
> Is one of your views actually the first responder?  Does the window have key 
> or main status?  By default, it wouldn't be able to become key or main if it 
> doesn't have a title bar and isn't resizable.  Is there a view that accepts 
> first responder (has overridden -acceptsFirstResponder to return YES)?  (Of 
> course, certain standard controls like NSTextField accept first responder 
> without you having to subclass them.)

I've overridden -acceptsFirstResponder to return true on the window controller 
and view controllers. I don't have any custom views in the window yet, just an 
SCNView and a slider.

This begins to touch on another issue I'm not satisfied with: if I have 
multiple NSViewControllers (say, in a split view), and I want them all to 
respond to (different) menu commands, there seems to be no way to do that 
directly, by sending command to the first responder, right?

> 
> I assume you're running macOS 10.10 or newer.  If not, you would have to take 
> special steps to include those controllers in the responder.

Yes, 10.13.5

> 
> Regards,
> Ken
> 


-- 
Rick Mann
rm...@latencyzero.com


___

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: Why are the simplest things the hardest?

2018-07-04 Thread Ken Thomases
On Jul 4, 2018, at 10:45 PM, Rick Mann  wrote:
> 
> I've overridden -acceptsFirstResponder to return true on the window 
> controller and view controllers.

That doesn't do anything.  -acceptsFirstResponder is a view method and is only 
called on views, not controllers.

> I don't have any custom views in the window yet, just an SCNView and a slider.

I don't know if SCNView accepts first responder by default.  You may need to 
use a subclass that overrides -acceptsFirstResponder.

A slider would only accept first responder if System Preferences > Keyboard > 
Shortcuts > Full Keyboard Access is set to All Controls.


> This begins to touch on another issue I'm not satisfied with: if I have 
> multiple NSViewControllers (say, in a split view), and I want them all to 
> respond to (different) menu commands, there seems to be no way to do that 
> directly, by sending command to the first responder, right?

Correct.  That's not an appropriate case for targeting the action at the first 
responder.  You would either target the views directly or implement the action 
methods in a superview or its controller and have that dispatch things from 
there.  You could implement some general scheme that searches the descendant 
views for one which responds and send it there.  Or perhaps have the descendant 
views register their interest in a specific action method with the controller.

Regards,
Ken

___

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: Why are the simplest things the hardest?

2018-07-04 Thread Rick Mann



> On Jul 4, 2018, at 21:31 , Ken Thomases  wrote:
> 
> On Jul 4, 2018, at 10:45 PM, Rick Mann  wrote:
>> 
>> I've overridden -acceptsFirstResponder to return true on the window 
>> controller and view controllers.
> 
> That doesn't do anything.  -acceptsFirstResponder is a view method and is 
> only called on views, not controllers.

Well, it's an NSResponder var, so I assumed any of them could become first 
responder. Seems perfectly reasonable to choose the deepest appropriate 
NSResponder, even if it's not a view.

> 
>> I don't have any custom views in the window yet, just an SCNView and a 
>> slider.
> 
> I don't know if SCNView accepts first responder by default.  You may need to 
> use a subclass that overrides -acceptsFirstResponder.
> 
> A slider would only accept first responder if System Preferences > Keyboard > 
> Shortcuts > Full Keyboard Access is set to All Controls.
> 
> 
>> This begins to touch on another issue I'm not satisfied with: if I have 
>> multiple NSViewControllers (say, in a split view), and I want them all to 
>> respond to (different) menu commands, there seems to be no way to do that 
>> directly, by sending command to the first responder, right?
> 
> Correct.  That's not an appropriate case for targeting the action at the 
> first responder.  You would either target the views directly or implement the 
> action methods in a superview or its controller and have that dispatch things 
> from there.  You could implement some general scheme that searches the 
> descendant views for one which responds and send it there.  Or perhaps have 
> the descendant views register their interest in a specific action method with 
> the controller.

Okay, I'll have to do that, thanks.

Annoying I have to have a first responder view just to allow even my Document 
to respond to menu commands.

> 
> Regards,
> Ken
> 

Thanks!

-- 
Rick Mann
rm...@latencyzero.com


___

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: Why are the simplest things the hardest?

2018-07-04 Thread Rick Mann



> On Jul 4, 2018, at 21:31 , Ken Thomases  wrote:
> 
> On Jul 4, 2018, at 10:45 PM, Rick Mann  wrote:
>> 
>> I've overridden -acceptsFirstResponder to return true on the window 
>> controller and view controllers.
> 
> That doesn't do anything.  -acceptsFirstResponder is a view method and is 
> only called on views, not controllers.
> 
>> I don't have any custom views in the window yet, just an SCNView and a 
>> slider.
> 
> I don't know if SCNView accepts first responder by default.  You may need to 
> use a subclass that overrides -acceptsFirstResponder.

Hmm, I tried this. It doesn't seem to make anything in my responder chain 
respond. I tried calling becomeFirstResponder() on it when the view controller 
loaded. Doesn't seem to have any effect.

Dropping an NSTextView randomly into my window did enable my responder chain.

> 
> A slider would only accept first responder if System Preferences > Keyboard > 
> Shortcuts > Full Keyboard Access is set to All Controls.
> 
> 
>> This begins to touch on another issue I'm not satisfied with: if I have 
>> multiple NSViewControllers (say, in a split view), and I want them all to 
>> respond to (different) menu commands, there seems to be no way to do that 
>> directly, by sending command to the first responder, right?
> 
> Correct.  That's not an appropriate case for targeting the action at the 
> first responder.  You would either target the views directly or implement the 
> action methods in a superview or its controller and have that dispatch things 
> from there.  You could implement some general scheme that searches the 
> descendant views for one which responds and send it there.  Or perhaps have 
> the descendant views register their interest in a specific action method with 
> the controller.
> 
> Regards,
> Ken
> 


-- 
Rick Mann
rm...@latencyzero.com


___

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: Why are the simplest things the hardest?

2018-07-04 Thread Rick Mann
Weird. Examining the firstResponder shows it is, in fact, my SCNView subclass. 
Yet menu actions to the first responder don't propagate up.

> On Jul 4, 2018, at 21:31 , Ken Thomases  wrote:
> 
> On Jul 4, 2018, at 10:45 PM, Rick Mann  wrote:
>> 
>> I've overridden -acceptsFirstResponder to return true on the window 
>> controller and view controllers.
> 
> That doesn't do anything.  -acceptsFirstResponder is a view method and is 
> only called on views, not controllers.
> 
>> I don't have any custom views in the window yet, just an SCNView and a 
>> slider.
> 
> I don't know if SCNView accepts first responder by default.  You may need to 
> use a subclass that overrides -acceptsFirstResponder.
> 
> A slider would only accept first responder if System Preferences > Keyboard > 
> Shortcuts > Full Keyboard Access is set to All Controls.
> 
> 
>> This begins to touch on another issue I'm not satisfied with: if I have 
>> multiple NSViewControllers (say, in a split view), and I want them all to 
>> respond to (different) menu commands, there seems to be no way to do that 
>> directly, by sending command to the first responder, right?
> 
> Correct.  That's not an appropriate case for targeting the action at the 
> first responder.  You would either target the views directly or implement the 
> action methods in a superview or its controller and have that dispatch things 
> from there.  You could implement some general scheme that searches the 
> descendant views for one which responds and send it there.  Or perhaps have 
> the descendant views register their interest in a specific action method with 
> the controller.
> 
> Regards,
> Ken
> 


-- 
Rick Mann
rm...@latencyzero.com


___

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