I wonder if anyone knows of a way to detect and take action when the user changes the selection within a table with the keyboard… something similar to setting up a double click action with:
First a setDoubleAction: doesn’t mean that the assigned method will be fired when the selection changes. It can also be fired without changing the selection. Then an NSTableView is a subclass of NSResponder so it will receive an key down and key up event when the user pressed a button.
The easiest way is subclassing an NSTableView and add the keyDown event
--this is something I almost literally translated from Objective-C to ASOC in text editor. So the code doesn't have to work but should indicate how to tackle the issue.
on keyDown_(theEvent)
set chars to theEvent's characters()
repeat with char in chars
if char = NSUpArrowFunctionKey then
--do something
end
end repeat
continue keyDown_(theEvent)--continue following the parenting chain
end keyDown_
Do you need to know whether the selection change was done from the keyboard, or just that there was a selection change? If it’s the latter, you can use the delegate method, tableViewSelectionDidChange:. It’s triggered regardless of how the selection was changed.
set theNotificationCenter to current application's NSNotificationCenter's defaultCenter()
tell theNotificationCenter to addObserver_selector_name_object_(me, "tableViewSelectionChanged:", "NSTableViewSelectionDidChangeNotification", missing value)
and:
on tableViewSelectionChanged_(aNotification)
log "TABLE CHANGE"
end
Sadly I had to get rid of the calls to the notification center I mention above as they were firing off multiple times when table rows were created and at other random times.
I simply connected my table to a subroutine through the interface and that fixed it. It doesn’t register clicks up and down on the keyboard which was my original intention of this but I’ve given up on that.