GTK: Refactor onRow

We name it withRow now and move the specific functions out of it.
This commit is contained in:
Julian Ospald 2015-12-17 19:41:45 +01:00
parent 8d9a6d7fb0
commit d5c6eef49e
No known key found for this signature in database
GPG Key ID: 220CD1C5BDEED020

View File

@ -165,8 +165,8 @@ setCallbacks mygui myview = do
liftIO $ upDir mygui myview liftIO $ upDir mygui myview
_ <- treeView mygui `on` keyPressEvent $ tryEvent $ do _ <- treeView mygui `on` keyPressEvent $ tryEvent $ do
"Delete" <- fmap glibToString eventKeyName "Delete" <- fmap glibToString eventKeyName
liftIO $ onRow Delete mygui myview liftIO $ withRow mygui myview del
_ <- treeView mygui `on` rowActivated $ (\_ _ -> onRow Open mygui myview) _ <- treeView mygui `on` rowActivated $ (\_ _ -> withRow mygui myview open)
_ <- menubarFileQuit mygui `on` menuItemActivated $ mainQuit _ <- menubarFileQuit mygui `on` menuItemActivated $ mainQuit
_ <- urlBar mygui `on` entryActivated $ urlGoTo mygui myview _ <- urlBar mygui `on` entryActivated $ urlGoTo mygui myview
return () return ()
@ -201,40 +201,46 @@ getSelectedRow mygui myview = do
treeModelGetRow rawModel' cIter treeModelGetRow rawModel' cIter
-- |Callback for file operations on a row, e.g. open, delete, etc. -- |Carry out an action on the currently selected row.
-- --
-- This might update the TVar `rawModel`. -- If there is no row selected, does nothing.
onRow :: FileOperation withRow :: MyGUI
-> MyGUI -> MyView
-> MyView -> ( DTZipper DirTreeInfo DirTreeInfo
-> IO () -> MyGUI
onRow fo mygui myview = do -> MyView
-> IO ()) -- ^ action to carry out
-> IO ()
withRow mygui myview io = do
mrow <- getSelectedRow mygui myview mrow <- getSelectedRow mygui myview
for_ mrow $ \row -> for_ mrow $ \row -> io row mygui myview
case fo of
Open -> open row
Delete -> del row -- |Supposed to be used with `withRow`. Opens a file or directory.
_ -> return () open :: DTZipper DirTreeInfo DirTreeInfo -> MyGUI -> MyView -> IO ()
where open row mygui myview = case row of
open row = case row of (Dir {}, _) ->
(Dir {}, _) -> refreshTreeView' mygui myview row
refreshTreeView' mygui myview row dz@(File {}, _) ->
dz@(File {}, _) -> withErrorDialog $ openFile (getFullPath dz)
withErrorDialog $ openFile (getFullPath dz) _ -> return ()
_ -> return ()
del row = case row of
dz@(Dir {}, _) -> do -- |Supposed to be used with `withRow`. Deletes a file or directory.
let fp = getFullPath dz del :: DTZipper DirTreeInfo DirTreeInfo -> MyGUI -> MyView -> IO ()
cmsg = "Really delete directory \"" ++ fp ++ "\"?" del row mygui myview = case row of
withConfirmationDialog cmsg dz@(Dir {}, _) -> do
$ withErrorDialog (deleteDir fp let fp = getFullPath dz
>> refreshTreeView mygui myview Nothing) cmsg = "Really delete directory \"" ++ fp ++ "\"?"
dz@(File {}, _) -> do withConfirmationDialog cmsg
let fp = getFullPath dz $ withErrorDialog (deleteDir fp
cmsg = "Really delete file \"" ++ fp ++ "\"?" >> refreshTreeView mygui myview Nothing)
withConfirmationDialog cmsg dz@(File {}, _) -> do
$ withErrorDialog (deleteFile fp let fp = getFullPath dz
>> refreshTreeView mygui myview Nothing) cmsg = "Really delete file \"" ++ fp ++ "\"?"
withConfirmationDialog cmsg
$ withErrorDialog (deleteFile fp
>> refreshTreeView mygui myview Nothing)
-- |Go up one directory and visualize it in the treeView. -- |Go up one directory and visualize it in the treeView.