Re: Getting the context of a context menu
Re: Getting the context of a context menu
- Subject: Re: Getting the context of a context menu
- From: Nicko van Someren <email@hidden>
- Date: Fri, 13 Apr 2007 12:53:24 +0100
On 12 Apr 2007, at 18:32, Andy Lee wrote:
On Apr 12, 2007, at 7:50 AM, Nicko van Someren wrote:
So, is there some way that I've not found to determine which view
was responsible for raising a context menu, or am I going to have
to subclass every standard UI item I use just so that I can bolt
in a -menuForEvent: method that says { menuContext = self; return
[self menu]; }
Offhand I don't see a built-in way to do it. I'd file an
enhancement request, since this seems like something people could
need from time to time.
I think I shall do that.
My first thought was poseAs. You could override NSView's -
menuForEvent: so that it remembers self in a global variable, so
you can always see what the last view was that did a -
menuForEvent:. Your menu action could assume that was the view
that was right-clicked. Then you could have your subclass pose as
NSView.
Yes, using poseAs was the solution I was reluctantly heading
towards. Doing this right seems to involve doing it in NSView, and
if the base class does not do it then either I have to sub-class
everything or I have to sub-class NSView and hack it in there.
But IIRC, poseAs is going away in Leopard. Maybe instead of
poseAs, you could try a method-swapping hack as described here:
http://theocacao.com/document.page/266.
I was not aware that poseAs is in danger of going away in Leopard,
but I'm not sure that I can bring myself to swizzling methods; it
just seems to nasty!
Does somebody have a less hacky way?
I hope so!
Nicko
_______________________________________________
Cocoa-dev mailing list (email@hidden)
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