Text Field Example
Now let's look at how to undo changes to a field.
Edit Script of Field
Set Field Script
Set the script of the field to the following RevTalk code. Read the comments for an explanation of what is going on.
local sMementoA
-- message sent by the Revolution engine when
-- focus enters the field
on openField
## Store content of field so we can undo changes the
## user makes. No undo entry is made here however
## as the user hasn't made any changes yet.
put the long id of the target into sMementoA["field"]
put the htmltext of the target into sMementoA["htmltext"]
pass openField
end openField
-- message sent by the Revolution engine when focus
-- leaves the field and the user has changed the field
-- contents by typing
on closefield
LogUndoIfNecessary
pass closefield
end closefield
-- message sent by the Revolution engine when focus
-- leaves the field and the user has NOT changed the field
-- contents by typing. Content could have been changed
-- by RevTalk code though so we need to check whether
-- or not an undo should be logged.
on exitField
LogUndoIfNecessary
pass exitField
end exitField
command LogUndoIfNecessary
## If the content of the field has changed since the openField
## message was received then add an undo action to the queue
## 'the target' will always be the field as this command is
## called from closeField and exitField.
if the htmltext of the target is not sMementoA["htmltext"] then
undoStoreUndo "edit field content", "Edit Text", sMementoA
end if
## Clear memory
put empty into sMementoA
end LogUndoIfNecessary
Switch to Browse Tool
Edit Field Text
Click inside the field. This triggers the openField message. Edit the text. Even though a change has been made the undo manager doesn't know about it yet and doesn't post an undo action to the queue. An undo action will be posted to the queue when the closeField or exitField message is received.
Click Outside Field
Clicking outside the field triggers the closeField message which in turn posts an Undo Action to the Undo Queue.
Click 'Undo Last Change'
The text will change to the original value and a dialog will appear showing you what happened.
0 Comments
Add your comment