I have a question.How I add a mouse right-down menu to the NSCollectionViewItem. As an attempt I alse use the Apple's demo app IconCollection.I tryed drag a NSMenu to the IconViewPrototype.xib and connect it to the view's menu outlet in IB.but when build and run,click the mouse right click,nothing happened.I think the NSBox also a subclass for NSView,the mouse right-down menu should be support.
Asked
Active
Viewed 777 times
1 Answers
3
I ended up creating an NSView
subclass to use as a View for the CollectionViewItem
. In there I set a delegate (connected in IB), and used this to catch the right mouse click and open the menu:
-(void)rightMouseDown:(NSEvent *)theEvent {
NSMenu *menu = [self.delegate menuForCollectionItemView:self];
[menu popUpMenuPositioningItem:[[menu itemArray] objectAtIndex:0]
atLocation:NSZeroPoint
inView:self];
}
This still needs some code to position the menu where the user clicked, but it's a start.
If anyone has a cleaner method I'd love to hear it.

Bob Vork
- 2,927
- 28
- 32
-
I came here for the same question. Your solution is still missing a few things, though: 1. It does not handle ctrl-click (which should behave like a right click). 2. It should select the item that's clicked on (and deselect others if the item wasn't already selected). – Thomas Tempelmann May 22 '19 at 21:01