|
|
|
|
- Overview
- How to?
- Example
- WLanguage functions
Managing actions with Undo/Redo
WINDEV allows you to easily manage the Undo/Redo feature in your applications with the ActionXXX functions. To do so, the user can press Ctrl + Z and Ctrl + Y to easily undo or redo an action. To manage the Undo/Redo feature in your WINDEV applications: - Declare the actions to save in the stack of actions performed by ActionDo. This function expects as parameter the name of the procedure that corresponds to the action. This procedure can be a local, global or internal procedure.
- In the code of the procedure corresponding to the action to perform, use ActionDeclareUndo to define the code that will be run to cancel the action. This function expects as parameter the name of the procedure to run. This procedure can be a local, global or internal procedure.
- Use the following functions if necessary:
Remarks: - You cannot stack several times the SAME actions defined by ActionDo. Each action requested by ActionDo deletes the previous identical action. Therefore, only the last SAME action can be canceled.
- In the context menu of a control, the "Cancel" option proposed by default does not have the same effect as ActionUndo or Ctrl + Z.
Example The following example is used to modify the background color of two edit controls. This action can be undone by Ctrl + Z: ActionDo(WIN_ACTION, Color)  INTERNAL PROCEDURE Color EDT_LastName.BackgroundColor = PastelGreen EDT_FirstName.BackgroundColor = PastelRed  ActionDeclareUndo(GoBack) INTERNAL PROCEDURE GoBack EDT_LastName.BackgroundColor = DefaultColor EDT_FirstName.BackgroundColor = DefaultColor END END
To allow the user to undo several actions, simply call ActionDo several times with different procedures. For example: ActionDo(WIN_ACTION, Color) ActionDo(WIN_ACTION, StoreValue)  INTERNAL PROCEDURE Color EDT_LastName.BackgroundColor = PastelGreen EDT_FirstName.BackgroundColor = PastelRed  ActionDeclareUndo(GoBack) INTERNAL PROCEDURE GoBack EDT_LastName.BackgroundColor = DefaultColor EDT_FirstName.BackgroundColor = DefaultColor END END  INTERNAL PROCEDURE StoreValue() EDT_LastName.Note = EDT_LastName EDT_FirstName.Note = EDT_FirstName  ActionDeclareUndo(GoBack) INTERNAL PROCEDURE GoBack EDT_LastName = EDT_LastName.Note EDT_FirstName = EDT_FirstName.Note END END
In this example, the first Ctrl + Z will undo the storage of values and the second will undo the coloring of controls. The following WLanguage functions are used to manage the actions:
| | ActionDeclareUndo | Declares how to cancel an action that was added by ActionDo. This function MUST be called when running the procedure supplied to ActionDo. | ActionDo | Creates and runs a custom action (defined through programming) with support of "Undo/Redo". | ActionRedo | Runs the last action canceled. | ActionUndo | Cancels the last action performed by the end user. |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|