home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 5 Edit / 05-Edit.zip / epmsmp.zip / UNDOREDO.E < prev    next >
Text File  |  1996-03-15  |  3KB  |  66 lines

  1.  
  2. /* The following code defines a couple of keys that let you step backwards
  3. and forwards through the undo states.  For the sake of example, I've
  4. defined the Undo key as Ctrl+U and the Redo key as Ctrl+R.  You might
  5. prefer to select other keys that don't conflict with standard EPM key
  6. definitions.  One important note - the way that the keys determine if
  7. you're still in an undo/redo sequence is checking if the previous key
  8. pressed was also Ctrl+U or Ctrl+R.  Because of the way keys are handled,
  9. you must press and hold the Ctrl key for as long as you're stepping back
  10. and forth (by pressing U and R) - once you release the Ctrl key, the next
  11. time you press Ctrl+U or Ctrl+R, they will see the previously-pressed key
  12. as being the Ctrl key, not Ctrl+U or Ctrl+R.  The same is true if you
  13. define the keys to be a Shift or Alt combination (which implies that they
  14. both have to have the same shift state - both start with s_, both with c_,
  15. both with a_, or both unshifted).
  16.  
  17. Note also that this assumes the user has not enabled undo-state recording
  18. on *every* keystroke.  If you did, then you might have to add code here
  19. to stop recording changes on keystrokes, and it's not clear how you'd
  20. figure out when to turn it back on.
  21.                                          by:  Larry Margolis  */
  22.  
  23. define
  24.    undo_key = 'c_U'  -- (Ctrl+U normally pops the Undo dialog)
  25.    redo_key = 'c_R'  -- (Ctrl+R normally starts recording keystrokes)
  26.  
  27. def $undo_key =
  28.    universal current_undo_state
  29.    lk = lastkey(1)
  30.    if lk = $undo_key | lk = $redo_key then  -- last key was undo or redo
  31.       parse value current_undo_state with presentstate oldeststate neweststate
  32.       if presentstate > oldeststate then
  33.          presentstate = presentstate - 1
  34.          undoaction 7, presentstate
  35.          current_undo_state = presentstate oldeststate neweststate
  36.       else
  37.          call beep(800, 500)
  38.       endif
  39.       sayerror 'Now at state' presentstate 'of' neweststate
  40.       return
  41.    endif
  42.    -- Need to get new state information
  43.    undoaction 1, starting_state  -- Do to fix range and for value.
  44.    undoaction 6, StateRange               -- query range
  45.    parse value staterange with oldeststate neweststate
  46.    presentstate = neweststate - 1
  47.    undoaction 7, presentstate
  48.    current_undo_state = presentstate oldeststate neweststate
  49.    sayerror 'Initialized:  at state' presentstate 'of' neweststate
  50.  
  51. def $redo_key =
  52.    universal current_undo_state
  53.    lk = lastkey(1)
  54.    if lk = $undo_key | lk = $redo_key then  -- last key was undo or redo
  55.       parse value current_undo_state with presentstate oldeststate neweststate
  56.       if presentstate < neweststate then
  57.          presentstate = presentstate + 1
  58.          undoaction 7, presentstate
  59.          current_undo_state = presentstate oldeststate neweststate
  60.          sayerror 'Now at state' presentstate 'of' neweststate
  61.          return
  62.       endif
  63.       sayerror 'Already at state' presentstate 'of' neweststate
  64.    endif
  65.    call beep(800, 500)
  66.