1

When right-clicking on an item in an NSBrowser view the selection won't change. Instead the item clicked on gets a frame and a context menu is opened. Selected item and right-clicked item are two different things.

In Finder (browser view), the operations in the context menu operate on the item the user right-clicks on, which is what I expect. If I do the same with a custom NSBrowser control, the operations are applied to the selected item instead.

I have attached an empty NSMenu to NSBrowser.menu to get the services menu. There  are NSBrowser's clickedRow/clickedColumn properties which yield valid values when queried from [NSMenuDelegate menuWillOpen], but this does not help me with the system-generated Services menu items.

How can I make the context menu operate on the right-clicked item?

EDIT 2017-10-29

I have subclassed NSBrowser for drag&drop support. This is how the context menu is added. It is an empty NSMenu, the Services menu is added automatically.

- (void) awakeFromNib
{
    NSMenu *m = [[[NSMenu alloc] init] autorelease];
    m.delegate = self;
    self.menu = m;
}
C. Ocoa
  • 85
  • 6
  • How do you add the services to the menu? `NSBrowser` doesn't support any services. And how do you communicate with the service? – Willeke Oct 27 '17 at 22:51
  • It adds services in my case, see my edit. – C. Ocoa Oct 29 '17 at 08:39
  • I found the problem: I have implemented the `validRequestorForSendType:returnType` and `writeSelectionToPasteboard:types` methods. These methods get called when I right-click on an item. In these methods I query `[self selectedCell]`. But I have to query `[self.clickedColumn]` and `[self.clickedRow]`and use these values if they return positive values. – C. Ocoa Oct 29 '17 at 08:52

0 Answers0