• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag
 

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Context Menu and first responder targets
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Context Menu and first responder targets


  • Subject: Re: Context Menu and first responder targets
  • From: Eyal Redler via Cocoa-dev <email@hidden>
  • Date: Mon, 6 Mar 2023 09:09:27 +0200

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 <email@hidden> 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
>> <email@hidden> 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 (email@hidden)
>>
>> 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:
>>
>> This email sent to email@hidden
>

_______________________________________________

Cocoa-dev mailing list (email@hidden)

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:

This email sent to email@hidden

References: 
 >Context Menu and first responder targets (From: Eyal Redler via Cocoa-dev <email@hidden>)
 >Re: Context Menu and first responder targets (From: Graham Cox via Cocoa-dev <email@hidden>)

  • Prev by Date: Re: Context Menu and first responder targets
  • Next by Date: OS/X Java native bug
  • Previous by thread: Re: Context Menu and first responder targets
  • Next by thread: OS/X Java native bug
  • Index(es):
    • Date
    • Thread