Copy contents of selected NSTableView row using Cmd+C key.

Discussion in 'Mac Programming' started by Marimuthu, Sep 30, 2011.

  1. Marimuthu macrumors member

    Joined:
    Oct 18, 2010
    #1
    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.
     
  2. jiminaus macrumors 65816

    jiminaus

    Joined:
    Dec 16, 2010
    Location:
    Sydney
    #2
    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.
     
  3. Marimuthu thread starter macrumors member

    Joined:
    Oct 18, 2010
    #3
    Thanks a lot for the reply.

    I'll look into the link provided by you.
     
  4. kainjow Moderator emeritus

    kainjow

    Joined:
    Jun 15, 2000
    #4
    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.

    You can also do this with the NSTableView subclass, just override menuForEvent:
     

Share This Page