1

I have a WebView embedded in an NSStatusItem, and I want to display an NSMenu that I've built in Interface Builder when the user right clicks on the WebView / NSStatusItem. What is the easiest way to do this?

Chetan
  • 46,743
  • 31
  • 106
  • 145

2 Answers2

5

You can assign an object as the web view's WebUIDelegate and implement this delegate method:

- (NSArray *)webView:(WebView *)sender contextMenuItemsForElement:(NSDictionary *)element defaultMenuItems:(NSArray *)defaultMenuItems

where you can return array with custom created menu items.

PSyton
  • 908
  • 11
  • 18
-2
[statusItem setMenu:menu];

or for right click, make a new subclass of nsview. In your subclass add the method:

(void)rightMouseUp:(NSEvent *)theEvent

Then you can set the view to the statusItem [statusItem setView:view];

Craig Ringer
  • 307,061
  • 76
  • 688
  • 778
lbrndnr
  • 3,361
  • 2
  • 24
  • 34
  • Ah didn't see this. Just make a new subclass of nsview. In your subclass add the method: -(void)rightMouseUp:(NSEvent *)theEvent. Then you can set the view to the statusItem [statusItem setView:view]; – lbrndnr Mar 26 '11 at 09:39