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,28 +201,34 @@ 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
-> MyView
-> ( DTZipper DirTreeInfo DirTreeInfo
-> MyGUI -> MyGUI
-> MyView -> MyView
-> IO ()) -- ^ action to carry out
-> IO () -> IO ()
onRow fo mygui myview = do 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
-- |Supposed to be used with `withRow`. Deletes a file or directory.
del :: DTZipper DirTreeInfo DirTreeInfo -> MyGUI -> MyView -> IO ()
del row mygui myview = case row of
dz@(Dir {}, _) -> do dz@(Dir {}, _) -> do
let fp = getFullPath dz let fp = getFullPath dz
cmsg = "Really delete directory \"" ++ fp ++ "\"?" cmsg = "Really delete directory \"" ++ fp ++ "\"?"