module Dialog where
import Tcl

dialog :: GUI ()
dialog = do
 w <- window []
 title w "Testing a dialog box"
 lbl <- label w []
 b1 <- button w [text "Get an Open File Name",
                 command (do t <- getOpenFileName
		             cset lbl [text $ show t])]
 b2 <- button w [text "Get a Save File Name",
                 command (do t <- getSaveFileName
		             cset lbl [text $ show t])]
 b3 <- button w [text "Ok or cancel dialog",
                 command (do t <- primDialog "Ok or cancel"
		             cset lbl [text $ show t])]
 f <- frame w []
 packAdd lbl [packV]
 packAdd f [packV]
 mapM_ (\b -> packAdd b [packH,inFrame f]) [b1,b2]
 packAdd b3 [packV]
 

primDialog :: String -> GUI Bool
primDialog s = do
  ref <- newState Nothing
  
  w <- window []
  title w "Modal Dialog"
  lbl <- label w [text s]
  f <- frame w []
  packAdd lbl [packV]
  packAdd f [packAnchor C,fillX,packV,expand True]

  ok <- button w [text "Ok",command $ writeState ref (Just True)]
  cancel <- button w [text "Cancel",command $ writeState ref (Just False)]
  mapM (\w -> packAdd w [expand True,fillX,packH]) [ok,cancel]

  mkDialog False ref w  
