summaryrefslogtreecommitdiff
path: root/src/GF/UseGrammar/Session.hs
diff options
context:
space:
mode:
authoraarne <unknown>2003-10-10 11:35:52 +0000
committeraarne <unknown>2003-10-10 11:35:52 +0000
commitd0c75667910bfe5e2ee3f8434d7079f2c1bed65c (patch)
tree53c0702bbb1b26e99fa68b7652d2cf3721f9fac8 /src/GF/UseGrammar/Session.hs
parentce253baf15f9df5e95d0402ccddf5cc25c0736c0 (diff)
Added clipboard.
Diffstat (limited to 'src/GF/UseGrammar/Session.hs')
-rw-r--r--src/GF/UseGrammar/Session.hs31
1 files changed, 25 insertions, 6 deletions
diff --git a/src/GF/UseGrammar/Session.hs b/src/GF/UseGrammar/Session.hs
index 81158a515..7d43ea33c 100644
--- a/src/GF/UseGrammar/Session.hs
+++ b/src/GF/UseGrammar/Session.hs
@@ -13,17 +13,20 @@ import Operations
-- keep these abstract
-type SState = [(State,[Exp],SInfo)] -- exps are candidate refinements
-type SInfo = ([String],(Int,Options)) -- string is message, int is the view
+type SState = [(State,([Exp],[Clip]),SInfo)] -- exps: candidate refinements,clipboard
+type SInfo = ([String],(Int,Options)) -- string is message, int is the view
initSState :: SState
-initSState = [(initState, [], (["Select category to start"],(0,noOptions)))]
+initSState = [(initState, ([],[]), (["Select category to start"],(0,noOptions)))]
-- instead of empty
+type Clip = Tree ---- (Exp,Type)
+
okInfo n = ([],(n,True))
stateSState ((s,_,_):_) = s
-candsSState ((_,ts,_):_) = ts
+candsSState ((_,(ts,_),_):_)= ts
+clipSState ((_,(_,ts),_):_)= ts
infoSState ((_,_,i):_) = i
msgSState ((_,_,(m,_)):_) = m
viewSState ((_,_,(_,(v,_))):_) = v
@@ -40,10 +43,13 @@ type ECommand = SState -> SState
-- change state, drop cands, drop message, preserve options
changeState :: State -> ECommand
-changeState s ss = changeMsg [] $ (s,[],infoSState ss) : ss
+changeState s ss = changeMsg [] $ (s,([],clipSState ss),infoSState ss) : ss
changeCands :: [Exp] -> ECommand
-changeCands ts ss@((s,_,(_,b)):_) = (s,ts,(candInfo ts,b)) : ss -- add new state
+changeCands ts ss@((s,(_,cb),(_,b)):_) = (s,(ts,cb),(candInfo ts,b)) : ss
+
+addtoClip :: Clip -> ECommand
+addtoClip t ss@((s,(ts,cb),(i,b)):_) = (s,(ts,t:cb),(i,b)) : ss
changeMsg :: [String] -> ECommand
changeMsg m ((s,ts,(_,b)):ss) = (s,ts,(m,b)) : ss -- just change message
@@ -116,3 +122,16 @@ replaceByTermCommand der gr co exp =
let g = grammar gr in
refineByTrees der g $ maybe [exp] (\f -> f gr exp) $
lookupCustom customTermCommand (strCI co)
+
+possClipsSState :: StateGrammar -> SState -> [(Int,Clip)]
+possClipsSState gr s = filter poss $ zip [0..] (clipSState s)
+ where
+ poss = possibleTreeVal cgr st . snd
+ st = stateSState s
+ cgr = grammar gr
+
+getNumberedClip :: Int -> SState -> Err Clip
+getNumberedClip i s = if length cs > i then return (cs !! i)
+ else Bad "not enough clips"
+ where
+ cs = clipSState s