Monday, September 22, 2014

#1 2013-05-08 10:42:32 am

Nik
Member
From: Colorado
Registered: 2005-11-09
Posts: 57
Website

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.

Offline

 

#2 2013-05-09 08:17:25 am

SuperMacGuy
Member
From: Amish Country, Lancaster, PA
Registered: 2004-06-23
Posts: 416
Website

Re: How to make a "smarter" delete button?

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.


Scripts for InDesign: http://chris.paveglio.com
ASOC & Cocoa, specializing in InDesign, Photoshop, Ai, FileMaker

Filed under: undo

Offline

 

#3 2013-05-11 05:45:52 pm

Shane Stanley
Member
From: Australia
Registered: 2002-12-07
Posts: 3631

Re: How to make a "smarter" delete button?

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.


Shane Stanley <sstanley@myriad-com.com.au>
www.macosxautomation.com/applescript/apps/

Offline

 

Board footer

Powered by FluxBB

[ Generated in 0.031 seconds, 10 queries executed ]

RSS (new topics) RSS (active topics)