From c95e003228237e8a01ecb513b9a1cd7f04cbeb33 Mon Sep 17 00:00:00 2001 From: hasufell Date: Thu, 2 Oct 2014 20:59:27 +0200 Subject: [PATCH] Make API suck less --- Gtk.hs | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/Gtk.hs b/Gtk.hs index 7307b0b..b632bb7 100644 --- a/Gtk.hs +++ b/Gtk.hs @@ -79,11 +79,12 @@ onClickedDrawButton fcb da scale' = do filename <- fileChooserGetFilename fcb case filename of Just x -> do - cId <- onExpose da (\x' -> do - drawDiag' x da scale' - return True) - drawDiag' x da scale' + cId <- onExpose da (\x' -> drawDiag' x da scale') _ <- on fcb fileActivated (signalDisconnect cId) + ret <- drawDiag' x da scale' + case ret of + True -> return () + False -> showErrorDialog "No valid Mesh file!" Nothing -> do showErrorDialog "No valid Mesh file!" @@ -95,7 +96,10 @@ onClickedSaveButton fcb = do filename <- fileChooserGetFilename fcb case filename of Just x -> do - saveDiag' x + ret <- saveDiag' x + case ret of + True -> return () + False -> showErrorDialog "No valid Mesh file!" Nothing -> do showErrorDialog "No valid Mesh file!" @@ -114,12 +118,11 @@ showErrorDialog str = do -- |Draws a Diagram which is built from a given file to -- the gtk DrawingArea. --- Prints an error dialog if no valid mesh file is found. drawDiag' :: (WidgetClass widget, RangeClass scale) => FilePath -> widget -> scale - -> IO () + -> IO (Bool) drawDiag' fp da scale' = case cmpExt "obj" fp of True -> do @@ -131,15 +134,16 @@ drawDiag' fp da scale' = (CairoOptions "" (Width 600) SVG False) (diagFromString (MkProp scaleVal) mesh) renderWithDrawable dw r - False -> showErrorDialog "No valid Mesh file!" + return True + False -> return False -- |Saves a Diagram which is built from a given file as an SVG. --- Prints an error dialog if no valid mesh file is found. -saveDiag' :: FilePath -> IO () +saveDiag' :: FilePath -> IO (Bool) saveDiag' fp = case cmpExt "obj" fp of True -> do mesh <- readFile fp renderCairo "out.svg" (Width 600) (diagFromString (MkProp 2) mesh) - False -> showErrorDialog "No valid Mesh file!" + return True + False -> return False