Created
December 25, 2011 10:31
-
-
Save wavewave/1519079 to your computer and use it in GitHub Desktop.
gtk2hs: fileChooserDialog example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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