ui: reg: g key reloads here too

This commit is contained in:
Simon Michael 2015-09-04 09:09:36 -07:00
parent 30cce4188f
commit 4a4fb13a95

View File

@ -7,7 +7,7 @@ module Hledger.UI.RegisterScreen
where where
import Control.Lens ((^.)) import Control.Lens ((^.))
-- import Control.Monad.IO.Class (liftIO) import Control.Monad.IO.Class (liftIO)
import Data.List import Data.List
import Data.List.Split (splitOn) import Data.List.Split (splitOn)
import Data.Monoid import Data.Monoid
@ -94,7 +94,7 @@ drawRegisterScreen AppState{ -- aopts=_uopts@UIOpts{cliopts_=_copts@CliOpts{repo
-- <+> str " and subs" -- <+> str " and subs"
<+> str " (" <+> str " ("
<+> cur <+> cur
<+> str " of " <+> str "/"
<+> total <+> total
<+> str ")" <+> str ")"
cur = str $ case l^.listSelectedL of cur = str $ case l^.listSelectedL of
@ -152,7 +152,8 @@ drawRegisterScreen AppState{ -- aopts=_uopts@UIOpts{cliopts_=_copts@CliOpts{repo
bottomlabel = borderKeysStr [ bottomlabel = borderKeysStr [
-- ("up/down/pgup/pgdown/home/end", "move") -- ("up/down/pgup/pgdown/home/end", "move")
("left", "return to accounts") ("g", "reload")
,("left", "return to accounts")
] ]
render $ defaultLayout toplabel bottomlabel $ renderList l (drawRegisterItem colwidths) render $ defaultLayout toplabel bottomlabel $ renderList l (drawRegisterItem colwidths)
@ -181,10 +182,23 @@ drawRegisterItem (datewidth,descwidth,acctswidth,changewidth,balwidth) selected
| otherwise = id | otherwise = id
handleRegisterScreen :: AppState -> Vty.Event -> EventM (Next AppState) handleRegisterScreen :: AppState -> Vty.Event -> EventM (Next AppState)
handleRegisterScreen st@AppState{aopts=_opts,aScreen=s@RegisterScreen{rsState=is}} e = do handleRegisterScreen st@AppState{
aScreen=s@RegisterScreen{rsState=is}
,aopts=UIOpts{cliopts_=copts}
,ajournal=j
} e = do
d <- liftIO getCurrentDay
let
reload = continue . initRegisterScreen d
case e of case e of
Vty.EvKey Vty.KEsc [] -> halt st Vty.EvKey Vty.KEsc [] -> halt st
Vty.EvKey (Vty.KChar 'q') [] -> halt st Vty.EvKey (Vty.KChar 'q') [] -> halt st
Vty.EvKey (Vty.KChar 'g') [] -> do
(ej, changed) <- liftIO $ journalReloadIfChanged copts j
case (changed, ej) of
(True, Right j') -> reload st{ajournal=j'}
-- (True, Left err) -> continue st{amsg=err} -- XXX report parse error
_ -> continue st
Vty.EvKey (Vty.KLeft) [] -> continue $ popScreen st Vty.EvKey (Vty.KLeft) [] -> continue $ popScreen st
-- Vty.EvKey (Vty.KRight) [] -> error (show curItem) where curItem = listSelectedElement is -- Vty.EvKey (Vty.KRight) [] -> error (show curItem) where curItem = listSelectedElement is
-- fall through to the list's event handler (handles [pg]up/down) -- fall through to the list's event handler (handles [pg]up/down)