Hi,
As (the other) Martin says, you can subclass NSTextView and override
-menuForEvent: for this, which is the best way of doing it if you need to
provide support for systems running versions of OS X earlier than Leopard. If
you only need to support Leopard or above, though, Leopard introduced a
delegate method which should do the same thing and obviate the need to subclass:
- (NSMenu *)textView:(NSTextView *)view menu:(NSMenu *)menu forEvent:(NSEvent
*)event atIndex:(NSUInteger)charIndex
So you should just be able to check for an attachment at charIndex and if one
is detected return your own custom menu; otherwise return the standard menu
that is passed in. (Note that I've never used this delegate method myself,
though, as my app still needs to support Tiger, so I use Martin's way.)
All the best,
Keith
--- Original Message ---
Dear list,
I have an NSTextView which support dragging files in, either to create a link
to the file, or to add the file as an attachment. So far so good.
Now I want to offer the user a context menu to perform operations on the
attachment (open, save, etc). So far I was unable to find a way to intercept a
'right-click' on the nstextview to offer a custom context menu. What I did get
working is the single left-click version by implementing
textView:clickedOnCell:inRect:atIndex: in the text view's delegate. In that
method I create a context menu and show it at the mouse location using NSMenu's
popUpContextMenu:withEvent:forView:. That works, but with one problem. The
context menu that appears has two additional menu items: "Import Image" and
"Capture Selection from Screen". So I have three questions:
1) Is there a better way to achieve what I want?
2) Where do these additional menu items come from? Are they services?
3) How could I do this with a right-click instead of a single-click?
I have another question about attachments, but I'll post that separately.
Thanking you in advance,
Martin
_______________________________________________
Cocoa-dev mailing list ([email protected])
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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com
This email sent to [email protected]