{-# LANGUAGE CPP #-}
module FileShellF(
#ifndef __NHC__
  fileShellF,fileShellF',
   textFileShellF,textFileShellF',
   showReadFileShellF,showReadFileShellF'
#endif
 ) where
import Fudgets
import FilePickPopupF
import TitleShellF(titleShellF')
import MenuBarF
#ifndef __NHC__
          (menuBarF,menu,idT,item,cmdItem,key)
#endif
import DialogueIO
import Prelude hiding (IOError)
import Data.Maybe(isJust,fromJust,fromMaybe)
import Data.Char(isSpace)

#ifndef __NHC__

textFileShellF :: [Char] -> F [Char] (InputMsg [Char]) -> F c d
textFileShellF = forall {c} {d}.
(ShellF -> ShellF) -> [Char] -> F [Char] (InputMsg [Char]) -> F c d
textFileShellF' forall a. Customiser a
standard
textFileShellF' :: (ShellF -> ShellF) -> [Char] -> F [Char] (InputMsg [Char]) -> F c d
textFileShellF' ShellF -> ShellF
customiser = forall {c} {c} {d}.
(ShellF -> ShellF)
-> (c -> [Char], [Char] -> Either [Char] c, Maybe c)
-> [Char]
-> F c (InputMsg c)
-> F c d
fileShellF' ShellF -> ShellF
customiser forall {a} {b} {a}. (a -> a, b -> Either a b, Maybe [Char])
textConv
  where textConv :: (a -> a, b -> Either a b, Maybe [Char])
textConv = (forall a. Customiser a
id,forall a b. b -> Either a b
Right,forall a. a -> Maybe a
Just [Char]
"")

showReadFileShellF :: Maybe c -> [Char] -> F c (InputMsg c) -> F c d
showReadFileShellF Maybe c
empty = forall {c} {c} {d}.
(Show c, Read c) =>
(ShellF -> ShellF)
-> Maybe c -> [Char] -> F c (InputMsg c) -> F c d
showReadFileShellF' forall a. Customiser a
standard Maybe c
empty
showReadFileShellF' :: (ShellF -> ShellF)
-> Maybe c -> [Char] -> F c (InputMsg c) -> F c d
showReadFileShellF' ShellF -> ShellF
customiser Maybe c
empty =
    forall {c} {c} {d}.
(ShellF -> ShellF)
-> (c -> [Char], [Char] -> Either [Char] c, Maybe c)
-> [Char]
-> F c (InputMsg c)
-> F c d
fileShellF' ShellF -> ShellF
customiser (forall a. Show a => a -> [Char]
show,forall {b}. Read b => [Char] -> Either [Char] b
parse,Maybe c
empty)
  where
    parse :: [Char] -> Either [Char] b
parse [Char]
contents =
      case forall a. Read a => ReadS a
reads [Char]
contents of
        [(b
x,[Char]
cs)] | forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
all Char -> Bool
isSpace [Char]
cs -> forall a b. b -> Either a b
Right b
x
	[(b, [Char])]
_ -> forall a b. a -> Either a b
Left [Char]
"Syntax error in input"



fileShellF :: (c -> [Char], [Char] -> Either [Char] c, Maybe c)
-> [Char] -> F c (InputMsg c) -> F c d
fileShellF = forall {c} {c} {d}.
(ShellF -> ShellF)
-> (c -> [Char], [Char] -> Either [Char] c, Maybe c)
-> [Char]
-> F c (InputMsg c)
-> F c d
fileShellF' forall a. Customiser a
standard

fileShellF' :: (ShellF -> ShellF)
-> (c -> [Char], [Char] -> Either [Char] c, Maybe c)
-> [Char]
-> F c (InputMsg c)
-> F c d
fileShellF' ShellF -> ShellF
customiser (c -> [Char], [Char] -> Either [Char] c, Maybe c)
conv [Char]
title0 F c (InputMsg c)
appF =
    forall a b c d. F a b -> F c d
stubF forall a b. (a -> b) -> a -> b
$ forall a b. F a a -> F a b
loopOnlyF forall a b. (a -> b) -> a -> b
$ forall {c} {d}.
(ShellF -> ShellF) -> [Char] -> F c d -> F (Either [Char] c) d
titleShellF' ShellF -> ShellF
customiser [Char]
title0 forall {c} {b} {a}.
F (Either
     (Either (FileMenuItem, ([Char], Maybe [Char])) (Either [Char] c))
     (Either FileMenuItem c))
  (Either
     [Char]
     (Either
        (Either (FileMenuItem, ([Char], Maybe [Char])) (Either [Char] b))
        (Either a c)))
mainF
  where
    mainF :: F (Either
     (Either (FileMenuItem, ([Char], Maybe [Char])) (Either [Char] c))
     (Either FileMenuItem c))
  (Either
     [Char]
     (Either
        (Either (FileMenuItem, ([Char], Maybe [Char])) (Either [Char] b))
        (Either a c)))
mainF = forall {a} {b} {a} {b} {b} {a}.
[Char]
-> (a -> [Char], [Char] -> Either [Char] a, Maybe a)
-> F (Either
        (Either ((FileMenuItem, b), [Char]) (Either a b))
        (Either FileMenuItem (InputMsg a)))
     (Either
        [Char]
        (Either
           (Either (FileMenuItem, ([Char], Maybe [Char])) (Either [Char] b))
           (Either a a)))
ctrlF [Char]
title0 (c -> [Char], [Char] -> Either [Char] c, Maybe c)
conv forall {a1} {b} {a2}. F a1 b -> F a2 a1 -> F a2 b
>==<
            (forall {c} {d}.
F (Either (FileMenuItem, ([Char], Maybe [Char])) (Either [Char] c))
  (Either
     ((FileMenuItem, ([Char], Maybe [Char])), [Char])
     (Either ([Char], Click) d))
popupsFforall {a} {b} {c} {d}.
F a b -> F c d -> F (Either a c) (Either b d)
>+<forall {a} {b}. F a b -> F a b
vBoxF (Bool -> F FileMenuItem FileMenuItem
fileShellMenuBarF Bool
hasNewforall {a} {b} {c} {d}.
F a b -> F c d -> F (Either a c) (Either b d)
>+<F c (InputMsg c)
appF))
      where hasNew :: Bool
hasNew = case (c -> [Char], [Char] -> Either [Char] c, Maybe c)
conv of (c -> [Char]
_,[Char] -> Either [Char] c
_,Maybe c
e) -> forall a. Maybe a -> Bool
isJust Maybe c
e

    popupsF :: F (Either (FileMenuItem, ([Char], Maybe [Char])) (Either [Char] c))
  (Either
     ((FileMenuItem, ([Char], Maybe [Char])), [Char])
     (Either ([Char], Click) d))
popupsF = F (FileMenuItem, ([Char], Maybe [Char]))
  ((FileMenuItem, ([Char], Maybe [Char])), [Char])
filePickPopupF' forall {a} {b} {c} {d}.
F a b -> F c d -> F (Either a c) (Either b d)
>+<(forall msg. Graphic msg => F msg (msg, Click)
messagePopupFforall {a} {b} {c} {d}.
F a b -> F c d -> F (Either a c) (Either b d)
>+<forall {hi} {ho}. F hi ho
nullF{-confirmPopupF-})
      where
        filePickPopupF' :: F (FileMenuItem, ([Char], Maybe [Char]))
  ((FileMenuItem, ([Char], Maybe [Char])), [Char])
filePickPopupF' = forall {b} {a}. [b] -> F a b -> F a b
putsF (forall a b. (a -> b) -> [a] -> [b]
map forall {b} {a}. b -> ((FileMenuItem, ([Char], Maybe a)), b)
f (forall a. Int -> [a] -> [a]
take Int
1 [[Char]]
args)) forall {a}.
F (a, ([Char], Maybe [Char])) ((a, ([Char], Maybe [Char])), [Char])
filePickPopupF
	f :: b -> ((FileMenuItem, ([Char], Maybe a)), b)
f b
x = ((FileMenuItem
Open,forall {a}. ([Char], Maybe a)
popup),b
x)


messageF :: a
-> F hi (Either a (Either (Either a (Either a b)) b))
-> F hi (Either a (Either (Either a (Either a b)) b))
messageF = forall {ho} {hi}. ho -> F hi ho -> F hi ho
putF forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall {a} {a} {a} {b} {b}.
a -> Either a (Either (Either a (Either a b)) b)
toMessage
toFilePick :: a -> Either a (Either (Either a b) b)
toFilePick = forall a b. b -> Either a b
Right forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a b. a -> Either a b
Left forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a b. a -> Either a b
Left
toMessage :: a -> Either a (Either (Either a (Either a b)) b)
toMessage = forall a b. b -> Either a b
Right forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a b. a -> Either a b
Left forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a b. b -> Either a b
Right forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a b. a -> Either a b
Left
--toConfirm = Right . Left . Right . Left
toApp :: a -> Either a (Either a (Either a a))
toApp = forall a b. b -> Either a b
Right forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a b. b -> Either a b
Right forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a b. b -> Either a b
Right
toTitle :: a -> Either a b
toTitle = forall a b. a -> Either a b
Left

ctrlF :: [Char]
-> (a -> [Char], [Char] -> Either [Char] a, Maybe a)
-> F (Either
        (Either ((FileMenuItem, b), [Char]) (Either a b))
        (Either FileMenuItem (InputMsg a)))
     (Either
        [Char]
        (Either
           (Either (FileMenuItem, ([Char], Maybe [Char])) (Either [Char] b))
           (Either a a)))
ctrlF [Char]
title0 (a -> [Char]
show,[Char] -> Either [Char] a
parse,Maybe a
optEmpty) = forall {b} {a} {b} {b} {a}.
F (Either
     (Either ((FileMenuItem, b), [Char]) (Either a b))
     (Either FileMenuItem (InputMsg a)))
  (Either
     [Char]
     (Either
        (Either (FileMenuItem, ([Char], Maybe [Char])) (Either [Char] b))
        (Either a a)))
start
 where
  start :: F (Either
     (Either ((FileMenuItem, b), [Char]) (Either a b))
     (Either FileMenuItem (InputMsg a)))
  (Either
     [Char]
     (Either
        (Either (FileMenuItem, ([Char], Maybe [Char])) (Either [Char] b))
        (Either a a)))
start = Maybe [Char]
-> Maybe a
-> F (Either
        (Either ((FileMenuItem, b), [Char]) (Either a b))
        (Either FileMenuItem (InputMsg a)))
     (Either
        [Char]
        (Either
           (Either (FileMenuItem, ([Char], Maybe [Char])) (Either [Char] b))
           (Either a a)))
loop forall a. Maybe a
Nothing forall a. Maybe a
Nothing
  changeTitle :: [Char] -> F hi (Either [Char] b) -> F hi (Either [Char] b)
changeTitle [Char]
name = forall {ho} {hi}. ho -> F hi ho -> F hi ho
putF (forall a b. a -> Either a b
toTitle ([Char]
title0forall a. [a] -> [a] -> [a]
++[Char]
": "forall a. [a] -> [a] -> [a]
++[Char]
name))
  loop :: Maybe [Char]
-> Maybe a
-> F (Either
        (Either ((FileMenuItem, b), [Char]) (Either a b))
        (Either FileMenuItem (InputMsg a)))
     (Either
        [Char]
        (Either
           (Either (FileMenuItem, ([Char], Maybe [Char])) (Either [Char] b))
           (Either a a)))
loop Maybe [Char]
filename Maybe a
document =
    forall {a} {ho}. Cont (F a ho) a
getF forall a b. (a -> b) -> a -> b
$ {-either quitMsg-} (forall a c b. (a -> c) -> (b -> c) -> Either a b -> c
either forall {b} {a} {b}.
Either ((FileMenuItem, b), [Char]) (Either a b)
-> F (Either
        (Either ((FileMenuItem, b), [Char]) (Either a b))
        (Either FileMenuItem (InputMsg a)))
     (Either
        [Char]
        (Either
           (Either (FileMenuItem, ([Char], Maybe [Char])) (Either [Char] b))
           (Either a a)))
fromPopups (forall a c b. (a -> c) -> (b -> c) -> Either a b -> c
either FileMenuItem
-> F (Either
        (Either ((FileMenuItem, b), [Char]) (Either a b))
        (Either FileMenuItem (InputMsg a)))
     (Either
        [Char]
        (Either
           (Either (FileMenuItem, ([Char], Maybe [Char])) (Either [Char] b))
           (Either a a)))
fromMenu InputMsg a
-> F (Either
        (Either ((FileMenuItem, b), [Char]) (Either a b))
        (Either FileMenuItem (InputMsg a)))
     (Either
        [Char]
        (Either
           (Either (FileMenuItem, ([Char], Maybe [Char])) (Either [Char] b))
           (Either a a)))
fromApp))
   where
    same :: F (Either
     (Either ((FileMenuItem, b), [Char]) (Either a b))
     (Either FileMenuItem (InputMsg a)))
  (Either
     [Char]
     (Either
        (Either (FileMenuItem, ([Char], Maybe [Char])) (Either [Char] b))
        (Either a a)))
same = Maybe [Char]
-> Maybe a
-> F (Either
        (Either ((FileMenuItem, b), [Char]) (Either a b))
        (Either FileMenuItem (InputMsg a)))
     (Either
        [Char]
        (Either
           (Either (FileMenuItem, ([Char], Maybe [Char])) (Either [Char] b))
           (Either a a)))
loop Maybe [Char]
filename Maybe a
document
    newName :: [Char]
-> Maybe a
-> F (Either
        (Either ((FileMenuItem, b), [Char]) (Either a b))
        (Either FileMenuItem (InputMsg a)))
     (Either
        [Char]
        (Either
           (Either (FileMenuItem, ([Char], Maybe [Char])) (Either [Char] b))
           (Either a a)))
newName [Char]
name Maybe a
document' = forall {hi} {b}.
[Char] -> F hi (Either [Char] b) -> F hi (Either [Char] b)
changeTitle [Char]
name forall a b. (a -> b) -> a -> b
$ Maybe [Char]
-> Maybe a
-> F (Either
        (Either ((FileMenuItem, b), [Char]) (Either a b))
        (Either FileMenuItem (InputMsg a)))
     (Either
        [Char]
        (Either
           (Either (FileMenuItem, ([Char], Maybe [Char])) (Either [Char] b))
           (Either a a)))
loop (forall a. a -> Maybe a
Just [Char]
name) Maybe a
document'
    errMsg :: [Char]
-> F (Either
        (Either ((FileMenuItem, b), [Char]) (Either a b))
        (Either FileMenuItem (InputMsg a)))
     (Either
        [Char]
        (Either
           (Either (FileMenuItem, ([Char], Maybe [Char])) (Either [Char] b))
           (Either a a)))
errMsg [Char]
err = forall {a} {hi} {a} {a} {b} {b}.
a
-> F hi (Either a (Either (Either a (Either a b)) b))
-> F hi (Either a (Either (Either a (Either a b)) b))
messageF [Char]
err F (Either
     (Either ((FileMenuItem, b), [Char]) (Either a b))
     (Either FileMenuItem (InputMsg a)))
  (Either
     [Char]
     (Either
        (Either (FileMenuItem, ([Char], Maybe [Char])) (Either [Char] b))
        (Either a a)))
same

    quitMsg :: ()
-> F (Either
        (Either ((FileMenuItem, b), [Char]) (Either a b))
        (Either FileMenuItem (InputMsg a)))
     (Either
        [Char]
        (Either
           (Either (FileMenuItem, ([Char], Maybe [Char])) (Either [Char] b))
           (Either a a)))
quitMsg () = F (Either
     (Either ((FileMenuItem, b), [Char]) (Either a b))
     (Either FileMenuItem (InputMsg a)))
  (Either
     [Char]
     (Either
        (Either (FileMenuItem, ([Char], Maybe [Char])) (Either [Char] b))
        (Either a a)))
terminateProgram

    fromPopups :: Either ((FileMenuItem, b), [Char]) (Either a b)
-> F (Either
        (Either ((FileMenuItem, b), [Char]) (Either a b))
        (Either FileMenuItem (InputMsg a)))
     (Either
        [Char]
        (Either
           (Either (FileMenuItem, ([Char], Maybe [Char])) (Either [Char] b))
           (Either a a)))
fromPopups = forall a c b. (a -> c) -> (b -> c) -> Either a b -> c
either forall {b}.
((FileMenuItem, b), [Char])
-> F (Either
        (Either ((FileMenuItem, b), [Char]) (Either a b))
        (Either FileMenuItem (InputMsg a)))
     (Either
        [Char]
        (Either
           (Either (FileMenuItem, ([Char], Maybe [Char])) (Either [Char] b))
           (Either a a)))
fromFilePick (forall a c b. (a -> c) -> (b -> c) -> Either a b -> c
either forall {p}.
p
-> F (Either
        (Either ((FileMenuItem, b), [Char]) (Either a b))
        (Either FileMenuItem (InputMsg a)))
     (Either
        [Char]
        (Either
           (Either (FileMenuItem, ([Char], Maybe [Char])) (Either [Char] b))
           (Either a a)))
fromMessage forall {p}.
p
-> F (Either
        (Either ((FileMenuItem, b), [Char]) (Either a b))
        (Either FileMenuItem (InputMsg a)))
     (Either
        [Char]
        (Either
           (Either (FileMenuItem, ([Char], Maybe [Char])) (Either [Char] b))
           (Either a a)))
fromConfirm)
    fromMessage :: p
-> F (Either
        (Either ((FileMenuItem, b), [Char]) (Either a b))
        (Either FileMenuItem (InputMsg a)))
     (Either
        [Char]
        (Either
           (Either (FileMenuItem, ([Char], Maybe [Char])) (Either [Char] b))
           (Either a a)))
fromMessage p
_ = F (Either
     (Either ((FileMenuItem, b), [Char]) (Either a b))
     (Either FileMenuItem (InputMsg a)))
  (Either
     [Char]
     (Either
        (Either (FileMenuItem, ([Char], Maybe [Char])) (Either [Char] b))
        (Either a a)))
same
    fromConfirm :: p
-> F (Either
        (Either ((FileMenuItem, b), [Char]) (Either a b))
        (Either FileMenuItem (InputMsg a)))
     (Either
        [Char]
        (Either
           (Either (FileMenuItem, ([Char], Maybe [Char])) (Either [Char] b))
           (Either a a)))
fromConfirm p
_ = F (Either
     (Either ((FileMenuItem, b), [Char]) (Either a b))
     (Either FileMenuItem (InputMsg a)))
  (Either
     [Char]
     (Either
        (Either (FileMenuItem, ([Char], Maybe [Char])) (Either [Char] b))
        (Either a a)))
same -- !!

    fromMenu :: FileMenuItem
-> F (Either
        (Either ((FileMenuItem, b), [Char]) (Either a b))
        (Either FileMenuItem (InputMsg a)))
     (Either
        [Char]
        (Either
           (Either (FileMenuItem, ([Char], Maybe [Char])) (Either [Char] b))
           (Either a a)))
fromMenu FileMenuItem
filecmd =
      case FileMenuItem
filecmd of
	FileMenuItem
Open -> forall {ho} {hi}. ho -> F hi ho -> F hi ho
putF (forall {a} {a} {b} {b}. a -> Either a (Either (Either a b) b)
toFilePick (FileMenuItem
Open,([Char]
"Open",forall a. Maybe a
Nothing))) F (Either
     (Either ((FileMenuItem, b), [Char]) (Either a b))
     (Either FileMenuItem (InputMsg a)))
  (Either
     [Char]
     (Either
        (Either (FileMenuItem, ([Char], Maybe [Char])) (Either [Char] b))
        (Either a a)))
same
        FileMenuItem
Save -> forall a b c. (a -> b -> c) -> b -> a -> c
flip (forall b a. b -> (a -> b) -> Maybe a -> b
maybe F (Either
     (Either ((FileMenuItem, b), [Char]) (Either a b))
     (Either FileMenuItem (InputMsg a)))
  (Either
     [Char]
     (Either
        (Either (FileMenuItem, ([Char], Maybe [Char])) (Either [Char] b))
        (Either a a)))
same) Maybe a
document forall a b. (a -> b) -> a -> b
$ \ a
doc ->
	        forall a b c. (a -> b -> c) -> b -> a -> c
flip (forall b a. b -> (a -> b) -> Maybe a -> b
maybe (FileMenuItem
-> F (Either
        (Either ((FileMenuItem, b), [Char]) (Either a b))
        (Either FileMenuItem (InputMsg a)))
     (Either
        [Char]
        (Either
           (Either (FileMenuItem, ([Char], Maybe [Char])) (Either [Char] b))
           (Either a a)))
fromMenu FileMenuItem
SaveAs)) Maybe [Char]
filename forall a b. (a -> b) -> a -> b
$ \ [Char]
name ->
		forall {t} {a} {b}.
(t -> [Char]) -> [Char] -> t -> ([Char] -> F a b) -> F a b -> F a b
saveF a -> [Char]
show [Char]
name a
doc [Char]
-> F (Either
        (Either ((FileMenuItem, b), [Char]) (Either a b))
        (Either FileMenuItem (InputMsg a)))
     (Either
        [Char]
        (Either
           (Either (FileMenuItem, ([Char], Maybe [Char])) (Either [Char] b))
           (Either a a)))
errMsg forall a b. (a -> b) -> a -> b
$
	        F (Either
     (Either ((FileMenuItem, b), [Char]) (Either a b))
     (Either FileMenuItem (InputMsg a)))
  (Either
     [Char]
     (Either
        (Either (FileMenuItem, ([Char], Maybe [Char])) (Either [Char] b))
        (Either a a)))
same
	FileMenuItem
SaveAs -> forall a b c. (a -> b -> c) -> b -> a -> c
flip (forall b a. b -> (a -> b) -> Maybe a -> b
maybe F (Either
     (Either ((FileMenuItem, b), [Char]) (Either a b))
     (Either FileMenuItem (InputMsg a)))
  (Either
     [Char]
     (Either
        (Either (FileMenuItem, ([Char], Maybe [Char])) (Either [Char] b))
        (Either a a)))
same) Maybe a
document forall a b. (a -> b) -> a -> b
$ \ a
_ ->
	          forall {ho} {hi}. ho -> F hi ho -> F hi ho
putF (forall {a} {a} {b} {b}. a -> Either a (Either (Either a b) b)
toFilePick (FileMenuItem
SaveAs,([Char]
"Save",forall a. a -> Maybe a
Just (forall a. a -> Maybe a -> a
fromMaybe [Char]
"" Maybe [Char]
filename)))) F (Either
     (Either ((FileMenuItem, b), [Char]) (Either a b))
     (Either FileMenuItem (InputMsg a)))
  (Either
     [Char]
     (Either
        (Either (FileMenuItem, ([Char], Maybe [Char])) (Either [Char] b))
        (Either a a)))
same
	FileMenuItem
Quit -> F (Either
     (Either ((FileMenuItem, b), [Char]) (Either a b))
     (Either FileMenuItem (InputMsg a)))
  (Either
     [Char]
     (Either
        (Either (FileMenuItem, ([Char], Maybe [Char])) (Either [Char] b))
        (Either a a)))
terminateProgram
	FileMenuItem
New  -> forall a b c. (a -> b -> c) -> b -> a -> c
flip (forall b a. b -> (a -> b) -> Maybe a -> b
maybe forall a b. (a -> b) -> a -> b
$ [Char]
-> F (Either
        (Either ((FileMenuItem, b), [Char]) (Either a b))
        (Either FileMenuItem (InputMsg a)))
     (Either
        [Char]
        (Either
           (Either (FileMenuItem, ([Char], Maybe [Char])) (Either [Char] b))
           (Either a a)))
errMsg [Char]
"New not implemented") Maybe a
optEmpty forall a b. (a -> b) -> a -> b
$ \a
empty ->
	        forall {hi} {b}.
[Char] -> F hi (Either [Char] b) -> F hi (Either [Char] b)
changeTitle [Char]
"Empty file" forall a b. (a -> b) -> a -> b
$
	        forall {ho} {hi}. ho -> F hi ho -> F hi ho
putF (forall {a} {a} {a} {a}. a -> Either a (Either a (Either a a))
toApp a
empty) forall a b. (a -> b) -> a -> b
$
		F (Either
     (Either ((FileMenuItem, b), [Char]) (Either a b))
     (Either FileMenuItem (InputMsg a)))
  (Either
     [Char]
     (Either
        (Either (FileMenuItem, ([Char], Maybe [Char])) (Either [Char] b))
        (Either a a)))
start
	FileMenuItem
_ -> F (Either
     (Either ((FileMenuItem, b), [Char]) (Either a b))
     (Either FileMenuItem (InputMsg a)))
  (Either
     [Char]
     (Either
        (Either (FileMenuItem, ([Char], Maybe [Char])) (Either [Char] b))
        (Either a a)))
same

    terminateProgram :: F (Either
     (Either ((FileMenuItem, b), [Char]) (Either a b))
     (Either FileMenuItem (InputMsg a)))
  (Either
     [Char]
     (Either
        (Either (FileMenuItem, ([Char], Maybe [Char])) (Either [Char] b))
        (Either a a)))
terminateProgram = forall a b. Request -> F a b -> F a b
hIOSuccF (Int -> Request
Exit Int
0) F (Either
     (Either ((FileMenuItem, b), [Char]) (Either a b))
     (Either FileMenuItem (InputMsg a)))
  (Either
     [Char]
     (Either
        (Either (FileMenuItem, ([Char], Maybe [Char])) (Either [Char] b))
        (Either a a)))
same

    fromFilePick :: ((FileMenuItem, b), [Char])
-> F (Either
        (Either ((FileMenuItem, b), [Char]) (Either a b))
        (Either FileMenuItem (InputMsg a)))
     (Either
        [Char]
        (Either
           (Either (FileMenuItem, ([Char], Maybe [Char])) (Either [Char] b))
           (Either a a)))
fromFilePick ((FileMenuItem
action,b
_),[Char]
filename) =
      case FileMenuItem
action of
        FileMenuItem
Open -> forall {b} {a} {b}.
([Char] -> Either [Char] b)
-> [Char] -> ([Char] -> F a b) -> (b -> F a b) -> F a b
openF [Char] -> Either [Char] a
parse [Char]
filename [Char]
-> F (Either
        (Either ((FileMenuItem, b), [Char]) (Either a b))
        (Either FileMenuItem (InputMsg a)))
     (Either
        [Char]
        (Either
           (Either (FileMenuItem, ([Char], Maybe [Char])) (Either [Char] b))
           (Either a a)))
errMsg
		      (\ a
contents ->
	               forall {ho} {hi}. ho -> F hi ho -> F hi ho
putF (forall {a} {a} {a} {a}. a -> Either a (Either a (Either a a))
toApp a
contents) forall a b. (a -> b) -> a -> b
$
	               [Char]
-> Maybe a
-> F (Either
        (Either ((FileMenuItem, b), [Char]) (Either a b))
        (Either FileMenuItem (InputMsg a)))
     (Either
        [Char]
        (Either
           (Either (FileMenuItem, ([Char], Maybe [Char])) (Either [Char] b))
           (Either a a)))
newName [Char]
filename (forall a. a -> Maybe a
Just a
contents))
        FileMenuItem
SaveAs -> forall {t} {a} {b}.
(t -> [Char]) -> [Char] -> t -> ([Char] -> F a b) -> F a b -> F a b
saveF a -> [Char]
show [Char]
filename (forall a. HasCallStack => Maybe a -> a
fromJust Maybe a
document) [Char]
-> F (Either
        (Either ((FileMenuItem, b), [Char]) (Either a b))
        (Either FileMenuItem (InputMsg a)))
     (Either
        [Char]
        (Either
           (Either (FileMenuItem, ([Char], Maybe [Char])) (Either [Char] b))
           (Either a a)))
errMsg forall a b. (a -> b) -> a -> b
$
                  [Char]
-> Maybe a
-> F (Either
        (Either ((FileMenuItem, b), [Char]) (Either a b))
        (Either FileMenuItem (InputMsg a)))
     (Either
        [Char]
        (Either
           (Either (FileMenuItem, ([Char], Maybe [Char])) (Either [Char] b))
           (Either a a)))
newName [Char]
filename Maybe a
document
	FileMenuItem
_ -> forall a. HasCallStack => a
undefined -- shouldn't happen

    fromApp :: InputMsg a
-> F (Either
        (Either ((FileMenuItem, b), [Char]) (Either a b))
        (Either FileMenuItem (InputMsg a)))
     (Either
        [Char]
        (Either
           (Either (FileMenuItem, ([Char], Maybe [Char])) (Either [Char] b))
           (Either a a)))
fromApp InputMsg a
inpmsg =
      case forall {a}. InputMsg a -> Maybe a
inputDone InputMsg a
inpmsg of
	Just a
doc ->
	  case Maybe [Char]
filename of
	    Just [Char]
name -> forall {t} {a} {b}.
(t -> [Char]) -> [Char] -> t -> ([Char] -> F a b) -> F a b -> F a b
saveF a -> [Char]
show [Char]
name a
doc [Char]
-> F (Either
        (Either ((FileMenuItem, b), [Char]) (Either a b))
        (Either FileMenuItem (InputMsg a)))
     (Either
        [Char]
        (Either
           (Either (FileMenuItem, ([Char], Maybe [Char])) (Either [Char] b))
           (Either a a)))
errMsg forall a b. (a -> b) -> a -> b
$
	                 Maybe [Char]
-> Maybe a
-> F (Either
        (Either ((FileMenuItem, b), [Char]) (Either a b))
        (Either FileMenuItem (InputMsg a)))
     (Either
        [Char]
        (Either
           (Either (FileMenuItem, ([Char], Maybe [Char])) (Either [Char] b))
           (Either a a)))
loop Maybe [Char]
filename (forall a. a -> Maybe a
Just a
doc)
            Maybe [Char]
Nothing   -> forall {ho} {hi}. ho -> F hi ho -> F hi ho
putF (forall {a} {a} {b} {b}. a -> Either a (Either (Either a b) b)
toFilePick (FileMenuItem
SaveAs,([Char]
"Save",Maybe [Char]
filename))) forall a b. (a -> b) -> a -> b
$
	                 Maybe [Char]
-> Maybe a
-> F (Either
        (Either ((FileMenuItem, b), [Char]) (Either a b))
        (Either FileMenuItem (InputMsg a)))
     (Either
        [Char]
        (Either
           (Either (FileMenuItem, ([Char], Maybe [Char])) (Either [Char] b))
           (Either a a)))
loop Maybe [Char]
filename (forall a. a -> Maybe a
Just a
doc)
	Maybe a
Nothing -> Maybe [Char]
-> Maybe a
-> F (Either
        (Either ((FileMenuItem, b), [Char]) (Either a b))
        (Either FileMenuItem (InputMsg a)))
     (Either
        [Char]
        (Either
           (Either (FileMenuItem, ([Char], Maybe [Char])) (Either [Char] b))
           (Either a a)))
loop Maybe [Char]
filename (forall a. a -> Maybe a
Just (forall {a}. InputMsg a -> a
stripInputMsg InputMsg a
inpmsg))


data FileMenuItem = New | Open | Save | SaveAs | Quit deriving (FileMenuItem -> FileMenuItem -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: FileMenuItem -> FileMenuItem -> Bool
$c/= :: FileMenuItem -> FileMenuItem -> Bool
== :: FileMenuItem -> FileMenuItem -> Bool
$c== :: FileMenuItem -> FileMenuItem -> Bool
Eq)


fileShellMenuBarF :: Bool -> F FileMenuItem FileMenuItem
fileShellMenuBarF Bool
hasNew =
    forall {a} {b}. Either a b -> a
fromLeft forall a b e. (a -> b) -> F e a -> F e b
>^=< forall {a} {b}. F a b -> F a b
hBoxF (Bool -> F FileMenuItem FileMenuItem
fileMenuF Bool
hasNew forall {a} {b} {c} {d}.
F a b -> F c d -> F (Either a c) (Either b d)
>+< forall {hi} {ho}. F hi ho
gcWarnF) forall c d e. F c d -> (e -> c) -> F e d
>=^< forall a b. a -> Either a b
Left
  where gcWarnF :: F a b
gcWarnF = forall {a} {b}. Spacer -> F a b -> F a b
spacer1F (Alignment -> Alignment -> Spacer
hvAlignS Alignment
aRight Alignment
aCenter) forall {hi} {ho}. F hi ho
gcWarningF

fileMenuF :: Bool -> F FileMenuItem FileMenuItem
fileMenuF Bool
hasNew =
    forall {a} {b}. Spacer -> F a b -> F a b
spacer1F (Bool -> Bool -> Spacer
noStretchS Bool
True Bool
True Spacer -> Spacer -> Spacer
`compS` Spacer
leftS) (forall {a}. Eq a => Menu a -> F a a
menuBarF [Item (MenuItem FileMenuItem)]
menuBar)
  where
    menuBar :: [Item (MenuItem FileMenuItem)]
menuBar = [forall {a1} {a2}. Graphic a1 => a2 -> a1 -> Item a2
item MenuItem FileMenuItem
fileMenu [Char]
"File"] -- more?
    fileMenu :: MenuItem FileMenuItem
fileMenu = forall {b} {a}. Eq b => Transl b a -> Menu b -> MenuItem a
menu forall {g}. Transl g g
idT forall a b. (a -> b) -> a -> b
$
               (if Bool
hasNew then (forall {a} {p}. Graphic a => p -> a -> Item (MenuItem p)
cmdItem FileMenuItem
New    [Char]
"New"forall a. a -> [a] -> [a]
:) else forall a. Customiser a
id)
	       [forall {a} {p}. Graphic a => p -> a -> Item (MenuItem p)
cmdItem FileMenuItem
Open   [Char]
"Open..."     forall {a}. Item a -> [Char] -> Item a
`key` [Char]
"o",
		forall {a} {p}. Graphic a => p -> a -> Item (MenuItem p)
cmdItem FileMenuItem
Save   [Char]
"Save"        forall {a}. Item a -> [Char] -> Item a
`key` [Char]
"s",
		forall {a} {p}. Graphic a => p -> a -> Item (MenuItem p)
cmdItem FileMenuItem
SaveAs [Char]
"Save As..."  forall {a}. Item a -> [Char] -> Item a
`key` [Char]
"a",
		forall {a} {p}. Graphic a => p -> a -> Item (MenuItem p)
cmdItem FileMenuItem
Quit   [Char]
"Quit"        forall {a}. Item a -> [Char] -> Item a
`key` [Char]
"q" ]

saveF :: (t -> [Char]) -> [Char] -> t -> ([Char] -> F a b) -> F a b -> F a b
saveF t -> [Char]
showdoc [Char]
filename t
doc [Char] -> F a b
errcont F a b
cont =
  forall a b.
Request -> (IOError -> F a b) -> (Response -> F a b) -> F a b
hIOerrF ([Char] -> [Char] -> Request
WriteFile [Char]
filename (t -> [Char]
showdoc t
doc))
	  ([Char] -> F a b
errcontforall b c a. (b -> c) -> (a -> b) -> a -> c
.forall a. Show a => a -> [Char]
show)
	  (forall a b. a -> b -> a
const F a b
cont)

openF :: ([Char] -> Either [Char] b)
-> [Char] -> ([Char] -> F a b) -> (b -> F a b) -> F a b
openF [Char] -> Either [Char] b
parse [Char]
filename [Char] -> F a b
errcont b -> F a b
cont =
  forall a b.
Request -> (IOError -> F a b) -> (Response -> F a b) -> F a b
hIOerrF ([Char] -> Request
ReadFile [Char]
filename) ([Char] -> F a b
errcontforall b c a. (b -> c) -> (a -> b) -> a -> c
.forall a. Show a => a -> [Char]
show) forall a b. (a -> b) -> a -> b
$ \ (Str [Char]
contents) ->
  forall a c b. (a -> c) -> (b -> c) -> Either a b -> c
either [Char] -> F a b
errcont b -> F a b
cont ([Char] -> Either [Char] b
parse [Char]
contents)

--messageF msg = contDynF $ (startupF [msg] messagePopupF>=^^<nullSP)
-- contDynF doesn't seem to work properly

#endif