How to make a "smarter" delete button?

I’ve followed the tutorial in Applescript ObjC Explored (thank you, Shane, it’s awesome!) and built myself a table of objects with Add and Remove buttons – both bound to the respective methods in the array handler.

What I would like to do is make the remove just a little bit smarter:

First, setDocumentEdited on the main window (I use the window state since the app manages a text file).

Second, make it possible to undo the delete and add the object back into the array with a CMD+Z.

Because the button is linked to the array’s remove method, I can’t add additional functions. Also, I’m generally confused on how to handle undos in general within AppleScript ObjC.

If any of you have some tips on this, I’d really appreciate it. Code examples would be especially useful – I’m still learning my way around converting more complex Cocoa methods into AppleScript format.

Have you used undo in Cocoa? I’ve got the Hillegass book and been in the class, it’s not quite the easiest thing. NSUndoManager and NSInvocation are needed. I think you’d have to have a method for each adding a person and removing a person. They could still be directed to add the object to the array with not a lot of new code, but then would also include something like
current application’s NSUndoManager’s defaultManager’s prepareWithInvocationTarget_(something) …

I’m not quite sure where this code is going but I’m looking at chapter 9 of Cocoa Programming 3rd edition.

As Chris says, undos are complex. If you need them, you will probably need to move to Objective-C at some stage.

You can implement setDocumentEdited_ by having the button trigger a handler that includes it, and which then calls remove_ on the array controller.