module CMDL.UndoRedo
( cUndo
, cRedo
) where
import Interfaces.History (redoOneStep, undoOneStep)
import Interfaces.Command (showCmd)
import Interfaces.DataTypes
import CMDL.DataTypesUtils (genMessage)
import CMDL.DataTypes (CmdlState (intState))
cUndo :: CmdlState -> IO CmdlState
cUndo :: CmdlState -> IO CmdlState
cUndo = Bool -> CmdlState -> IO CmdlState
cdo Bool
True
cRedo :: CmdlState -> IO CmdlState
cRedo :: CmdlState -> IO CmdlState
cRedo = Bool -> CmdlState -> IO CmdlState
cdo Bool
False
cdo :: Bool -> CmdlState -> IO CmdlState
cdo :: Bool -> CmdlState -> IO CmdlState
cdo isUndo :: Bool
isUndo state :: CmdlState
state =
let msg :: [Char]
msg = (if Bool
isUndo then "un" else "re") [Char] -> [Char] -> [Char]
forall a. [a] -> [a] -> [a]
++ "do"
in case (if Bool
isUndo then IntHistory -> [CmdHistory]
undoList else IntHistory -> [CmdHistory]
redoList) (IntHistory -> [CmdHistory])
-> (IntState -> IntHistory) -> IntState -> [CmdHistory]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. IntState -> IntHistory
i_hist (IntState -> [CmdHistory]) -> IntState -> [CmdHistory]
forall a b. (a -> b) -> a -> b
$ CmdlState -> IntState
intState CmdlState
state of
[] -> CmdlState -> IO CmdlState
forall (m :: * -> *) a. Monad m => a -> m a
return (CmdlState -> IO CmdlState) -> CmdlState -> IO CmdlState
forall a b. (a -> b) -> a -> b
$ [Char] -> [Char] -> CmdlState -> CmdlState
genMessage [] ("Nothing to " [Char] -> [Char] -> [Char]
forall a. [a] -> [a] -> [a]
++ [Char]
msg) CmdlState
state
action :: CmdHistory
action : _ ->
do
IntState
nwIntState <- (if Bool
isUndo then IntState -> IO IntState
undoOneStep else IntState -> IO IntState
redoOneStep)
(IntState -> IO IntState) -> IntState -> IO IntState
forall a b. (a -> b) -> a -> b
$ CmdlState -> IntState
intState CmdlState
state
CmdlState -> IO CmdlState
forall (m :: * -> *) a. Monad m => a -> m a
return (CmdlState -> IO CmdlState)
-> (CmdlState -> CmdlState) -> CmdlState -> IO CmdlState
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Char] -> [Char] -> CmdlState -> CmdlState
genMessage [] ("Action '" [Char] -> [Char] -> [Char]
forall a. [a] -> [a] -> [a]
++ Command -> [Char]
showCmd (CmdHistory -> Command
command CmdHistory
action)
[Char] -> [Char] -> [Char]
forall a. [a] -> [a] -> [a]
++ "' is now " [Char] -> [Char] -> [Char]
forall a. [a] -> [a] -> [a]
++ [Char]
msg [Char] -> [Char] -> [Char]
forall a. [a] -> [a] -> [a]
++ "ne")
(CmdlState -> IO CmdlState) -> CmdlState -> IO CmdlState
forall a b. (a -> b) -> a -> b
$ CmdlState
state { intState :: IntState
intState = IntState
nwIntState }