Version: 01.10.10 - last Update: Tuesday, October 13, 2009, 13:05:00
Foxtools Editor Support Functions
_EDUNDOON
_EdUndoOn() Creates a group of undo-/redo-able actions in the editor session window passed in <nWHAND> parameter.
VFP Syntax
= _EdUndoOn(nWHAND, lOpenClose)
Parameters
[in] nWHAND
Fox-window handle of the editor session in question. If nWHANDL is no valid editor-session handle, an error “API call caused an exception” (Error 2028) is raised.
[in] lOpenClose
Controls the grouping: TRUE opens a new group, FALSE closes the (last opened) group
Returns
VOID - no evaluable return value, coz always TRUE.
Remarks
With _EdUndoOn() one can group an arbitrary set of editor actions. Groups cannot be nested.
Background:
Every editor action, either interactive or programmatic is pushed on an internal action-stack which has a typical FIFO (first in, first out) layout. _EdUndo() pops the last action from that action-stack, reverts the action’s outcome in the editor’s text buffer and then pushes the action on a second undo-stack which has the same FIFO layout. _EdRedo() reverts this process by popping the last action from that undo-stack, re-applies its outcome to the text buffer and then pushes the action back on the action-stack again.
_EdUndoON(wh, .T.) creates some kind of basket (or envelop) holding multiple actions that gets pushed on the action-stack when _EdUndoON(wh, .F.) or _EdUndo() is called. Internally the group-container is handled like a single action while being pushed and popped on and from the stacks. The only difference is, that more than on action has to be applied/reverted to the editor’s text buffer in case of a group.
VFP Example(s)
Opening an editor session, activating multiple undo-grouping, finally issuing some _EdUndo()s and _EdRedo()s to roll the whole sequence back and forth:
*\\ Open text editor session nWHAND =_EDOPENFIL("TEST.TXT", 1) lcText = "1.) This is a single line inserted without undo-grouping"+CHR(13) = _EDINSERT(m.nWHAND, m.lcText, LEN(m.lcText)) lcText = "2.) Another single line inserted without undo-grouping"+CHR(13) = _EDINSERT(m.nWHAND, m.lcText, LEN(m.lcText)) lcText = "3.) After this line 1st undo-group will be created"+CHR(13) = _EDINSERT(m.nWHAND, m.lcText, LEN(m.lcText)) *\\ Create undo-group ---------------------- =_EDUNDOON(m.nWHAND,.T.) lcText = "4a) Line inserted while 1st undo-grouping is active"+CHR(13) = _EDINSERT(m.nWHAND, m.lcText, LEN(m.lcText)) lcText = "4b) Line inserted while 1st undo-grouping is active"+CHR(13) = _EDINSERT(m.nWHAND, m.lcText, LEN(m.lcText)) lcText = "4c) After this line 1st undo-group will be closed"+CHR(13) = _EDINSERT(m.nWHAND, m.lcText, LEN(m.lcText)) *\\ Close undo-group ---------------------- =_EDUNDOON(m.nWHAND,.F.) *\\ Create another undo-group ---------------------- =_EDUNDOON(m.nWHAND,.T.) lcText = "5a) Line inserted while 2nd undo-grouping is active"+CHR(13) = _EDINSERT(m.nWHAND, m.lcText, LEN(m.lcText)) lcText = "5b) Line inserted while 2nd undo-grouping is active"+CHR(13) = _EDINSERT(m.nWHAND, m.lcText, LEN(m.lcText)) lcText = "5c) After this line 2nd undo-group will be closed"+CHR(13) = _EDINSERT(m.nWHAND, m.lcText, LEN(m.lcText)) *\\ Close undo-group ---------------------- =_EDUNDOON(m.nWHAND,.F.) lcText = "6.) This is a single line inserted without undo-grouping"+CHR(13) = _EDINSERT(m.nWHAND, m.lcText, LEN(m.lcText)) lcText = "7.) This is the last line inserted without undo-grouping" + CHR(13) + ; " What do you think - how many times we have to call " + CHR(13) + ; " EdUndo() to clear the editor session completely?" = _EDINSERT(m.nWHAND, m.lcText, LEN(m.lcText)) *// WAIT WINDOW "Press any key to UNDO changes (1)" = _EDUNDO(m.nWHAND) WAIT WINDOW "Press any key to UNDO changes (2)" = _EDUNDO(m.nWHAND) WAIT WINDOW "Press any key to UNDO changes (3)" = _EDUNDO(m.nWHAND) WAIT WINDOW "Press any key to UNDO changes (4)" = _EDUNDO(m.nWHAND) WAIT WINDOW "Press any key to UNDO changes (5)" = _EDUNDO(m.nWHAND) WAIT WINDOW "Press any key to UNDO changes (6)" = _EDUNDO(m.nWHAND) WAIT WINDOW "Press any key to UNDO changes (7)" = _EDUNDO(m.nWHAND) *// WAIT WINDOW "Press any key to REDO changes (1)" = _EDREDO(m.nWHAND) WAIT WINDOW "Press any key to REDO changes (2)" = _EDREDO(m.nWHAND) WAIT WINDOW "Press any key to REDO changes (3)" = _EDREDO(m.nWHAND) WAIT WINDOW "Press any key to REDO changes (4)" = _EDREDO(m.nWHAND) WAIT WINDOW "Press any key to REDO changes (5)" = _EDREDO(m.nWHAND) WAIT WINDOW "Press any key to REDO changes (6)" = _EDREDO(m.nWHAND) WAIT WINDOW "Press any key to REDO changes (7)" = _EDREDO(m.nWHAND)