UndoRedo.hs revision 260192a59aed3dbf3b339ea86d4009a7d1c0d728
b4a00883f358625923365ca1560c96edec172a52sfModule : $Header$
b4a00883f358625923365ca1560c96edec172a52sfDescription : description of undo and redo functions
b4a00883f358625923365ca1560c96edec172a52sfCopyright : uni-bremen and DFKI
b4a00883f358625923365ca1560c96edec172a52sfLicense : GPLv2 or higher, see LICENSE.txt
b4a00883f358625923365ca1560c96edec172a52sfMaintainer : r.pascanu@jacobs-university.de
b4a00883f358625923365ca1560c96edec172a52sfStability : provisional
b4a00883f358625923365ca1560c96edec172a52sfPortability : portable
b4a00883f358625923365ca1560c96edec172a52sfCMDL.UnDoRedo contains the implementation of the undo and redo commads
b4a00883f358625923365ca1560c96edec172a52sfimport Interfaces.History (redoOneStep, undoOneStep)
44f575c8cb19a7a5cd61664a7848be6bc197df02fuankgimport Interfaces.Command (showCmd)
b4a00883f358625923365ca1560c96edec172a52sfimport CMDL.DataTypesUtils (genMessage)
b4a00883f358625923365ca1560c96edec172a52sfimport CMDL.DataTypes (CmdlState (intState))
b4a00883f358625923365ca1560c96edec172a52sf-- | Undoes the last command entered
b4a00883f358625923365ca1560c96edec172a52sfcUndo :: CmdlState -> IO CmdlState
b4a00883f358625923365ca1560c96edec172a52sfcUndo = cdo True
b4a00883f358625923365ca1560c96edec172a52sf-- | Redoes the last undo command
b4a00883f358625923365ca1560c96edec172a52sfcRedo :: CmdlState -> IO CmdlState
b4a00883f358625923365ca1560c96edec172a52sfcRedo = cdo False
b4a00883f358625923365ca1560c96edec172a52sfcdo :: Bool -> CmdlState -> IO CmdlState
b4a00883f358625923365ca1560c96edec172a52sfcdo isUndo state =
b4a00883f358625923365ca1560c96edec172a52sf let msg = (if isUndo then "un" else "re") ++ "do"
b4a00883f358625923365ca1560c96edec172a52sf in case (if isUndo then undoList else redoList) . i_hist $ intState state of
b4a00883f358625923365ca1560c96edec172a52sf [] -> return $ genMessage [] ("Nothing to " ++ msg) state
b4a00883f358625923365ca1560c96edec172a52sf action : _ ->
b4a00883f358625923365ca1560c96edec172a52sf nwIntState <- (if isUndo then undoOneStep else redoOneStep)
b4a00883f358625923365ca1560c96edec172a52sf $ intState state
b4a00883f358625923365ca1560c96edec172a52sf return . genMessage [] ("Action '" ++ showCmd (command action)
b4a00883f358625923365ca1560c96edec172a52sf ++ "' is now " ++ msg ++ "ne")
b4a00883f358625923365ca1560c96edec172a52sf $ state { intState = nwIntState }