views:

353

answers:

1

Is there any way to achieve multiple selection behavior in an NSTableView without requiring the user to hold down the command button while clicking? This was easy to do in a Carbon list box, by ORing in the cmdKey modifier flag, during mouse down processing, on the call to the HandleControlClick() function. I am new to Cocoa, and it is not clear to me how I can easily modify an event programmatically, or if this is the best solution.

+1  A: 

Subclass NSTableView and make your table view an instance of this subclass. In the subclass, respond to both mouseDown: and mouseUp: by creating a new mouse event based on the one you received, only with the NSCommandKeyMask flag ORed into the modifier flags, and passing the new event up to super.

However, I hope it will be obvious to your user that they can select multiple items. Also, don't break the Shift key—make sure contiguous selection still works.

Peter Hosey
Thanks Peter! I ended up responding to mouseDown in the subclass, creating a new mouseDown event based on the one received, and ORing in the NSCommandKeyMask based on whether the NSShiftKeyMask was set. It works just great.
Er, yeah. Mouse is what I meant, not key. I've edited my answer accordingly.
Peter Hosey