use guards instead of if-else
This commit is contained in:
parent
233d7a6416
commit
99515f4520
1 changed files with 10 additions and 8 deletions
|
|
@ -10,7 +10,7 @@ import Control.Concurrent
|
|||
import GI.Gtk
|
||||
import GI.Gio hiding (Application)
|
||||
import qualified GI.Gtk as GTK
|
||||
import Control.Monad (when, void, mzero)
|
||||
import Control.Monad (when, void, mzero, guard)
|
||||
import Data.Foldable (for_)
|
||||
import System.Directory (doesDirectoryExist, listDirectory)
|
||||
import System.FilePath ((</>))
|
||||
|
|
@ -19,13 +19,15 @@ import Control.Monad.Trans.Maybe (MaybeT(..), runMaybeT)
|
|||
|
||||
|
||||
selectFolder :: FileDialog -> ApplicationWindow -> (Maybe String -> IO ()) -> IO ()
|
||||
selectFolder fd w k = fileDialogSelectFolder fd (Just w) (Nothing :: Maybe Cancellable) $ Just $ \_ r -> do
|
||||
mbPath <- runMaybeT $ do
|
||||
f <- MaybeT $ handleDialogError (\_ _ -> return Nothing) (fileDialogSelectFolderFinish fd r)
|
||||
p <- MaybeT $ fileGetPath f
|
||||
e <- liftIO $ doesDirectoryExist p
|
||||
if e then return p else mzero
|
||||
k mbPath
|
||||
selectFolder fd w k =
|
||||
fileDialogSelectFolder fd (Just w) (Nothing :: Maybe Cancellable) $ Just $ \_ r -> do
|
||||
mbPath <- runMaybeT $ do
|
||||
f <- MaybeT $ handleDialogError (\_ _ -> pure Nothing)
|
||||
(fileDialogSelectFolderFinish fd r)
|
||||
p <- MaybeT $ fileGetPath f
|
||||
guard =<< liftIO (doesDirectoryExist p)
|
||||
pure p
|
||||
k mbPath
|
||||
|
||||
main :: IO ()
|
||||
main = do
|
||||
|
|
|
|||
Loading…
Reference in a new issue