views:

28

answers:

2

Hi!, I have 5 NSTableView's instances that have the same contextual menu. When I get the message that the menu has been clicked I need to know which table sent it. I've checked the NSMenu documentation but I don't seem to find a way to check which of the tables opened the menu..

I'm thinking of subclassing NSTableView and send a message to the delegate on menuForEvent, would that be the best way?

Thank you, Jose.

A: 

I don't see a way to get this information. Menus aren't "attached" to anything; they're displayed in a location. Your -menuForEvent: override might work but it gives me the willies.

While this isn't an answer to your question, I confess my first reaction is "why do you have multiple tables with exactly the same menu?" This strikes me more as a UI issue. One would think a contextual menu would be pretty specific to the specific kind of thing (or view thereof) that it represents. That begs the question: why do you have 5 table views that all have exactly the same context? If all 5 tables represent things that are controlled in the same way by the (presumably) same controller, it's highly likely there's a better way to represent your "collection of things" than 5 separate tables.

I'm making a lot of assumptions, granted, but my curiosity is getting the best of me, I suppose. :-)

Joshua Nozzi
A: 

Thanks Joshua, I,am using 5 tables to display a 5 day week task planning. Each table represents a week day, and I added the contextual menu for adding and removing tasks. So when a user clicks "add task" on a week day I need to know which one. I've got it working by subclassing tableview and sending a message to the delegate when the menu is opened. In this manner my controller knows which of the tables was the last to call the menu. But it doesn't seem to me like the best implementation to get this, maybe is like you said the problem lies on the UI, what do you think? Jose.

the Reverend