NSTableView + delete button?

  • I'm using an NSTableView, and I want to be able to remove items from the
    list by pressing the delete key on the keyboard. What is the procedure to
    receive a message when a key is pressed and the table view has focus?

    Thanks,

    -Kevin
  • On Mar 11, 2008, at 3:03 PM, Kevin Dixon wrote:

    > I'm using an NSTableView, and I want to be able to remove items from
    > the
    > list by pressing the delete key on the keyboard. What is the
    > procedure to
    > receive a message when a key is pressed and the table view has focus?

    Subclass NSTableView and override "-keyDown:". There should be several
    implementations of this online that you could take a look at.

    j o a r
  • On Mar 11, 2008, at 15:12, j o a r wrote:

    > On Mar 11, 2008, at 3:03 PM, Kevin Dixon wrote:
    >
    >> I'm using an NSTableView, and I want to be able to remove items
    >> from the
    >> list by pressing the delete key on the keyboard. What is the
    >> procedure to
    >> receive a message when a key is pressed and the table view has focus?
    >
    >
    > Subclass NSTableView and override "-keyDown:". There should be
    > several implementations of this online that you could take a look at.
    >
    > j o a r

    You can also do it by adding a "delete:" action method to the document
    or window controller that is in charge of the table view's window, and
    have that action do whatever is necessary (in the simplest case, send
    a "remove:" action to the NSArrayController controlling the table view).

    The catch is that you may need to look at the window's first responder
    to check that the delete came from the table view and not somewhere
    else in the window.

    But it's fairly easy to add refinements like confirmation dialogs if
    you use this approach.
  • >
    > On Mar 11, 2008, at 3:03 PM, Kevin Dixon wrote:
    >
    >> I'm using an NSTableView, and I want to be able to remove items from
    >> the
    >> list by pressing the delete key on the keyboard. What is the
    >> procedure to
    >> receive a message when a key is pressed and the table view has focus?
    >
    >
    > Subclass NSTableView and override "-keyDown:". There should be several
    > implementations of this online that you could take a look at.
    >
    > j o a r

    I have implemented -keyDown as such

    if([theEvent type] == NSKeyDown) {
    if([theEvent keyCode] == 51) {
      //process 'delete' press
    }
    }

    to catch the pressing of delete on the NSTableView. This works, but
    reminds me of BASIC...Is there a better way to do this, to make sure I'm
    getting the delete key, say even on international keyboards?

    -Kevin
  • On Mar 11, 2008, at 5:47 PM, Kevin Dixon wrote:

    >

    > to catch the pressing of delete on the NSTableView. This works, but
    > reminds me of BASIC...Is there a better way to do this, to make sure
    > I'm
    > getting the delete key, say even on international keyboards?

    See "NSDeleteCharacter" and similar in NSText.h (and in the
    documentation).

    j o a r
  • On 3/11/08 8:47 PM, Kevin Dixon said:

    > I have implemented -keyDown as such
    >
    > if([theEvent type] == NSKeyDown) {
    > if([theEvent keyCode] == 51) {
    > //process 'delete' press
    > }
    > }
    >
    > to catch the pressing of delete on the NSTableView. This works, but
    > reminds me of BASIC...Is there a better way to do this, to make sure I'm
    > getting the delete key, say even on international keyboards?

    See NSResponder's deleteBackward: method and docs.

    --
    ____________________________________________________________
    Sean McBride, B. Eng                <sean...>
    Rogue Research                        www.rogue-research.com
    Mac Software Developer              Montréal, Québec, Canada