Thanks Graham,

To explain the context, this menu pops out from a custom view in a toolbar item 
and needs to target the selection in the window so I can't wire it directly to 
the actual target since it is dynamic.

Using the information you supplied, I was able to make this work by passing the 
current first responder as the view to popUpContextMenu:withEvent:forView

This solves the issue but I do wish there was a way to make a context menu 
behave just like the menus in the menu bar, with target set to nil, it would 
adjust and send the action to the first responder.

Eyal

> On 6 Mar 2023, at 1:43, Graham Cox <graham....@bigpond.com> wrote:
> 
> Hi Eyal,
> 
> I believe the target for a pop-up menu is the view that you pass in that 
> method, at least initially. If there is an established responder chain from 
> that view to other responders (up to and including First Responder) then the 
> menu items should reach their target. But it’s pretty easy to break that 
> chain, for example if the view isn’t set as allowing itself to become first 
> responder. Just having a pop-up menu doesn’t refocus the view.
> 
> The usual approach is to create a pop-up menu in IB and wire it directly to 
> the view that pops it up, targeting actions as needed. You don’t need to do 
> anything special to make this menu pop-up, it will do so automatically when 
> you right-click, and the target is directly set as the view (or other 
> objects) so the whole responder chain management is avoided. If your menu is 
> more dynamic, and creating a static menu in IB doesn’t seem to be a good fit, 
> look at the menu delegation protocol, which allows you to populate a menu on 
> the fly. You can still create a placeholder in IB to get automatic pop-up 
> behaviour.
> 
> —Graham
> 
> (Forgive any misinformation, I’m getting a little rusty).
> 
>> On 6 Mar 2023, at 3:27 am, Eyal Redler via Cocoa-dev 
>> <cocoa-dev@lists.apple.com> wrote:
>> 
>> Hi, 
>> 
>> 
>> I'm using popUpContextMenu:withEvent:forView: to show a context menu. The 
>> menu contains several items whose target is the first responder (that is, 
>> nil). But the items are not enabled and if I turn off autoEnable then the 
>> action is never called on the first responder.
>> 
>> Same target/action setup works just fine for the same items in the main 
>> menu, as expected.
>> 
>> Is this by design or am I missing something?
>> 
>> Tia
>> 
>> Eyal Redler
>> ------------------------------------------------------------------------------------------------
>> "If Uri Geller bends spoons with divine powers, then he's doing it the hard 
>> way."
>> --James Randi
>> www.eyalredler.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/graham.cox%40bigpond.com
>> 
>> This email sent to graham....@bigpond.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

Reply via email to