Re: Context Menu and first responder targets
site_archiver@lists.apple.com Delivered-To: cocoa-dev@lists.apple.com Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mellel-com.20210112.gappssmtp.com; s=20210112; h=to:references:message-id:content-transfer-encoding:cc:date :in-reply-to:from:subject:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=kQU9G2Zi8JMY2gcFLX2mvgBtUvM7nopBJ57IFZIO9FI=; b=F3/bDPcMNu2CbO4/f3RzZxHcpR6U/5I17qOFKTkaVzWAFvAKtcDALlHvoNGitwAuqe 0LbkyZIN0jzfRSIBsLMX/uSC4a9BOd224yaPrAUEwGOrz6lvDf6I7n5S8l7J0h8pLKKo L5c99SDNb2ULqqG6MZ7gzLmlGuPqZCQLhDKmgcnuwxLQmfiBrGCeUBotVyxj2oLG/gHI SXhnZZ9TaHO9MT1BnS4xEhruEWczVqhwWMfjVDltaI0cNErWBLLXlBsdGpcWfdW44y2K M2/NhiXZkQ7YK5RXoVV0vuWkdV0pWG9YSOimMAL8Y+RZJ/SAPWfQtTKWvkIquSzUAMW2 /+BQ== 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.cox@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.cox@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/site_archiver%40lists.appl... This email sent to site_archiver@lists.apple.com
participants (1)
-
Eyal Redler via Cocoa-dev