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?
Asked
Active
Viewed 1,477 times
1
-
1a `WebView` inside an `NSStatusItem`?? That sounds *extremely* unconventional... – Dave DeLong Mar 26 '11 at 07:24
-
Haha, I know, but I have my reasons :) – Chetan Mar 26 '11 at 08:16
2 Answers
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