Commit c1ac965f authored by Bas Lijnse's avatar Bas Lijnse

Fixed another missed unwrapping case in extractDownstreamChange.

parent 4242d0de
......@@ -714,7 +714,7 @@ externalProcessExample =
enterInformation "Enter the path to the external process. To for instance open a shell run '/bin/bash' or 'c:\\Windows\\System32\\cmd.exe'." [] >>= \path ->
withShared
Nothing
( \sds -> ( externalProcess () path [] Nothing sds handlers Nothing gEditor{|*|} <<@ ApplyLayout (removeSubUIs (SelectByPath [])) >&>
( \sds -> ( externalProcess () path [] Nothing sds handlers Nothing gEditor{|*|} <<@ ApplyLayout hideUI >&>
viewSharedInformation "Process output" []
) -&&-
forever (enterInformation "Enter data to send to StdIn" [] >>= \data -> set (Just (data +++ "\n")) sds)
......
......@@ -150,7 +150,7 @@ manageWorkInSession
where
layout = sequenceLayouts
[unwrapUI //Get rid of the step
,arrangeWithSideBar 0 TopSide 50 True
,arrangeWithSideBar 0 TopSide 50 False
,layoutSubUIs (SelectByPath [0]) layoutManageSession
,layoutSubUIs (SelectByPath [1]) (sequenceLayouts [unwrapUI,layoutWhatToDo])
//Use maximal screen space
......
......@@ -195,6 +195,7 @@ extractUIWithEffects :: (LUI,LUIMoves) -> (!Maybe UI,!(LUI,LUIMoves))
//Helper functions (exported for unit testing)
scanToPosition_ :: LUINo Int [LUI] LUIMoves -> (Int,Bool,Maybe LUI)
nodeExists_ :: !LUINo !LUI LUIMoves -> Bool
selectChildNodes_ :: LUINo ([LUI],LUIMoves) -> [LUI]
updateChildNodes_ :: LUINo (Int (LUI,LUIMoves) -> (LUI,LUIMoves)) ([LUI],LUIMoves) -> ([LUI],LUIMoves)
selectSubNode_ :: LUINo UIPath (LUI,LUIMoves) -> Maybe LUI
......
......@@ -345,11 +345,9 @@ where
moveSubUIs :: UISelection UIPath Int -> LayoutRule
moveSubUIs selection path pos = rule
where
rule ruleId (lui=:(LUINode type attr items changes=:{toBeReplaced=Just replacement} effects), moves)
# (replacement,moves) = rule ruleId (replacement, moves)
= (LUINode type attr items {changes & toBeReplaced=Just replacement} effects, moves)
rule ruleNo (lui,moves) = updateNode_ ruleNo (rule` ruleNo) (lui,moves)
rule ruleNo (lui,moves)
rule` ruleNo (lui,moves)
# (moved,lui,moves) = checkNodes selection (destinationExists path pos (lui,moves)) lui moves
# (lui,moves) = updateDestination moved (lui,moves)
= (lui,moves)
......@@ -495,15 +493,27 @@ nodeExists_ ruleNo (LUINode _ _ _ _ {hidden=ESToBeUpdated _ hiddenBy}) moves = h
nodeExists_ ruleNo (LUINode _ _ _ _ {additional=ESToBeApplied addedBy}) moves = addedBy <= ruleNo
nodeExists_ ruleNo (LUINode _ _ _ _ {additional=ESApplied addedBy}) moves = addedBy <= ruleNo
nodeExists_ ruleNo (LUINode _ _ _ _ {additional=ESToBeRemoved _}) moves = False //Marked to be removed
nodeExists_ ruleNo (LUINode _ _ items _ {wrapper=ESToBeApplied wrappedBy}) moves
= wrappedNodeExists_ ruleNo items wrappedBy moves
nodeExists_ ruleNo (LUINode _ _ items _ {wrapper=ESApplied wrappedBy}) moves
= wrappedNodeExists_ ruleNo items wrappedBy moves
nodeExists_ ruleNo (LUINode _ _ items _ {wrapper=ESToBeApplied wrappedBy}) moves | wrappedBy > ruleNo
= case scanToPosition_ wrappedBy 0 items moves of
(_,_,Just wrapped) = nodeExists_ ruleNo wrapped moves //Check the wrapped child
_ = False // The wrapped child does not exist, nothing to check
nodeExists_ ruleNo (LUINode _ _ items _ {wrapper=ESApplied wrappedBy}) moves | wrappedBy > ruleNo
= case scanToPosition_ wrappedBy 0 items moves of
(_,_,Just wrapped) = nodeExists_ ruleNo wrapped moves //Check the wrapped child
_ = False // The wrapped child does not exist, nothing to check
nodeExists_ ruleNo (LUINode _ _ items _ {wrapper=ESToBeRemoved wrappedBy}) moves //No longer wrapped
= case scanToPosition_ wrappedBy 0 items moves of //Consider the wrapped child (that will be restored)
(_,_,Just wrapped) = nodeExists_ ruleNo wrapped moves //Check the wrapped child
_ = False // The wrapped child does not exist, nothing to check
//TODO: Handle unwrapped case
nodeExists_ ruleNo (LUINode _ _ items _ {unwrapped=ESToBeApplied unwrappedBy}) moves | unwrappedBy <= ruleNo
= case scanToPosition_ unwrappedBy 0 items moves of
(_,_,Just unwrapped) = nodeExists_ ruleNo unwrapped moves
_ = False
nodeExists_ ruleNo (LUINode _ _ items _ {unwrapped=ESApplied unwrappedBy}) moves | unwrappedBy <= ruleNo
= case scanToPosition_ unwrappedBy 0 items moves of
(_,_,Just unwrapped) = nodeExists_ ruleNo unwrapped moves
_ = False
//Moved nodes
nodeExists_ ruleNo (LUIMoveSource moveId) moves
= case getMovedNode_ moveId moves of
......@@ -515,6 +525,7 @@ nodeExists_ ruleNo (LUIMoveSource moveId) moves
| otherwise = movedBy >= ruleNo
(LUINode _ _ _ _ {moved=ESToBeRemoved _}) = True
(LUINode _ _ _ _ {moved=ESNotApplied}) = True
//TODO: HANDLE ALL CASES
nodeExists_ ruleNo (LUIMoveDestination moveId moveRule) moves
= case getMovedNode_ moveId moves of
(LUINode _ _ _ {toBeRemoved=True} _) = False
......@@ -525,14 +536,9 @@ nodeExists_ ruleNo (LUIMoveDestination moveId moveRule) moves
| otherwise = movedBy < ruleNo
(LUINode _ _ _ _ {moved=ESToBeRemoved _}) = False
(LUINode _ _ _ _ {moved=ESNotApplied}) = False
//TODO: HANDLE ALL CASES
nodeExists_ _ _ _ = True
wrappedNodeExists_ ruleNo items wrappedBy moves
| wrappedBy <= ruleNo = True //Already wrapped, (the wrapper counts as an existing child)
| otherwise = case scanToPosition_ wrappedBy 0 items moves of //Not yet wrapped, consider the wrapped child
(_,_,Just wrapped) = nodeExists_ ruleNo wrapped moves //Check the wrapped child
_ = False // The wrapped child does not exist, nothing to check
//Test if a node matches a selection UI at a path is in the selection
nodeSelected_ :: LUINo UISelection UIPath LUI LUIMoves -> Bool
nodeSelected_ ruleNo (SelectByPath p) path _ moves = p === path
......@@ -592,16 +598,11 @@ where
| r == 0 = (i,True,Just x)
| otherwise = scan (r - 1) (i + 1) xs
isAddedBy_ :: LUINo LUI -> Bool
isAddedBy_ lid (LUINode _ _ _ _ {additional=ESToBeApplied ruleId}) = lid == ruleId
isAddedBy_ lid (LUINode _ _ _ _ {additional=ESApplied ruleId}) = lid == ruleId
isAddedBy_ lid (LUINode _ _ _ _ {additional=ESToBeRemoved ruleId}) = lid == ruleId
isAddedBy_ _ _ = False
isAdditional_ :: LUI -> Bool
isAdditional_ (LUINode _ _ _ _ {additional=ESToBeApplied _}) = True
isAdditional_ (LUINode _ _ _ _ {additional=ESApplied _}) = True
isAdditional_ (LUINode _ _ _ _ {additional=ESToBeRemoved _}) = True
isAdditional_ (LUIMoveDestination _ _) = True //TODO: Create a test for this case
isAdditional_ _ = False
isShifted_ :: LUI -> Bool
......@@ -751,7 +752,7 @@ processNode_ ruleNo fun (lui,moves) = case lui of
_
= (Nothing,lui,moves)
//TODO: Refactor to reduce overlap in cases
(LUINode type attr items changes effects=:{unwrapped=ESToBeApplied unwrappedBy}) | unwrappedBy < ruleNo
(LUINode type attr items changes effects=:{unwrapped=ESApplied unwrappedBy}) | unwrappedBy < ruleNo
//Already wrapped, process the inner node
= case scanToPosition_ ruleNo 0 items moves of
(index,True,Just item)
......@@ -933,10 +934,10 @@ extractDownstreamChange (lui,moves) = case extractDownstreamChildChange lui move
_ = (NoChange,(lui,moves)) //TODO: This case should not really happen
//For each node we need to extract one of the following changes:
// 1. Just (InsertChild x) - The node did not exist previously, but does now
// 1. Just (InsertChild x) - The node did not exist client-side, but does now
// 2. Just (RemoveChild) - The node existed previously but should not
// 3. Just (ChangeChild x) - The node existed previously and still does
// 4. Nothing - The node does not exist client side and still does not...
// 4. Nothing - The node did not exist client-side and still does not...
extractDownstreamChildChange :: LUI LUIMoves -> (!Maybe UIChildChange,!Maybe LUI,!LUIMoves)
extractDownstreamChildChange lui moves
# (mbMoveId,mbDestinationRule,current=:LUINode _ _ items changes effects=:{moved}) = case lui of
......@@ -1002,12 +1003,16 @@ where
differentFirstChild [LUIShiftDestination _:_]= True
differentFirstChild items = False
//TODO: make 'moves' an explicit argument
existsDownstream_ _ (LUINode _ _ _ _ {LUIEffects|hidden=ESApplied _}) = False
existsDownstream_ _ (LUINode _ _ _ _ {LUIEffects|hidden=ESToBeRemoved _}) = False
existsDownstream_ (LUIMoveSource _) (LUINode _ _ _ _ {LUIEffects|moved=ESApplied _}) = False
existsDownstream_ (LUIMoveSource _) (LUINode _ _ _ _ {LUIEffects|moved=ESToBeUpdated _ _}) = False
existsDownstream_ (LUIMoveSource _) (LUINode _ _ _ _ {LUIEffects|moved=ESPartiallyUpdated _ _}) = False
existsDownstream_ ref (LUINode _ _ [i:_] _ {LUIEffects|unwrapped=ESApplied _}) = existsDownstream_ ref i
existsDownstream_ ref (LUINode _ _ items _ {LUIEffects|unwrapped=ESApplied unwrappedBy})
= case scanToPosition_ unwrappedBy 0 items moves of
(_,_,Just item) = existsDownstream_ ref item
_ = False
existsDownstream_ _ _ = True
determineInsert_ node current moves = case extractUIWithEffects (current,moves) of
......
......@@ -25,7 +25,7 @@ arrangeWithTabs closeable = layoutSubUIs
:if closeable [moveCloseToTab] []
])
where
moveCloseToTab = layoutSubUIs //Only on children directly containing a clos action
moveCloseToTab = layoutSubUIs //Only on children directly containing a close action
(SelectAND
SelectChildren
(SelectByContains
......@@ -53,12 +53,10 @@ where
arrangeWithSideBar :: !Int !UISide !Int !Bool -> LayoutRule
arrangeWithSideBar index side size resize = sequenceLayouts
[wrapUI UIPanel //Push the current container down a level
[wrapUI UIPanel //Push the current container down a level
,copySubUIAttributes SelectAll [0] [] //Keep the attributes from the original UI
,setUIAttributes (directionAttr direction)
,insertChildUI sidePanelIndex (ui UIComponent) //Make sure we have a target for the move
,moveSubUIs (SelectByPath [mainPanelIndex,index]) [sidePanelIndex] 0
,layoutSubUIs (SelectByPath [sidePanelIndex]) unwrapUI //Remove the temporary wrapping panel
,moveSubUIs (SelectByPath [0,index]) [] sidePanelIndex
,layoutSubUIs (SelectByPath [sidePanelIndex]) (sequenceLayouts
[setUIAttributes (sizeAttr sidePanelWidth sidePanelHeight)
:if resize
......@@ -69,7 +67,6 @@ arrangeWithSideBar index side size resize = sequenceLayouts
]
where
sidePanelIndex = if (side === TopSide || side === LeftSide) 0 1
mainPanelIndex = if (sidePanelIndex === 0) 1 0
direction = if (side === TopSide|| side === BottomSide) Vertical Horizontal
padders TopSide = bottomPaddingAttr 5
......
......@@ -28,8 +28,7 @@ where
instance tune ApplyLayout Task
where
tune (ApplyLayout l) task = task
//tune (ApplyLayout l) task = applyLayout l task
tune (ApplyLayout l) task = applyLayout l task
applyLayout :: LayoutRule (Task a) -> Task a
applyLayout rule task=:(Task evala) = Task eval
......
......@@ -79,6 +79,21 @@ applyUpstreamChangeTests =
] noChanges noEffects
,initLUIMoves)
(applyUpstreamChange (ChangeUI [] [(1,ChangeChild (ReplaceUI (UI UIEmpty 'DM'.newMap [])))]) (lui1,initLUIMoves))
,assertEqual "Moved child replace"
(LUINode UIPanel ('DM'.fromList [("title",JSONString "Parent panel")])
[LUIMoveDestination 2 (LUINo [0])
,LUINode UIInteract 'DM'.newMap [] noChanges noEffects
,LUIMoveSource 2
] noChanges noEffects
,'DM'.fromList [(2,LUINode UIStep 'DM'.newMap [] {noChanges & toBeReplaced = Just (LUINode UIEmpty 'DM'.newMap [] noChanges noEffects)} {noEffects & moved = ESApplied (LUINo [0])})])
(applyUpstreamChange (ChangeUI [] [(1,ChangeChild (ReplaceUI (UI UIEmpty 'DM'.newMap [])))])
(LUINode UIPanel ('DM'.fromList [("title",JSONString "Parent panel")])
[LUIMoveDestination 2 (LUINo [0])
,LUINode UIInteract 'DM'.newMap [] noChanges noEffects
,LUIMoveSource 2
] noChanges noEffects
,'DM'.fromList [(2,LUINode UIStep 'DM'.newMap [] noChanges {noEffects & moved = ESApplied (LUINo [0])})]))
,assertEqual "Child remove"
(LUINode UIPanel ('DM'.fromList [("title",JSONString "Parent panel")])
......@@ -294,6 +309,7 @@ extractDownstreamChangeTests =
,extractDownstreamChangeTest_NewUnwrappedChild
,extractDownstreamChangeTest_NoLongerUnwrappedChild
,extractDownstreamChangeTest_ChangingAnUnwrappedAttribute
,extractDownstreamChangeTest_ChangingAnUnwrappedAttributeNotZero
,extractDownstreamChangeTest_ChangingAfterUnwrappedHiddenAttribute
,extractDownstreamChangeTest_InsertIntoUnwrappedContainer
,extractDownstreamChangeTest_RemovingUnwrappedContainer
......@@ -889,6 +905,30 @@ extractDownstreamChangeTest_ChangingAnUnwrappedAttribute =
] noChanges noEffects
,initLUIMoves))
extractDownstreamChangeTest_ChangingAnUnwrappedAttributeNotZero =
assertEqual "Changing an attribute on an unwrapped child that is not the first child"
(ChangeUI [] [(1,ChangeChild (ChangeUI [SetAttribute "title" (JSONString "test")] []))]
,(LUINode UIPanel ('DM'.fromList [("title",JSONString "Parent panel")])
[LUINode UIInteract 'DM'.newMap [] noChanges noEffects
,LUINode UIStep 'DM'.newMap
[LUINode UIInteract 'DM'.newMap [] noChanges {noEffects & hidden = ESApplied (LUINo [0])}
,LUINode UIDebug ('DM'.fromList [("title",JSONString "test")]) [] noChanges noEffects
] noChanges {noEffects & unwrapped = ESApplied (LUINo [1])}
,LUINode UIParallel 'DM'.newMap [] noChanges noEffects
] noChanges noEffects
,initLUIMoves)
)
(extractDownstreamChange (
LUINode UIPanel ('DM'.fromList [("title",JSONString "Parent panel")])
[LUINode UIInteract 'DM'.newMap [] noChanges noEffects
,LUINode UIStep 'DM'.newMap
[LUINode UIInteract 'DM'.newMap [] noChanges {noEffects & hidden = ESApplied (LUINo [0])}
,LUINode UIDebug 'DM'.newMap [] {noChanges & setAttributes = 'DM'.fromList [("title",JSONString "test")]} noEffects
] noChanges {noEffects & unwrapped = ESApplied (LUINo [1])}
,LUINode UIParallel 'DM'.newMap [] noChanges noEffects
] noChanges noEffects
,initLUIMoves))
extractDownstreamChangeTest_ChangingAfterUnwrappedHiddenAttribute =
assertEqual "Changing an attribute after an unwrapped hidden child"
(ChangeUI [] [(1,ChangeChild (ChangeUI [SetAttribute "title" (JSONString "test")] []))]
......@@ -1137,7 +1177,16 @@ scanToPosition_Tests =
initLUIMoves
)
]
nodeExists_Tests =
[assertEqual "Node exists: unwrapped hidden node"
False
(nodeExists_ (LUINo [2])
(LUINode UIStep 'DM'.newMap [
LUINode UIInteract 'DM'.newMap [] noChanges {noEffects & hidden = ESApplied (LUINo [1])}
] noChanges {noEffects & unwrapped = ESApplied (LUINo [0])})
'DM'.newMap
)
]
compareLUINoTests =
[assertEqual "Comparison of ruleNumbers: 1 < 1.2" True (LUINo [1] < LUINo [1,2])
,assertEqual "Comparison of ruleNumbers: 1.2 < 3" True (LUINo [1,2] < LUINo [3])
......@@ -1444,6 +1493,95 @@ layoutSubUIsTests =
,initLUIMoves)
)
]
combinationTests =
//Applying the first change
[assertEqual "Combination rule: wrapping after unwrapping -> first rule"
(LUINode UIStep 'DM'.newMap
[LUINode UIDebug 'DM'.newMap [
LUINode UIInteract 'DM'.newMap [
LUINode UIEmpty 'DM'.newMap [] noChanges noEffects
,LUINode UITextField 'DM'.newMap [] noChanges noEffects
] noChanges noEffects
] noChanges {noEffects & wrapper = ESToBeApplied (LUINo [0,1])}
] noChanges {noEffects & unwrapped = ESToBeApplied (LUINo [0,0])}
,'DM'.newMap)
((sequenceLayouts [unwrapUI,wrapUI UIDebug]) (LUINo [0])
(LUINode UIStep 'DM'.newMap
[LUINode UIInteract 'DM'.newMap [
LUINode UIEmpty 'DM'.newMap [] noChanges noEffects
,LUINode UITextField 'DM'.newMap [] noChanges noEffects
] noChanges noEffects
] noChanges noEffects
,'DM'.newMap)
)
//Extract the initial ui
,assertEqual "Combination rule: wrapping after unwrapping -> initial ui"
(Just (UI UIDebug 'DM'.newMap [UI UIInteract 'DM'.newMap []])
,(LUINode UIStep 'DM'.newMap
[LUINode UIDebug 'DM'.newMap [
LUINode UIInteract 'DM'.newMap [
] noChanges noEffects
] noChanges {noEffects & wrapper = ESApplied (LUINo [0,1])}
] noChanges {noEffects & unwrapped = ESApplied (LUINo [0,0])}
,'DM'.newMap))
(extractUIWithEffects
(LUINode UIStep 'DM'.newMap
[LUINode UIDebug 'DM'.newMap [
LUINode UIInteract 'DM'.newMap [
] noChanges noEffects
] noChanges {noEffects & wrapper = ESToBeApplied (LUINo [0,1])}
] noChanges {noEffects & unwrapped = ESToBeApplied (LUINo [0,0])}
,'DM'.newMap)
)
//Apply a change
,assertEqual "Combination rule: wrapping after unwrapping -> new event"
(LUINode UIStep 'DM'.newMap
[LUINode UIDebug 'DM'.newMap [
LUINode UIInteract 'DM'.newMap [] {noChanges & setAttributes = 'DM'.fromList [("test",JSONString "x")]} noEffects
] noChanges {noEffects & wrapper = ESApplied (LUINo [0,1])}
] noChanges {noEffects & unwrapped = ESApplied (LUINo [0,0])}
,'DM'.newMap)
(applyUpstreamChange (ChangeUI [] [(0,ChangeChild (ChangeUI [SetAttribute "test" (JSONString "x")] []))])
(LUINode UIStep 'DM'.newMap
[LUINode UIDebug 'DM'.newMap [
LUINode UIInteract 'DM'.newMap [] {noChanges & setAttributes = 'DM'.fromList [("test",JSONString "x")]} noEffects
] noChanges {noEffects & wrapper = ESApplied (LUINo [0,1])}
] noChanges {noEffects & unwrapped = ESApplied (LUINo [0,0])}
,'DM'.newMap)
)
//Reapply the rule
,assertEqual "Combination rule: wrapping after unwrapping -> reapply rule"
(LUINode UIStep 'DM'.newMap
[LUINode UIDebug 'DM'.newMap [
LUINode UIInteract 'DM'.newMap [] {noChanges & setAttributes = 'DM'.fromList [("test",JSONString "x")]} noEffects
] noChanges {noEffects & wrapper = ESApplied (LUINo [0,1])}
] noChanges {noEffects & unwrapped = ESApplied (LUINo [0,0])}
,'DM'.newMap)
((sequenceLayouts [unwrapUI,wrapUI UIDebug]) (LUINo [0])
(LUINode UIStep 'DM'.newMap
[LUINode UIDebug 'DM'.newMap [
LUINode UIInteract 'DM'.newMap [] {noChanges & setAttributes = 'DM'.fromList [("test",JSONString "x")]} noEffects
] noChanges {noEffects & wrapper = ESApplied (LUINo [0,1])}
] noChanges {noEffects & unwrapped = ESApplied (LUINo [0,0])}
,'DM'.newMap)
)
//Extract the downstream change
,assertEqual "Combination rule: wrapping after unwrapping -> downstream"
(ChangeUI [] [(0,ChangeChild (ChangeUI [SetAttribute "test" (JSONString "x")] []))]
,(LUINode UIStep 'DM'.newMap
[LUINode UIDebug 'DM'.newMap [
LUINode UIInteract ('DM'.fromList [("test",JSONString "x")]) [] noChanges noEffects
] noChanges {noEffects & wrapper = ESApplied (LUINo [0,1])}
] noChanges {noEffects & unwrapped = ESApplied (LUINo [0,0])}
,'DM'.newMap))
(extractDownstreamChange (LUINode UIStep 'DM'.newMap
[LUINode UIDebug 'DM'.newMap [
LUINode UIInteract 'DM'.newMap [] {noChanges & setAttributes = 'DM'.fromList [("test",JSONString "x")]} noEffects
] noChanges {noEffects & wrapper = ESApplied (LUINo [0,1])}
] noChanges {noEffects & unwrapped = ESApplied (LUINo [0,0])}
,'DM'.newMap))
]
tests = applyUpstreamChangeTests
++ extractDownstreamChangeTests
......@@ -1452,6 +1590,7 @@ tests = applyUpstreamChangeTests
++ selectSubNode_Tests
++ updateSubNode_Tests
++ scanToPosition_Tests
++ nodeExists_Tests
++ compareLUINoTests
++ setUITypeTests
++ setUIAttributesTests
......@@ -1464,6 +1603,6 @@ tests = applyUpstreamChangeTests
++ wrapUITests
++ unwrapUITests
++ layoutSubUIsTests
++ combinationTests
Start w = runUnitTestsCLI [testsuite "Test.iTasks.UI.Layout" "Duh.." tests] w
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