Skip to content

Instantly share code, notes, and snippets.

@wavewave
Created December 25, 2011 10:31
Show Gist options
  • Select an option

  • Save wavewave/1519079 to your computer and use it in GitHub Desktop.

Select an option

Save wavewave/1519079 to your computer and use it in GitHub Desktop.
gtk2hs: fileChooserDialog example
import Graphics.UI.Gtk
import Control.Monad.Trans
import System.Directory
main :: IO ()
main = do
putStrLn "file open test"
initGUI
window <- windowNew
button <- buttonNewWithLabel "test"
vbox <- vBoxNew False 0
boxPackStart vbox button PackNatural 0
containerAdd window vbox
button `on` buttonActivated $ do
putStrLn "button press"
fileOpen
window `on` deleteEvent $ tryEvent $ do
liftIO $ mainQuit
widgetShowAll window
mainGUI
fileOpen :: IO ()
fileOpen = do
cwd <- getCurrentDirectory
dialog <- fileChooserDialogNew Nothing Nothing FileChooserActionOpen
[ ("OK", ResponseOk)
, ("Cancel", ResponseCancel) ]
fileChooserSetCurrentFolder dialog cwd
res <- dialogRun dialog
case res of
ResponseDeleteEvent -> widgetDestroy dialog
ResponseOk -> do
mfilename <- fileChooserGetFilename dialog
putStrLn $ show $ mfilename
widgetDestroy dialog
ResponseCancel -> widgetDestroy dialog
_ -> error "??? in file open"
return ()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment