Apple Newton Utilities User's Guide Page 624

  • Download
  • Add to my manuals
  • Print
  • Page
    / 942
  • Table of contents
  • BOOKMARKS
  • Rated. / 5. Based on customer reviews
Page view 623
CHAPTER 17
Additional System Services
17-8 Using Additional System Services
Using Undo Actions 17
The following code example shows how to provide undo capability in a view.
Imagine you have a view that uses cards. The view has a particular method,
DeleteCard, that it uses to delete a card. Within the DeleteCard method, you
call the
AddUndoAction method, passing as its arguments the name of the card
deleted and a different method that will add the card (thereby undoing the delete
operation). Your call to
view:AddUndoAction would look like the one in the
following code fragment:
DeleteCard: func(theCard)
begin
// statements that delete a card
...
// call AddCard as an undo action
:AddUndoAction ('AddCard, [theCard])
end,
You also need to supply the AddCard method, which would look similar to the
following example. It too provides an undo action—one that calls the original
action, thereby completing the Undo/Redo cycle.
AddCard: func(theCard)
begin
// statements that add a card
. . .
// call DeleteCard as an undo action
:AddUndoAction ('DeleteCard, [theCard])
end,
The Various Undo Methods 17
The AddUndoAction method ties an undo action to a specic view. If that view is
no longer open when the user taps Undo, the action does not take place. Because
an undo action should generally cause a visible change, it is often desirable to tie
the undo actions to views.
When it is not desirable or feasible to tie an undo action to an open view, you can
use the
AddUndoCall or AddUndoSend functions to execute the undo action
unconditionally. For example, view methods usually use the
AddUndoAction
view method to post their undo action; however, if the view will not be open when
the user taps Undo, you may need to use the
AddUndoCall or AddUndoSend
functions to post the undo action. If your action relies on the view being open or
some other condition, it must test that condition explicitly.
Page view 623
1 2 ... 619 620 621 622 623 624 625 626 627 628 629 ... 941 942

Comments to this Manuals

No comments