LIB/GTK: use throwIO instead of throw

This commit is contained in:
Julian Ospald 2016-05-09 11:34:02 +02:00
parent 173c4cbddd
commit dc457eb168
No known key found for this signature in database
GPG Key ID: 511B62C09D50CD28
4 changed files with 32 additions and 32 deletions

View File

@ -148,26 +148,26 @@ isDirDoesExist _ = False
throwFileDoesExist :: Path Abs -> IO () throwFileDoesExist :: Path Abs -> IO ()
throwFileDoesExist fp = throwFileDoesExist fp =
whenM (doesFileExist fp) (throw . FileDoesExist whenM (doesFileExist fp) (throwIO . FileDoesExist
. P.fromAbs $ fp) . P.fromAbs $ fp)
throwDirDoesExist :: Path Abs -> IO () throwDirDoesExist :: Path Abs -> IO ()
throwDirDoesExist fp = throwDirDoesExist fp =
whenM (doesDirectoryExist fp) (throw . DirDoesExist whenM (doesDirectoryExist fp) (throwIO . DirDoesExist
. P.fromAbs $ fp) . P.fromAbs $ fp)
throwFileDoesNotExist :: Path Abs -> IO () throwFileDoesNotExist :: Path Abs -> IO ()
throwFileDoesNotExist fp = throwFileDoesNotExist fp =
unlessM (doesFileExist fp) (throw . FileDoesNotExist unlessM (doesFileExist fp) (throwIO . FileDoesNotExist
. P.fromAbs $ fp) . P.fromAbs $ fp)
throwDirDoesNotExist :: Path Abs -> IO () throwDirDoesNotExist :: Path Abs -> IO ()
throwDirDoesNotExist fp = throwDirDoesNotExist fp =
unlessM (doesDirectoryExist fp) (throw . DirDoesNotExist unlessM (doesDirectoryExist fp) (throwIO . DirDoesNotExist
. P.fromAbs $ fp) . P.fromAbs $ fp)
-- |Uses `isSameFile` and throws `SameFile` if it returns True. -- |Uses `isSameFile` and throws `SameFile` if it returns True.
@ -176,7 +176,7 @@ throwSameFile :: Path Abs
-> IO () -> IO ()
throwSameFile fp1 fp2 = throwSameFile fp1 fp2 =
whenM (sameFile fp1 fp2) whenM (sameFile fp1 fp2)
(throw $ SameFile (P.fromAbs fp1) (P.fromAbs fp2)) (throwIO $ SameFile (P.fromAbs fp1) (P.fromAbs fp2))
-- |Check if the files are the same by examining device and file id. -- |Check if the files are the same by examining device and file id.
@ -211,8 +211,8 @@ throwDestinationInSource source dest = do
sid <- fmap (\x -> (PF.deviceID x, PF.fileID x)) sid <- fmap (\x -> (PF.deviceID x, PF.fileID x))
$ PF.getFileStatus (P.fromAbs source) $ PF.getFileStatus (P.fromAbs source)
when (elem sid dids) when (elem sid dids)
(throw $ DestinationInSource (P.fromAbs dest) (throwIO $ DestinationInSource (P.fromAbs dest)
(P.fromAbs source)) (P.fromAbs source))
-- |Checks if the given file exists and is not a directory. -- |Checks if the given file exists and is not a directory.
@ -256,7 +256,7 @@ canOpenDirectory fp =
throwCantOpenDirectory :: Path Abs -> IO () throwCantOpenDirectory :: Path Abs -> IO ()
throwCantOpenDirectory fp = throwCantOpenDirectory fp =
unlessM (canOpenDirectory fp) unlessM (canOpenDirectory fp)
(throw . Can'tOpenDirectory . P.fromAbs $ fp) (throwIO . Can'tOpenDirectory . P.fromAbs $ fp)
@ -289,7 +289,7 @@ rethrowErrnoAs :: Exception e
-> e -- ^ rethrow as if errno matches -> e -- ^ rethrow as if errno matches
-> IO a -- ^ action to try -> IO a -- ^ action to try
-> IO a -> IO a
rethrowErrnoAs en fmex action = catchErrno en action (throw fmex) rethrowErrnoAs en fmex action = catchErrno en action (throwIO fmex)

View File

@ -46,7 +46,7 @@ import Control.Exception
( (
bracket bracket
, bracketOnError , bracketOnError
, throw , throwIO
) )
import Control.Monad import Control.Monad
( (
@ -420,7 +420,7 @@ _copyFile sflags dflags from to
then return $ fromIntegral totalsize then return $ fromIntegral totalsize
else do rsize <- SPB.fdWriteBuf dfd buf size else do rsize <- SPB.fdWriteBuf dfd buf size
-- TODO: switch to IOError? -- TODO: switch to IOError?
when (rsize /= size) (throw . CopyFailed $ "wrong size!") when (rsize /= size) (throwIO . CopyFailed $ "wrong size!")
write' sfd dfd buf (totalsize + fromIntegral size) write' sfd dfd buf (totalsize + fromIntegral size)

View File

@ -28,7 +28,7 @@ import Control.Concurrent.STM
) )
import Control.Exception import Control.Exception
( (
throw throwIO
) )
import Control.Monad import Control.Monad
( (
@ -340,8 +340,8 @@ del items@(_:_) _ _ = withErrorDialog $ do
withConfirmationDialog cmsg withConfirmationDialog cmsg
$ forM_ items $ \item -> easyDelete . path $ item $ forM_ items $ \item -> easyDelete . path $ item
del _ _ _ = withErrorDialog del _ _ _ = withErrorDialog
. throw $ InvalidOperation . throwIO $ InvalidOperation
"Operation not supported on multiple files" "Operation not supported on multiple files"
-- |Initializes a file move operation. -- |Initializes a file move operation.
@ -355,8 +355,8 @@ moveInit items@(_:_) mygui _ = do
popStatusbar mygui popStatusbar mygui
void $ pushStatusBar mygui sbmsg void $ pushStatusBar mygui sbmsg
moveInit _ _ _ = withErrorDialog moveInit _ _ _ = withErrorDialog
. throw $ InvalidOperation . throwIO $ InvalidOperation
"No file selected!" "No file selected!"
-- |Supposed to be used with 'withRows'. Initializes a file copy operation. -- |Supposed to be used with 'withRows'. Initializes a file copy operation.
copyInit :: [Item] -> MyGUI -> MyView -> IO () copyInit :: [Item] -> MyGUI -> MyView -> IO ()
@ -369,8 +369,8 @@ copyInit items@(_:_) mygui _ = do
popStatusbar mygui popStatusbar mygui
void $ pushStatusBar mygui sbmsg void $ pushStatusBar mygui sbmsg
copyInit _ _ _ = withErrorDialog copyInit _ _ _ = withErrorDialog
. throw $ InvalidOperation . throwIO $ InvalidOperation
"No file selected!" "No file selected!"
-- |Finalizes a file operation, such as copy or move. -- |Finalizes a file operation, such as copy or move.
@ -434,8 +434,8 @@ renameF [item] _ _ = withErrorDialog $ do
HSFM.FileSystem.FileOperations.renameFile (path item) HSFM.FileSystem.FileOperations.renameFile (path item)
((P.dirname $ path item) P.</> fn) ((P.dirname $ path item) P.</> fn)
renameF _ _ _ = withErrorDialog renameF _ _ _ = withErrorDialog
. throw $ InvalidOperation . throwIO $ InvalidOperation
"Operation not supported on multiple files" "Operation not supported on multiple files"
@ -468,8 +468,8 @@ execute :: [Item] -> MyGUI -> MyView -> IO ()
execute [item] _ _ = withErrorDialog $ execute [item] _ _ = withErrorDialog $
void $ executeFile (path item) [] void $ executeFile (path item) []
execute _ _ _ = withErrorDialog execute _ _ _ = withErrorDialog
. throw $ InvalidOperation . throwIO $ InvalidOperation
"Operation not supported on multiple files" "Operation not supported on multiple files"
-- |Supposed to be used with 'withRows'. Opens a file or directory. -- |Supposed to be used with 'withRows'. Opens a file or directory.
@ -485,8 +485,8 @@ open [item] mygui myview = withErrorDialog $
open (FileLikeList fs) _ _ = withErrorDialog $ open (FileLikeList fs) _ _ = withErrorDialog $
forM_ fs $ \f -> void $ openFile . path $ f forM_ fs $ \f -> void $ openFile . path $ f
open _ _ _ = withErrorDialog open _ _ _ = withErrorDialog
. throw $ InvalidOperation . throwIO $ InvalidOperation
"Operation not supported on multiple files" "Operation not supported on multiple files"
-- |Go up one directory and visualize it in the treeView. -- |Go up one directory and visualize it in the treeView.

View File

@ -24,7 +24,7 @@ module HSFM.GUI.Gtk.Dialogs where
import Control.Exception import Control.Exception
( (
displayException displayException
, throw , throwIO
, IOException , IOException
, catches , catches
, Handler(..) , Handler(..)
@ -153,7 +153,7 @@ fileCollisionDialog t = do
forM mfn $ \fn -> do forM mfn $ \fn -> do
pfn <- P.parseFn (P.userStringToFP fn) pfn <- P.parseFn (P.userStringToFP fn)
return $ Rename pfn return $ Rename pfn
_ -> throw UnknownDialogButton _ -> throwIO UnknownDialogButton
renameDialog :: ByteString -> IO (Maybe FCollisonMode) renameDialog :: ByteString -> IO (Maybe FCollisonMode)
@ -178,7 +178,7 @@ renameDialog t = do
forM mfn $ \fn -> do forM mfn $ \fn -> do
pfn <- P.parseFn (P.userStringToFP fn) pfn <- P.parseFn (P.userStringToFP fn)
return $ Rename pfn return $ Rename pfn
_ -> throw UnknownDialogButton _ -> throwIO UnknownDialogButton
-- |Shows the about dialog from the help menu. -- |Shows the about dialog from the help menu.
@ -250,7 +250,7 @@ textInputDialog title inittext = do
-- TODO: make this more safe -- TODO: make this more safe
ResponseUser 0 -> Just <$> entryGetText entry ResponseUser 0 -> Just <$> entryGetText entry
ResponseUser 1 -> return Nothing ResponseUser 1 -> return Nothing
_ -> throw UnknownDialogButton _ -> throwIO UnknownDialogButton
widgetDestroy chooserDialog widgetDestroy chooserDialog
return ret return ret