Commit 53570d10 authored by Tim Steenvoorden's avatar Tim Steenvoorden

Merge branch 'typed-task-editor' into typed-task-editor-simple

parent 75bde537
......@@ -3,28 +3,38 @@ module DynEditorExample
import StdEnv
import Data.Func
import Data.Functor
import Text
import iTasks
import iTasks.Extensions.Editors.DynamicEditor
// Synonyms ////////////////////////////////////////////////////////////////////
// Helpers /////////////////////////////////////////////////////////////////////
:: List a :== [a]
:: Message :== String
:: Button :== String
always x :== const True x
(>?>) infixl 1 :: (Task a) (List ( Button, a -> Bool, a -> Task b )) -> Task b | iTask a & iTask b
(>?>) task options = task >>* map trans options
where
trans ( a, p, t ) = OnAction (Action a) (ifValue p t)
// Main ////////////////////////////////////////////////////////////////////////
Start world = doTasks editTask world
Start world = doTasks (editTaskExpr Nothing) world
editTask :: Task Value
editTask = forever $
enterInformation ("Contruct a task", info1) [EnterUsing id $ dynamicEditor taskEditor]
>>= \v ->
viewInformation ("Evaluate the task", info2) [] ()
||- (evalTaskExpr (toValue taskEditor v) <<@ ApplyLayout frameCompact)
>>= viewInformation ("Done!", info3) []
>>= return // Extra return to disable `Continue` button
editTaskExpr :: (Maybe (DynamicEditorValue TaskExpr)) -> Task (Maybe (DynamicEditorValue TaskExpr))
editTaskExpr mv =
enterOrUpdateExpr ("Contruct a task", info1) mv >?>
[ ( "Run", always, \v -> viewInformation ("Evaluate the task", info2) [] () ||- (evalTaskExpr (toValue taskEditor v) <<@ ApplyLayout frameCompact) >?>
[ ( "Finish", always, \r -> viewInformation ("Done!", info3) [] r >?>
[ ( "Back", always, \_ -> editTaskExpr (Just v) ) ]
)
]
)
]
where
info1 :: String
info1 = "Select the editors and combinators you'd like to use. When you're ready, push the 'Continue' button below to run your program."
......@@ -33,6 +43,9 @@ where
info3 :: String
info3 = "The program is done, the result is given below."
enterOrUpdateExpr msg Nothing = enterInformation msg [EnterUsing id $ dynamicEditor taskEditor]
enterOrUpdateExpr msg (Just v) = updateInformation msg [UpdateUsing id (curry fst) (dynamicEditor taskEditor)] v
// Data ////////////////////////////////////////////////////////////////////////
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment