Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

Marimuthu

macrumors member
Original poster
Oct 18, 2010
43
0
Dear all,

I have an application developed in 10.6 with Xcode 3.2.6 and consists of an window which contains a NSTableView where I display few text items in each of the rows.
I am able to select an row but the shortcut key to copy (i.e, Command + C) does not seem to work.
I would like this shortcut key to copy the contents onto the clipboard so that the contents can be pasted in some other location.
It would also be great if I can get a copy option (menu item) when I right-click a given row.
 
I've never done copy'n'paste for an NSTable, only drag'n'drop. I think Mac users are more likely to want to drag'n'drop because they're more used to the direct manipulation style of user experience.

Some things come to mind immediately.

The Pasteboard Programming Guide while tell you about the underlying mechanism of copy and paste.

You will need an Edit menu in the main menu bar with Copy and Paste menu items set up with Cmd+C and Cmd+V key equivalents.

The Using Drag and Drop in Tables chapter of the Drag and Drop Programming Topics for Cocoa guide shows how to do drag'n'drop. Perhaps it will give some insight into doing copy'n'paste as well. I'm thinking particularly of how to get your rows on and off the pasteboard.
 
I would like this shortcut key to copy the contents onto the clipboard so that the contents can be pasted in some other location.
Edit > Copy is connected to the first responder as the selector copy:, so you need to subclass NSTableView and implement that method. Best way would be to declare a new delegate method that your subclass calls so that you can handle it alongside your other table view code.

It would also be great if I can get a copy option (menu item) when I right-click a given row.

You can also do this with the NSTableView subclass, just override menuForEvent:
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.