From dc457eb168470946f15c8c0a98ea5e824d61f580 Mon Sep 17 00:00:00 2001 From: Julian Ospald Date: Mon, 9 May 2016 11:34:02 +0200 Subject: [PATCH] LIB/GTK: use throwIO instead of throw --- src/HSFM/FileSystem/Errors.hs | 26 +++++++++++++------------- src/HSFM/FileSystem/FileOperations.hs | 4 ++-- src/HSFM/GUI/Gtk/Callbacks.hs | 26 +++++++++++++------------- src/HSFM/GUI/Gtk/Dialogs.hs | 8 ++++---- 4 files changed, 32 insertions(+), 32 deletions(-) diff --git a/src/HSFM/FileSystem/Errors.hs b/src/HSFM/FileSystem/Errors.hs index 9b4680f..84f1feb 100644 --- a/src/HSFM/FileSystem/Errors.hs +++ b/src/HSFM/FileSystem/Errors.hs @@ -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) diff --git a/src/HSFM/FileSystem/FileOperations.hs b/src/HSFM/FileSystem/FileOperations.hs index 87fc25a..66a6462 100644 --- a/src/HSFM/FileSystem/FileOperations.hs +++ b/src/HSFM/FileSystem/FileOperations.hs @@ -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) diff --git a/src/HSFM/GUI/Gtk/Callbacks.hs b/src/HSFM/GUI/Gtk/Callbacks.hs index d9a8321..bcafa3a 100644 --- a/src/HSFM/GUI/Gtk/Callbacks.hs +++ b/src/HSFM/GUI/Gtk/Callbacks.hs @@ -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. diff --git a/src/HSFM/GUI/Gtk/Dialogs.hs b/src/HSFM/GUI/Gtk/Dialogs.hs index 4a10cba..aa2adc3 100644 --- a/src/HSFM/GUI/Gtk/Dialogs.hs +++ b/src/HSFM/GUI/Gtk/Dialogs.hs @@ -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