module Controller.Cell (getInput,updateInView ,showContent,showSelectedContent) where import Control.Applicative ((<$>)) import Control.Monad (forM_) import Controller (Controller,onGridModel,onGridView,onView) import View.Component.Grid (setValue,getCursorPos) import View.FormulaInput (logString) import Model.Grid (getCell) import Model.Cell (showValueInGrid,input,value) import Model.CellContent (CellValue(EmptyValue,Error)) import CellCoordinate (CellCoord) getInput :: CellCoord -> Controller String getInput coord = input <$> (onGridModel $ getCell coord) updateInView :: [CellCoord] -> Controller () updateInView coords = forM_ coords $ \c -> do cell <- onGridModel $ getCell c onGridView $ setValue c $ showValueInGrid cell showContent :: CellCoord -> Controller () showContent coords = do cell <- onGridModel $ getCell coords let info = case value cell of EmptyValue -> show EmptyValue Error e -> show e _ -> input cell onView $ logString info showSelectedContent :: Controller () showSelectedContent = onGridView getCursorPos >>= showContent