Creating Undo/Redo Buttons

Let's look at how to work with Undo.

Open the Application

Open the application stored in the Starting Application folder of the homework folder. Open launcher.rev and click on it to load the application.

Open Experiment Stack

Edit 'Undo Last Change' Button Script

With the Edit tool active right-click on the Undo Last Change button and edit its script.

Paste In RevTalk Code

Set the script of the button to the following RevTalk code:

on mouseUp

if undoCanUndo() then

put undoUndoActionName() into theName

undoUndo

answer "Undo performed for action named:" && theName

else

answer "No undo action in queue"

end if

end mouseUp

 

What Does the Script Do?

This script will undo the first action in the Undo Queue.

1) Check to see if an undo can be performed. If there are no Undo Actions in the Undo Queue then the undoCanUndo() function returns false.

2) Get the name of the undo action. This is the 2nd parameter that was passed into undoStoreUndo and is useful for displaying to the user (e.g. in the Edit menu).

3) Perform the undo.

Edit 'Redo Last Change' Button Script

Paste in RevTalk Code

Set the script of the button to the following RevTalk code. The code is the same as the Undo button except that it uses the redo API calls.

on mouseUp

if undoCanRedo() then

put undoRedoActionName() into theName

undoRedo

answer "Redo performed for action named:" && theName

else

answer "No redo action in queue"

end if

end mouseUp

0 Comments

Add your comment

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.