GUI: merge callback functions into drawDiag/saveDiag

This commit is contained in:
hasufell 2014-10-11 02:01:17 +02:00
parent 0681b4d605
commit 5e5f305c65
No known key found for this signature in database
GPG Key ID: 220CD1C5BDEED020

View File

@ -108,19 +108,19 @@ makeGUI startFile = do
-- callbacks -- callbacks
_ <- onDestroy (win mygui) mainQuit _ <- onDestroy (win mygui) mainQuit
_ <- onClicked (dB mygui) $ onClickedDrawButton mygui _ <- onClicked (dB mygui) $ drawDiag mygui
_ <- onClicked (sB mygui) $ onClickedSaveButton mygui _ <- onClicked (sB mygui) $ saveDiag mygui
_ <- onClicked (qB mygui) mainQuit _ <- onClicked (qB mygui) mainQuit
_ <- onResponse (aD mygui) (\x -> case x of _ <- onResponse (aD mygui) (\x -> case x of
ResponseCancel -> widgetHideAll (aD mygui) ResponseCancel -> widgetHideAll (aD mygui)
_ -> return ()) _ -> return ())
-- have to redraw for window overlapping and resizing on expose -- have to redraw for window overlapping and resizing on expose
_ <- onExpose (da mygui) (\_ -> onClickedDrawButton mygui >>= _ <- onExpose (da mygui) (\_ -> drawDiag mygui >>=
(\_ -> return True)) (\_ -> return True))
_ <- on (cB mygui) changed (onClickedDrawButton mygui) _ <- on (cB mygui) changed (drawDiag mygui)
_ <- on (gC mygui) toggled (onClickedDrawButton mygui) _ <- on (gC mygui) toggled (drawDiag mygui)
_ <- on (cC mygui) toggled (onClickedDrawButton mygui) _ <- on (cC mygui) toggled (drawDiag mygui)
_ <- on (hs mygui) valueChanged (onClickedDrawButton mygui) _ <- on (hs mygui) valueChanged (drawDiag mygui)
-- hotkeys -- hotkeys
_ <- win mygui `on` keyPressEvent $ tryEvent $ do _ <- win mygui `on` keyPressEvent $ tryEvent $ do
@ -130,11 +130,11 @@ makeGUI startFile = do
_ <- win mygui `on` keyPressEvent $ tryEvent $ do _ <- win mygui `on` keyPressEvent $ tryEvent $ do
[Control] <- eventModifier [Control] <- eventModifier
"s" <- eventKeyName "s" <- eventKeyName
liftIO $ onClickedSaveButton mygui liftIO $ saveDiag mygui
_ <- win mygui `on` keyPressEvent $ tryEvent $ do _ <- win mygui `on` keyPressEvent $ tryEvent $ do
[Control] <- eventModifier [Control] <- eventModifier
"d" <- eventKeyName "d" <- eventKeyName
liftIO $ onClickedDrawButton mygui liftIO $ drawDiag mygui
_ <- win mygui `on` keyPressEvent $ tryEvent $ do _ <- win mygui `on` keyPressEvent $ tryEvent $ do
[Control] <- eventModifier [Control] <- eventModifier
"a" <- eventKeyName "a" <- eventKeyName
@ -145,37 +145,6 @@ makeGUI startFile = do
mainGUI mainGUI
-- |Callback when the "Draw" Button is clicked.
onClickedDrawButton :: MyGUI
-> IO ()
onClickedDrawButton mygui = do
let fcb = fB mygui
filename <- fileChooserGetFilename fcb
case filename of
Just x -> do
ret <- drawDiag' x mygui
case ret of
1 -> showErrorDialog "No valid x/y dimensions!"
2 -> showErrorDialog "No valid Mesh file!"
_ -> return ()
Nothing -> showErrorDialog "No valid Mesh file!"
-- |Callback when the "Save" Button is clicked.
onClickedSaveButton :: MyGUI
-> IO ()
onClickedSaveButton mygui = do
filename <- fileChooserGetFilename (fB mygui)
case filename of
Just x -> do
ret <- saveDiag' x mygui
case ret of
1 -> showErrorDialog "No valid x/y dimensions!"
2 -> showErrorDialog "No valid Mesh file!"
_ -> return ()
Nothing -> showErrorDialog "No valid Mesh file!"
-- |Pops up an error Dialog with the given String. -- |Pops up an error Dialog with the given String.
showErrorDialog :: String -> IO () showErrorDialog :: String -> IO ()
showErrorDialog str = do showErrorDialog str = do
@ -190,17 +159,33 @@ showErrorDialog str = do
-- |Draws a Diagram which is built from a given file to -- |Draws a Diagram which is built from a given file to
-- the gtk DrawingArea. -- the gtk DrawingArea.
drawDiag' :: FilePath drawDiag :: MyGUI
-> MyGUI -> IO ()
-> IO Int drawDiag mygui = do
drawDiag' fp mygui = saveAndDrawDiag fp "" mygui fp <- fileChooserGetFilename (fB mygui)
case fp of
Just x -> do
ret <- saveAndDrawDiag x "" mygui
case ret of
1 -> showErrorDialog "No valid x/y dimensions!"
2 -> showErrorDialog "No valid Mesh file!"
_ -> return ()
Nothing -> showErrorDialog "No valid Mesh file!"
-- |Saves a Diagram which is built from a given file as an SVG. -- |Saves a Diagram which is built from a given file as an SVG.
saveDiag' :: FilePath saveDiag :: MyGUI
-> MyGUI -> IO ()
-> IO Int saveDiag mygui = do
saveDiag' fp mygui = saveAndDrawDiag fp "out.svg" mygui fp <- fileChooserGetFilename (fB mygui)
case fp of
Just x -> do
ret <- saveAndDrawDiag x "out.svg" mygui
case ret of
1 -> showErrorDialog "No valid x/y dimensions!"
2 -> showErrorDialog "No valid Mesh file!"
_ -> return ()
Nothing -> showErrorDialog "No valid Mesh file!"
-- |Draws and saves a Diagram which is built from a given file. -- |Draws and saves a Diagram which is built from a given file.