• 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: NSTextView attachments and context menus
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSTextView attachments and context menus


  • Subject: Re: NSTextView attachments and context menus
  • From: Keith Blount <email@hidden>
  • Date: Tue, 9 Mar 2010 00:43:16 -0800 (PST)

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@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

  • Follow-Ups:
    • Re: NSTextView attachments and context menus
      • From: Martin Hewitson <email@hidden>
  • Prev by Date: Re: NSTextView attachments and context menus
  • Next by Date: Re: Custom View in Toolbar
  • Previous by thread: Re: NSTextView attachments and context menus
  • Next by thread: Re: NSTextView attachments and context menus
  • Index(es):
    • Date
    • Thread