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 fp =
whenM (doesFileExist fp) (throw . FileDoesExist
. P.fromAbs $ fp)
whenM (doesFileExist fp) (throwIO . FileDoesExist
. P.fromAbs $ fp)
throwDirDoesExist :: Path Abs -> IO ()
throwDirDoesExist fp =
whenM (doesDirectoryExist fp) (throw . DirDoesExist
. P.fromAbs $ fp)
whenM (doesDirectoryExist fp) (throwIO . DirDoesExist
. P.fromAbs $ fp)
throwFileDoesNotExist :: Path Abs -> IO ()
throwFileDoesNotExist fp =
unlessM (doesFileExist fp) (throw . FileDoesNotExist
. P.fromAbs $ fp)
unlessM (doesFileExist fp) (throwIO . FileDoesNotExist
. P.fromAbs $ fp)
throwDirDoesNotExist :: Path Abs -> IO ()
throwDirDoesNotExist fp =
unlessM (doesDirectoryExist fp) (throw . DirDoesNotExist
. P.fromAbs $ fp)
unlessM (doesDirectoryExist fp) (throwIO . DirDoesNotExist
. P.fromAbs $ fp)
-- |Uses `isSameFile` and throws `SameFile` if it returns True.
@ -176,7 +176,7 @@ throwSameFile :: Path Abs
-> IO ()
throwSameFile 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.
@ -211,8 +211,8 @@ throwDestinationInSource source dest = do
sid <- fmap (\x -> (PF.deviceID x, PF.fileID x))
$ PF.getFileStatus (P.fromAbs source)
when (elem sid dids)
(throw $ DestinationInSource (P.fromAbs dest)
(P.fromAbs source))
(throwIO $ DestinationInSource (P.fromAbs dest)
(P.fromAbs source))
-- |Checks if the given file exists and is not a directory.
@ -256,7 +256,7 @@ canOpenDirectory fp =
throwCantOpenDirectory :: Path Abs -> IO ()
throwCantOpenDirectory 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
-> IO a -- ^ action to try
-> 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
, bracketOnError
, throw
, throwIO
)
import Control.Monad
(
@ -420,7 +420,7 @@ _copyFile sflags dflags from to
then return $ fromIntegral totalsize
else do rsize <- SPB.fdWriteBuf dfd buf size
-- 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)

View File

@ -28,7 +28,7 @@ import Control.Concurrent.STM
)
import Control.Exception
(
throw
throwIO
)
import Control.Monad
(
@ -340,8 +340,8 @@ del items@(_:_) _ _ = withErrorDialog $ do
withConfirmationDialog cmsg
$ forM_ items $ \item -> easyDelete . path $ item
del _ _ _ = withErrorDialog
. throw $ InvalidOperation
"Operation not supported on multiple files"
. throwIO $ InvalidOperation
"Operation not supported on multiple files"
-- |Initializes a file move operation.
@ -355,8 +355,8 @@ moveInit items@(_:_) mygui _ = do
popStatusbar mygui
void $ pushStatusBar mygui sbmsg
moveInit _ _ _ = withErrorDialog
. throw $ InvalidOperation
"No file selected!"
. throwIO $ InvalidOperation
"No file selected!"
-- |Supposed to be used with 'withRows'. Initializes a file copy operation.
copyInit :: [Item] -> MyGUI -> MyView -> IO ()
@ -369,8 +369,8 @@ copyInit items@(_:_) mygui _ = do
popStatusbar mygui
void $ pushStatusBar mygui sbmsg
copyInit _ _ _ = withErrorDialog
. throw $ InvalidOperation
"No file selected!"
. throwIO $ InvalidOperation
"No file selected!"
-- |Finalizes a file operation, such as copy or move.
@ -434,8 +434,8 @@ renameF [item] _ _ = withErrorDialog $ do
HSFM.FileSystem.FileOperations.renameFile (path item)
((P.dirname $ path item) P.</> fn)
renameF _ _ _ = withErrorDialog
. throw $ InvalidOperation
"Operation not supported on multiple files"
. throwIO $ InvalidOperation
"Operation not supported on multiple files"
@ -468,8 +468,8 @@ execute :: [Item] -> MyGUI -> MyView -> IO ()
execute [item] _ _ = withErrorDialog $
void $ executeFile (path item) []
execute _ _ _ = withErrorDialog
. throw $ InvalidOperation
"Operation not supported on multiple files"
. throwIO $ InvalidOperation
"Operation not supported on multiple files"
-- |Supposed to be used with 'withRows'. Opens a file or directory.
@ -485,8 +485,8 @@ open [item] mygui myview = withErrorDialog $
open (FileLikeList fs) _ _ = withErrorDialog $
forM_ fs $ \f -> void $ openFile . path $ f
open _ _ _ = withErrorDialog
. throw $ InvalidOperation
"Operation not supported on multiple files"
. throwIO $ InvalidOperation
"Operation not supported on multiple files"
-- |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
(
displayException
, throw
, throwIO
, IOException
, catches
, Handler(..)
@ -153,7 +153,7 @@ fileCollisionDialog t = do
forM mfn $ \fn -> do
pfn <- P.parseFn (P.userStringToFP fn)
return $ Rename pfn
_ -> throw UnknownDialogButton
_ -> throwIO UnknownDialogButton
renameDialog :: ByteString -> IO (Maybe FCollisonMode)
@ -178,7 +178,7 @@ renameDialog t = do
forM mfn $ \fn -> do
pfn <- P.parseFn (P.userStringToFP fn)
return $ Rename pfn
_ -> throw UnknownDialogButton
_ -> throwIO UnknownDialogButton
-- |Shows the about dialog from the help menu.
@ -250,7 +250,7 @@ textInputDialog title inittext = do
-- TODO: make this more safe
ResponseUser 0 -> Just <$> entryGetText entry
ResponseUser 1 -> return Nothing
_ -> throw UnknownDialogButton
_ -> throwIO UnknownDialogButton
widgetDestroy chooserDialog
return ret