Commit 4807bf11 authored by Peter Achten's avatar Peter Achten

refactored Editor-parameters to decrease String size of graph_to_sapl_string

applied John's idea to refactor functions that passed on Editor in order to get to their member functions by added pattern-matches to the functions directly
parent bb9d4d00
......@@ -63,10 +63,10 @@ withClientSideInit ::
withClientSideInit initUI genUI dp val vst=:{VSt|taskId} = case genUI dp val vst of
(Ok (UI type attr items,mask),vst=:{VSt|iworld}) = case editorLinker initUI iworld of
(Ok (saplDeps, saplInit),iworld)
# extraAttr = 'DM'.fromList [("taskId",JSONString taskId)
,("editorId",JSONString (editorId dp))
,("saplDeps",JSONString saplDeps)
,("saplInit",JSONString saplInit)
# extraAttr = 'DM'.fromList [("taskId", JSONString taskId)
,("editorId",JSONString (editorId dp))
,("saplDeps",JSONString saplDeps)
,("saplInit",JSONString saplInit)
]
= (Ok (UI type ('DM'.union extraAttr attr) items,mask), {VSt|vst & iworld = iworld})
(Error e,iworld)
......
......@@ -12,111 +12,111 @@ from Text.GenJSON import :: JSONNode
//# UIContainer
container :: Editor ()
containerl :: (Editor a) -> Editor [a]
containerL :: [Editor a] -> Editor [a]
container1 :: (Editor a) -> Editor a
container2 :: (Editor a) (Editor b) -> Editor (a,b)
container3 :: (Editor a) (Editor b) (Editor c) -> Editor (a,b,c)
container4 :: (Editor a) (Editor b) (Editor c) (Editor d) -> Editor (a,b,c,d)
container5 :: (Editor a) (Editor b) (Editor c) (Editor d) (Editor e) -> Editor (a,b,c,d,e)
containerc :: (Editor Int) [(a -> a, Editor a)] -> Editor (Int, a)
containerl :: !(Editor a) -> Editor [a]
containerL :: ![Editor a] -> Editor [a]
container1 :: !(Editor a) -> Editor a
container2 :: !(Editor a) !(Editor b) -> Editor (a,b)
container3 :: !(Editor a) !(Editor b) !(Editor c) -> Editor (a,b,c)
container4 :: !(Editor a) !(Editor b) !(Editor c) !(Editor d) -> Editor (a,b,c,d)
container5 :: !(Editor a) !(Editor b) !(Editor c) !(Editor d) !(Editor e) -> Editor (a,b,c,d,e)
containerc :: !(Editor Int) ![(a -> a, Editor a)] -> Editor (Int, a)
//# UIPanel
panel :: Editor ()
panell :: (Editor a) -> Editor [a]
panelL :: [Editor a] -> Editor [a]
panel1 :: (Editor a) -> Editor a
panel2 :: (Editor a) (Editor b) -> Editor (a,b)
panel3 :: (Editor a) (Editor b) (Editor c) -> Editor (a,b,c)
panel4 :: (Editor a) (Editor b) (Editor c) (Editor d) -> Editor (a,b,c,d)
panel5 :: (Editor a) (Editor b) (Editor c) (Editor d) (Editor e) -> Editor (a,b,c,d,e)
panelc :: (Editor Int) [(a -> a, Editor a)] -> Editor (Int, a)
panell :: !(Editor a) -> Editor [a]
panelL :: ![Editor a] -> Editor [a]
panel1 :: !(Editor a) -> Editor a
panel2 :: !(Editor a) !(Editor b) -> Editor (a,b)
panel3 :: !(Editor a) !(Editor b) !(Editor c) -> Editor (a,b,c)
panel4 :: !(Editor a) !(Editor b) !(Editor c) !(Editor d) -> Editor (a,b,c,d)
panel5 :: !(Editor a) !(Editor b) !(Editor c) !(Editor d) !(Editor e) -> Editor (a,b,c,d,e)
panelc :: !(Editor Int) ![(a -> a, Editor a)] -> Editor (Int, a)
//# UITabSet
tabset :: Editor ()
tabsetl :: (Editor a) -> Editor [a]
tabsetL :: [Editor a] -> Editor [a]
tabset1 :: (Editor a) -> Editor a
tabset2 :: (Editor a) (Editor b) -> Editor (a,b)
tabset3 :: (Editor a) (Editor b) (Editor c) -> Editor (a,b,c)
tabset4 :: (Editor a) (Editor b) (Editor c) (Editor d) -> Editor (a,b,c,d)
tabset5 :: (Editor a) (Editor b) (Editor c) (Editor d) (Editor e) -> Editor (a,b,c,d,e)
tabsetc :: (Editor Int) [(a -> a, Editor a)] -> Editor (Int, a)
tabsetl :: !(Editor a) -> Editor [a]
tabsetL :: ![Editor a] -> Editor [a]
tabset1 :: !(Editor a) -> Editor a
tabset2 :: !(Editor a) !(Editor b) -> Editor (a,b)
tabset3 :: !(Editor a) !(Editor b) !(Editor c) -> Editor (a,b,c)
tabset4 :: !(Editor a) !(Editor b) !(Editor c) !(Editor d) -> Editor (a,b,c,d)
tabset5 :: !(Editor a) !(Editor b) !(Editor c) !(Editor d) !(Editor e) -> Editor (a,b,c,d,e)
tabsetc :: !(Editor Int) ![(a -> a, Editor a)] -> Editor (Int, a)
//# UIWindow
window :: Editor ()
windowl :: (Editor a) -> Editor [a]
windowL :: [Editor a] -> Editor [a]
window1 :: (Editor a) -> Editor a
window2 :: (Editor a) (Editor b) -> Editor (a,b)
window3 :: (Editor a) (Editor b) (Editor c) -> Editor (a,b,c)
window4 :: (Editor a) (Editor b) (Editor c) (Editor d) -> Editor (a,b,c,d)
window5 :: (Editor a) (Editor b) (Editor c) (Editor d) (Editor e) -> Editor (a,b,c,d,e)
windowc :: (Editor Int) [(a -> a, Editor a)] -> Editor (Int, a)
windowl :: !(Editor a) -> Editor [a]
windowL :: ![Editor a] -> Editor [a]
window1 :: !(Editor a) -> Editor a
window2 :: !(Editor a) !(Editor b) -> Editor (a,b)
window3 :: !(Editor a) !(Editor b) !(Editor c) -> Editor (a,b,c)
window4 :: !(Editor a) !(Editor b) !(Editor c) !(Editor d) -> Editor (a,b,c,d)
window5 :: !(Editor a) !(Editor b) !(Editor c) !(Editor d) !(Editor e) -> Editor (a,b,c,d,e)
windowc :: !(Editor Int) ![(a -> a, Editor a)] -> Editor (Int, a)
//# UIMenu
menu :: Editor ()
menul :: (Editor a) -> Editor [a]
menuL :: [Editor a] -> Editor [a]
menu1 :: (Editor a) -> Editor a
menu2 :: (Editor a) (Editor b) -> Editor (a,b)
menu3 :: (Editor a) (Editor b) (Editor c) -> Editor (a,b,c)
menu4 :: (Editor a) (Editor b) (Editor c) (Editor d) -> Editor (a,b,c,d)
menu5 :: (Editor a) (Editor b) (Editor c) (Editor d) (Editor e) -> Editor (a,b,c,d,e)
menuc :: (Editor Int) [(a -> a, Editor a)] -> Editor (Int, a)
menul :: !(Editor a) -> Editor [a]
menuL :: ![Editor a] -> Editor [a]
menu1 :: !(Editor a) -> Editor a
menu2 :: !(Editor a) !(Editor b) -> Editor (a,b)
menu3 :: !(Editor a) !(Editor b) !(Editor c) -> Editor (a,b,c)
menu4 :: !(Editor a) !(Editor b) !(Editor c) !(Editor d) -> Editor (a,b,c,d)
menu5 :: !(Editor a) !(Editor b) !(Editor c) !(Editor d) !(Editor e) -> Editor (a,b,c,d,e)
menuc :: !(Editor Int) ![(a -> a, Editor a)] -> Editor (Int, a)
//# UIToolBar
toolbar :: Editor ()
toolbarl :: (Editor a) -> Editor [a]
toolbarL :: [Editor a] -> Editor [a]
toolbar1 :: (Editor a) -> Editor a
toolbar2 :: (Editor a) (Editor b) -> Editor (a,b)
toolbar3 :: (Editor a) (Editor b) (Editor c) -> Editor (a,b,c)
toolbar4 :: (Editor a) (Editor b) (Editor c) (Editor d) -> Editor (a,b,c,d)
toolbar5 :: (Editor a) (Editor b) (Editor c) (Editor d) (Editor e) -> Editor (a,b,c,d,e)
toolbarc :: (Editor Int) [(a -> a, Editor a)] -> Editor (Int, a)
toolbarl :: !(Editor a) -> Editor [a]
toolbarL :: ![Editor a] -> Editor [a]
toolbar1 :: !(Editor a) -> Editor a
toolbar2 :: !(Editor a) !(Editor b) -> Editor (a,b)
toolbar3 :: !(Editor a) !(Editor b) !(Editor c) -> Editor (a,b,c)
toolbar4 :: !(Editor a) !(Editor b) !(Editor c) !(Editor d) -> Editor (a,b,c,d)
toolbar5 :: !(Editor a) !(Editor b) !(Editor c) !(Editor d) !(Editor e) -> Editor (a,b,c,d,e)
toolbarc :: !(Editor Int) ![(a -> a, Editor a)] -> Editor (Int, a)
//# UIButtonBar
buttonbar :: Editor ()
buttonbarl :: (Editor a) -> Editor [a]
buttonbarL :: [Editor a] -> Editor [a]
buttonbar1 :: (Editor a) -> Editor a
buttonbar2 :: (Editor a) (Editor b) -> Editor (a,b)
buttonbar3 :: (Editor a) (Editor b) (Editor c) -> Editor (a,b,c)
buttonbar4 :: (Editor a) (Editor b) (Editor c) (Editor d) -> Editor (a,b,c,d)
buttonbar5 :: (Editor a) (Editor b) (Editor c) (Editor d) (Editor e) -> Editor (a,b,c,d,e)
buttonbarc :: (Editor Int) [(a -> a, Editor a)] -> Editor (Int, a)
buttonbarl :: !(Editor a) -> Editor [a]
buttonbarL :: ![Editor a] -> Editor [a]
buttonbar1 :: !(Editor a) -> Editor a
buttonbar2 :: !(Editor a) !(Editor b) -> Editor (a,b)
buttonbar3 :: !(Editor a) !(Editor b) !(Editor c) -> Editor (a,b,c)
buttonbar4 :: !(Editor a) !(Editor b) !(Editor c) !(Editor d) -> Editor (a,b,c,d)
buttonbar5 :: !(Editor a) !(Editor b) !(Editor c) !(Editor d) !(Editor e) -> Editor (a,b,c,d,e)
buttonbarc :: !(Editor Int) ![(a -> a, Editor a)] -> Editor (Int, a)
//# UIList
list :: Editor ()
listl :: (Editor a) -> Editor [a]
listL :: [Editor a] -> Editor [a]
list1 :: (Editor a) -> Editor a
list2 :: (Editor a) (Editor b) -> Editor (a,b)
list3 :: (Editor a) (Editor b) (Editor c) -> Editor (a,b,c)
list4 :: (Editor a) (Editor b) (Editor c) (Editor d) -> Editor (a,b,c,d)
list5 :: (Editor a) (Editor b) (Editor c) (Editor d) (Editor e) -> Editor (a,b,c,d,e)
listc :: (Editor Int) [(a -> a, Editor a)] -> Editor (Int, a)
listl :: !(Editor a) -> Editor [a]
listL :: ![Editor a] -> Editor [a]
list1 :: !(Editor a) -> Editor a
list2 :: !(Editor a) !(Editor b) -> Editor (a,b)
list3 :: !(Editor a) !(Editor b) !(Editor c) -> Editor (a,b,c)
list4 :: !(Editor a) !(Editor b) !(Editor c) !(Editor d) -> Editor (a,b,c,d)
list5 :: !(Editor a) !(Editor b) !(Editor c) !(Editor d) !(Editor e) -> Editor (a,b,c,d,e)
listc :: !(Editor Int) ![(a -> a, Editor a)] -> Editor (Int, a)
//# UIListItem
listitem :: Editor ()
listiteml :: (Editor a) -> Editor [a]
listitemL :: [Editor a] -> Editor [a]
listitem1 :: (Editor a) -> Editor a
listitem2 :: (Editor a) (Editor b) -> Editor (a,b)
listitem3 :: (Editor a) (Editor b) (Editor c) -> Editor (a,b,c)
listitem4 :: (Editor a) (Editor b) (Editor c) (Editor d) -> Editor (a,b,c,d)
listitem5 :: (Editor a) (Editor b) (Editor c) (Editor d) (Editor e) -> Editor (a,b,c,d,e)
listitemc :: (Editor Int) [(a -> a, Editor a)] -> Editor (Int, a)
listiteml :: !(Editor a) -> Editor [a]
listitemL :: ![Editor a] -> Editor [a]
listitem1 :: !(Editor a) -> Editor a
listitem2 :: !(Editor a) !(Editor b) -> Editor (a,b)
listitem3 :: !(Editor a) !(Editor b) !(Editor c) -> Editor (a,b,c)
listitem4 :: !(Editor a) !(Editor b) !(Editor c) !(Editor d) -> Editor (a,b,c,d)
listitem5 :: !(Editor a) !(Editor b) !(Editor c) !(Editor d) !(Editor e) -> Editor (a,b,c,d,e)
listitemc :: !(Editor Int) ![(a -> a, Editor a)] -> Editor (Int, a)
//# UIDebug
debug :: Editor ()
debugl :: (Editor a) -> Editor [a]
debugL :: [Editor a] -> Editor [a]
debug1 :: (Editor a) -> Editor a
debug2 :: (Editor a) (Editor b) -> Editor (a,b)
debug3 :: (Editor a) (Editor b) (Editor c) -> Editor (a,b,c)
debug4 :: (Editor a) (Editor b) (Editor c) (Editor d) -> Editor (a,b,c,d)
debug5 :: (Editor a) (Editor b) (Editor c) (Editor d) (Editor e) -> Editor (a,b,c,d,e)
debugc :: (Editor Int) [(a -> a, Editor a)] -> Editor (Int, a)
debugl :: !(Editor a) -> Editor [a]
debugL :: ![Editor a] -> Editor [a]
debug1 :: !(Editor a) -> Editor a
debug2 :: !(Editor a) !(Editor b) -> Editor (a,b)
debug3 :: !(Editor a) !(Editor b) !(Editor c) -> Editor (a,b,c)
debug4 :: !(Editor a) !(Editor b) !(Editor c) !(Editor d) -> Editor (a,b,c,d)
debug5 :: !(Editor a) !(Editor b) !(Editor c) !(Editor d) !(Editor e) -> Editor (a,b,c,d,e)
debugc :: !(Editor Int) ![(a -> a, Editor a)] -> Editor (Int, a)
This diff is collapsed.
......@@ -10,7 +10,7 @@ from System.Time import :: Timestamp
from iTasks.Internal.Generic.Visualization import generic gText, :: TextFormat
/**
* Main eneric editor function
* Main generic editor function
*/
generic gEditor a | gText a, gDefault a, JSONEncode a, JSONDecode a :: Editor a
......
......@@ -18,7 +18,8 @@ derive bimap Editor,(,),(,,),(,,,), MaybeError
gEditor{|UNIT|} = emptyEditor
gEditor{|RECORD of {grd_arity}|} ex _ _ _ _ = {Editor|genUI=genUI,onEdit=onEdit,onRefresh=onRefresh}
gEditor{|RECORD of {grd_arity}|} {genUI=exGenUI,onEdit=exOnEdit,onRefresh=exOnRefresh} _ _ _ _
= {Editor|genUI=genUI,onEdit=onEdit,onRefresh=onRefresh}
where
genUI dp (RECORD x) vst=:{VSt|taskId,mode,optional}
= case mode of
......@@ -27,11 +28,11 @@ where
# (enableUI,enableMask) = genEnableUI taskId dp False
= (Ok (uic UIRecord [enableUI], CompoundMask [enableMask]), vst)
| otherwise
= case ex.Editor.genUI (pairPath grd_arity dp) x {VSt|vst & optional = False} of
(Ok viz,vst) = (Ok (fromPairUI UIRecord grd_arity viz),vst)
= case exGenUI (pairPath grd_arity dp) x {VSt|vst & optional = False} of
(Ok viz, vst) = (Ok (fromPairUI UIRecord grd_arity viz),vst)
(Error e,vst) = (Error e,vst)
Update
= case ex.Editor.genUI (pairPath grd_arity dp) x {VSt|vst & optional = False} of
= case exGenUI (pairPath grd_arity dp) x {VSt|vst & optional = False} of
(Ok viz,vst)
# (UI type attr items, CompoundMask masks) = fromPairUI UIRecord grd_arity viz
//When optional we add a checkbox to clear the record
......@@ -42,7 +43,7 @@ where
= (Ok (UI type attr items,CompoundMask masks),vst)
(Error e,vst) = (Error e,vst)
View
= case ex.Editor.genUI (pairPath grd_arity dp) x {VSt|vst & optional = False} of
= case exGenUI (pairPath grd_arity dp) x {VSt|vst & optional = False} of
(Ok viz,vst) = (Ok (fromPairUI UIRecord grd_arity viz),vst)
(Error e,vst) = (Error e,vst)
......@@ -52,7 +53,7 @@ where
| not optional
= (Error "Enabling non-optional record",RECORD val,vst)
//Create and add the fields
= case ex.Editor.genUI (pairPath grd_arity dp) val {vst & mode = Enter, optional = False} of
= case exGenUI (pairPath grd_arity dp) val {vst & mode = Enter, optional = False} of
(Ok viz,vst)
# (UI type attr items, CompoundMask masks) = fromPairUI UIRecord grd_arity viz
# change = ChangeUI [] [(i,InsertChild ui) \\ ui <- items & i <- [1..]]
......@@ -76,7 +77,7 @@ where
//When optional we need to adjust for the added checkbox, so we need to offset the record field index with one
//In the generated UI and mask (but not in the paths when targeting the edit!!).
# idx = if optional (d + 1) d
= case ex.Editor.onEdit (pairPath grd_arity dp) (pairSelectPath d grd_arity ++ ds,e) val (masks !! idx) {VSt|vst & optional = False} of
= case exOnEdit (pairPath grd_arity dp) (pairSelectPath d grd_arity ++ ds,e) val (masks !! idx) {VSt|vst & optional = False} of
(Ok (change,mask),val,vst)
//Extend the change
# change = case change of NoChange = NoChange; _ = ChangeUI [] [(idx,ChangeChild change)]
......@@ -91,7 +92,7 @@ where
| optional && not (mode =: View)
//Account for the extra mask of the enable/disable checkbox
# enableMask = hd fields
= case ex.Editor.onRefresh (pairPath grd_arity dp) new old (toPairMask (CompoundMask (tl fields))) {VSt|vst & optional = False} of
= case exOnRefresh (pairPath grd_arity dp) new old (toPairMask (CompoundMask (tl fields))) {VSt|vst & optional = False} of
(Ok (change,mask),val,vst)
# change = fromPairChange 0 grd_arity change
# (CompoundMask fields) = fromPairMask grd_arity mask
......@@ -106,7 +107,7 @@ where
(Error e,val,vst)
= (Error e, RECORD val, vst)
| otherwise
= case ex.Editor.onRefresh (pairPath grd_arity dp) new old (toPairMask mask) {VSt|vst & optional = False} of
= case exOnRefresh (pairPath grd_arity dp) new old (toPairMask mask) {VSt|vst & optional = False} of
(Ok (change,mask),val,vst)
= (Ok (fromPairChange 0 grd_arity change, fromPairMask grd_arity mask), RECORD val, vst)
(Error e,val,vst)
......@@ -114,18 +115,19 @@ where
onRefresh dp (RECORD new) (RECORD old) mask vst=:{VSt|taskId,optional,mode}
= (Error "Corrupt mask in generic RECORD editor",RECORD old, vst)
gEditor{|FIELD of {gfd_name}|} ex _ _ _ _ = {Editor|genUI=genUI,onEdit=onEdit,onRefresh=onRefresh}
gEditor{|FIELD of {gfd_name}|} {genUI=exGenUI,onEdit=exOnEdit,onRefresh=exOnRefresh} _ _ _ _
= {Editor|genUI=genUI,onEdit=onEdit,onRefresh=onRefresh}
where
genUI dp (FIELD x) vst = case ex.Editor.genUI dp x vst of //Just add the field name as a label
genUI dp (FIELD x) vst = case exGenUI dp x vst of //Just add the field name as a label
(Ok (UI type attr items, mask),vst) = (Ok (UI type ('DM'.union attr (labelAttr gfd_name)) items, mask),vst)
(Error e,vst) = (Error e,vst)
onEdit dp (tp,e) (FIELD field) mask vst
# (mbmask,field,vst) = ex.Editor.onEdit dp (tp,e) field mask vst
# (mbmask,field,vst) = exOnEdit dp (tp,e) field mask vst
= (mbmask,FIELD field,vst)
onRefresh dp (FIELD new) (FIELD old) mask vst
# (change,val,vst) = ex.Editor.onRefresh dp new old mask vst
# (change,val,vst) = exOnRefresh dp new old mask vst
= (change,FIELD val,vst)
/*
......@@ -133,14 +135,15 @@ where
* - There is only one constructor
* - There are multiple constructors
*/
gEditor{|OBJECT of {gtd_num_conses,gtd_conses}|} ex _ _ _ _ = withEditModeAttr {Editor|genUI=genUI,onEdit=onEdit,onRefresh=onRefresh}
gEditor{|OBJECT of {gtd_num_conses,gtd_conses}|} {genUI=exGenUI,onEdit=exOnEdit,onRefresh=exOnRefresh} _ _ _ _
= withEditModeAttr {Editor|genUI=genUI,onEdit=onEdit,onRefresh=onRefresh}
where
genUI dp (OBJECT x) vst=:{VSt|taskId,mode,optional,selectedConsIndex}
= case mode of
Enter
//If there is only one constructor, we generate the UI for that constructor
| gtd_num_conses == 1
= case ex.Editor.genUI dp x vst of
= case exGenUI dp x vst of
(Ok (consUI,consMask), vst) //The CONS will already create a ui of type UICons
= (Ok (consUI,consMask), {vst & selectedConsIndex = selectedConsIndex})
(Error e, vst)
......@@ -151,7 +154,7 @@ where
= (Ok (UI UIVarCons 'DM'.newMap [consChooseUI],CompoundMask [consChooseMask]),{vst & selectedConsIndex = selectedConsIndex})
Update
//Generate the ui for the current value
= case ex.Editor.genUI dp x vst of
= case exGenUI dp x vst of
(Ok (consUI=:(UI UICons attr items), consMask=:(CompoundMask fields)),vst)
//If there is only constructor, we are done
| gtd_num_conses == 1
......@@ -164,7 +167,7 @@ where
(Error e,vst) = (Error e,vst)
View
//If there is only one constructor we don't need to show the constructor name
= case ex.Editor.genUI dp x vst of
= case exGenUI dp x vst of
(Ok (consUI=:(UI UICons attr items), consMask=:(CompoundMask fields)),vst)
| gtd_num_conses == 1
= (Ok (consUI, consMask),{vst & selectedConsIndex = selectedConsIndex})
......@@ -190,9 +193,9 @@ where
//Create a default value for the selected constructor
//This is a rather ugly trick: We create a special target path that consists only of negative values that is
//decoded by the the onEdit instance of EITHER to create a value that consists of the correct nesting of LEFT's and RIGHT's
# (_,val,vst) = ex.Editor.onEdit dp (consCreatePath consIdx gtd_num_conses,JSONNull) val newCompoundMask vst
# (_,val,vst) = exOnEdit dp (consCreatePath consIdx gtd_num_conses,JSONNull) val newCompoundMask vst
//Create a UI for the new constructor
= case ex.Editor.genUI dp val {vst & mode = Enter} of
= case exGenUI dp val {vst & mode = Enter} of
(Ok (UI UICons attr items, CompoundMask masks),vst)
//Construct a UI change that does the following:
//1: If necessary remove the fields of the previously selected constructor
......@@ -223,13 +226,13 @@ where
onEdit dp (tp,e) (OBJECT val) mask=:(CompoundMask fields) vst
| gtd_num_conses == 1
//Just call onEdit for the inner value
= case ex.Editor.onEdit dp (tp,e) val mask vst of
= case exOnEdit dp (tp,e) val mask vst of
(Ok (change,mask),val,vst) = (Ok (change,mask),OBJECT val,vst)
(Error e,val,vst) = (Error e, OBJECT val, vst)
| otherwise
//Adjust for the added constructor switch UI
# consChooseMask = hd fields
= case ex.Editor.onEdit dp (tp,e) val (CompoundMask (tl fields)) vst of
= case exOnEdit dp (tp,e) val (CompoundMask (tl fields)) vst of
(Ok (change,CompoundMask fields),val,vst)
# change = case change of
(ChangeUI attrChanges itemChanges) = ChangeUI attrChanges [(i + 1,c) \\ (i,c) <- itemChanges]
......@@ -239,7 +242,7 @@ where
onRefresh dp (OBJECT new) (OBJECT old) mask=:(CompoundMask fields) vst=:{VSt|mode,taskId,optional,selectedConsIndex=curSelectedConsIndex}
| gtd_num_conses == 1
# (change,val,vst) = ex.Editor.onRefresh dp new old mask vst
# (change,val,vst) = exOnRefresh dp new old mask vst
= (change,OBJECT val,vst)
| otherwise
//Adjust for the added constructor view/choose UI
......@@ -247,7 +250,7 @@ where
//Don't recursively refresh if no constructor has been chosen
| (not mode =: View) && consChooseMask =: (FieldMask {FieldMask|state=JSONNull})
= (Ok (NoChange,mask),OBJECT old,vst)
= case ex.Editor.onRefresh dp new old (CompoundMask (tl fields)) {vst & selectedConsIndex = 0} of
= case exOnRefresh dp new old (CompoundMask (tl fields)) {vst & selectedConsIndex = 0} of
(Ok (change,CompoundMask fields),val,vst=:{VSt|selectedConsIndex})
//If the cons was changed we need to update the selector
# consIndex = ~selectedConsIndex - 1
......@@ -273,51 +276,54 @@ where
onRefresh dp (OBJECT new) (OBJECT old) mask vst
= (Error "Corrupt mask in generic OBJECT editor",OBJECT old, vst)
gEditor{|EITHER|} ex _ dx _ _ ey _ dy _ _ = {Editor|genUI=genUI,onEdit=onEdit,onRefresh=onRefresh}
gEditor{|EITHER|} {genUI=exGenUI,onEdit=exOnEdit,onRefresh=exOnRefresh} _ dx _ _
{genUI=eyGenUI,onEdit=eyOnEdit,onRefresh=eyOnRefresh} _ dy _ _
= {Editor|genUI=genUI,onEdit=onEdit,onRefresh=onRefresh}
where
genUI dp (LEFT x) vst = ex.Editor.genUI dp x vst
genUI dp (RIGHT y) vst = ey.Editor.genUI dp y vst
genUI dp (LEFT x) vst = exGenUI dp x vst
genUI dp (RIGHT y) vst = eyGenUI dp y vst
//Special case to create a LEFT, after a constructor switch
onEdit dp ([-1],e) _ mask vst = (Ok (NoChange,mask),LEFT dx,vst)
onEdit dp ([-1:ds],e) _ mask vst
# (mask,x,vst) = ex.Editor.onEdit dp (ds,e) dx mask vst
# (mask,x,vst) = exOnEdit dp (ds,e) dx mask vst
= (mask,LEFT x,vst)
//Special cases to create a RIGHT, after a constructor switch
onEdit dp ([-2],e) _ mask vst = (Ok (NoChange,mask),RIGHT dy,vst)
onEdit dp ([-2:ds],e) _ mask vst
# (mask,y,vst) = ey.Editor.onEdit dp (ds,e) dy mask vst
# (mask,y,vst) = eyOnEdit dp (ds,e) dy mask vst
= (mask,RIGHT y,vst)
//Just pass the edit event through
onEdit dp (tp,e) (LEFT x) mask vst
# (mask,x,vst) = ex.Editor.onEdit dp (tp,e) x mask vst
# (mask,x,vst) = exOnEdit dp (tp,e) x mask vst
= (mask,LEFT x,vst)
onEdit dp (tp,e) (RIGHT y) mask vst
# (mask,y,vst) = ey.Editor.onEdit dp (tp,e) y mask vst
# (mask,y,vst) = eyOnEdit dp (tp,e) y mask vst
= (mask,RIGHT y,vst)
onRefresh dp (LEFT new) (LEFT old) mask vst
# (change,val,vst) = ex.Editor.onRefresh dp new old mask vst
# (change,val,vst) = exOnRefresh dp new old mask vst
= (change,LEFT val,vst)
onRefresh dp (RIGHT new) (RIGHT old) mask vst
# (change,val,vst) = ey.Editor.onRefresh dp new old mask vst
# (change,val,vst) = eyOnRefresh dp new old mask vst
= (change,RIGHT val,vst)
//A different constructor is selected -> generate a new UI
//We use a negative selConsIndex to encode that the constructor was changed
onRefresh dp (RIGHT new) (LEFT old) mask vst
= case ey.Editor.genUI dp new vst of
= case eyGenUI dp new vst of
(Ok (ui,mask),vst=:{selectedConsIndex}) = (Ok (ReplaceUI ui,mask),RIGHT new,{vst & selectedConsIndex = -1 - selectedConsIndex})
(Error e,vst=:{selectedConsIndex}) = (Error e,LEFT old,{vst & selectedConsIndex = -1 - selectedConsIndex})
onRefresh dp (LEFT new) (RIGHT old) mask vst
= case ex.Editor.genUI dp new vst of
= case exGenUI dp new vst of
(Ok (ui,mask),vst=:{selectedConsIndex}) = (Ok (ReplaceUI ui,mask),LEFT new,{vst & selectedConsIndex = -1 - selectedConsIndex})
(Error e,vst=:{selectedConsIndex}) = (Error e,RIGHT old,{vst & selectedConsIndex = -1 - selectedConsIndex})
gEditor{|CONS of {gcd_index,gcd_arity}|} ex _ _ _ _ = {Editor|genUI=genUI,onEdit=onEdit,onRefresh=onRefresh}
gEditor{|CONS of {gcd_index,gcd_arity}|} {genUI=exGenUI,onEdit=exOnEdit,onRefresh=exOnRefresh} _ _ _ _
= {Editor|genUI=genUI,onEdit=onEdit,onRefresh=onRefresh}
where
genUI dp (CONS x) vst = case ex.Editor.genUI (pairPath gcd_arity dp) x vst of
genUI dp (CONS x) vst = case exGenUI (pairPath gcd_arity dp) x vst of
(Ok viz,vst) = (Ok (fromPairUI UICons gcd_arity viz), {VSt| vst & selectedConsIndex = gcd_index})
(Error e,vst) = (Error e,{VSt| vst & selectedConsIndex = gcd_index})
......@@ -325,7 +331,7 @@ where
| d >= gcd_arity
= (Error "Edit aimed at non-existent constructor field",CONS val,vst)
//Update the targeted field in the constructor
= case ex.Editor.onEdit (pairPath gcd_arity dp) (pairSelectPath d gcd_arity ++ ds,e) val (masks !! d) vst of
= case exOnEdit (pairPath gcd_arity dp) (pairSelectPath d gcd_arity ++ ds,e) val (masks !! d) vst of
(Ok (change,mask),val,vst)
//Extend the change
# change = case change of NoChange = NoChange; _ = ChangeUI [] [(d,ChangeChild change)]
......@@ -336,58 +342,60 @@ where
onRefresh dp (CONS new) (CONS old) mask vst
//Refresh
= case ex.Editor.onRefresh (pairPath gcd_arity dp) new old (toPairMask mask) vst of
= case exOnRefresh (pairPath gcd_arity dp) new old (toPairMask mask) vst of
(Ok (change,mask),val,vst)
= (Ok (fromPairChange 0 gcd_arity change, fromPairMask gcd_arity mask), CONS val, vst)
(Error e,val,vst)
= (Error e, CONS val, vst)
gEditor{|PAIR|} ex _ _ _ _ ey _ _ _ _ = {Editor|genUI=genUI,onRefresh=onRefresh,onEdit=onEdit}
gEditor{|PAIR|} {genUI=exGenUI,onEdit=exOnEdit,onRefresh=exOnRefresh} _ _ _ _
{genUI=eyGenUI,onEdit=eyOnEdit,onRefresh=eyOnRefresh} _ _ _ _
= {Editor|genUI=genUI,onRefresh=onRefresh,onEdit=onEdit}
where
genUI dp (PAIR x y) vst
# (dpx,dpy) = pairPathSplit dp
# (vizx, vst) = ex.Editor.genUI dpx x vst
# (vizx, vst) = exGenUI dpx x vst
| vizx =: (Error _) = (vizx,vst)
# (vizy, vst) = ey.Editor.genUI dpy y vst
# (vizy, vst) = eyGenUI dpy y vst
| vizy =: (Error _) = (vizy,vst)
# ((vizx,maskx),(vizy,masky)) = (fromOk vizx,fromOk vizy)
=