diff --git a/hledger-ui/Hledger/UI/AccountsScreen.hs b/hledger-ui/Hledger/UI/AccountsScreen.hs index c8655cd08..0522855b3 100644 --- a/hledger-ui/Hledger/UI/AccountsScreen.hs +++ b/hledger-ui/Hledger/UI/AccountsScreen.hs @@ -231,7 +231,7 @@ asHandleNormalMode (ALS scons ass) ev = do -- XXX be sure we don't leave unconsumed app events piling up -- A data file has changed (or the user has pressed g): reload. e | e `elem` [AppEvent FileChange, VtyEvent (EvKey (KChar 'g') [])] -> - liftIO (uiReload copts d ui) >>= put' + uiReload copts d ui >>= put' -- The date has changed (and we are viewing a standard period which contained the old date): -- adjust the viewed period and regenerate, just in case needed. diff --git a/hledger-ui/Hledger/UI/ErrorScreen.hs b/hledger-ui/Hledger/UI/ErrorScreen.hs index f72b25404..005a6a3c9 100644 --- a/hledger-ui/Hledger/UI/ErrorScreen.hs +++ b/hledger-ui/Hledger/UI/ErrorScreen.hs @@ -94,7 +94,7 @@ esHandle ev = do Right (f',l,c) -> (Just (l, Just c),f') Left _ -> (endPosition, journalFilePath j) e | e `elem` [VtyEvent (EvKey (KChar 'g') []), AppEvent FileChange] -> - liftIO (uiReload copts d (popScreen ui)) >>= put' . uiCheckBalanceAssertions d + uiReload copts d (popScreen ui) >>= put' . uiCheckBalanceAssertions d -- (ej, _) <- liftIO $ journalReloadIfChanged copts d j -- case ej of -- Left err -> continue ui{aScreen=s{esError=err}} -- show latest parse error @@ -142,8 +142,8 @@ hledgerparseerrorpositionp = do -- Like at hledger-ui startup, --forecast is always enabled. -- A forecast period specified in the provided opts, or at startup, is preserved. -- -uiReload :: CliOpts -> Day -> UIState -> IO UIState -uiReload copts d ui = do +uiReload :: CliOpts -> Day -> UIState -> EventM Name UIState UIState +uiReload copts d ui = liftIO $ do ej <- let copts' = enableForecast (astartupopts ui) copts in runExceptT $ journalTransform copts' <$> journalReload copts' @@ -165,9 +165,9 @@ uiReload copts d ui = do -- RegisterScreen _ _ _ _ _ _ -- TransactionScreen _ _ _ _ _ _ --- | Like uiReload, but does not re-parse the journal if the file(s) --- have not changed since last loaded. Always regenerates the screens though, --- since the provided options or today-date may have changed. +-- | Like uiReload, except it skips re-reading the journal if its file(s) have not changed +-- since it was last loaded. The up app state is always updated, since the options or today-date may have changed. +-- Also, this one runs in IO, suitable for suspendAndResume. uiReloadIfFileChanged :: CliOpts -> Day -> Journal -> UIState -> IO UIState uiReloadIfFileChanged copts d j ui = do let copts' = enableForecast (astartupopts ui) copts diff --git a/hledger-ui/Hledger/UI/MenuScreen.hs b/hledger-ui/Hledger/UI/MenuScreen.hs index fb5d36486..7291dcb50 100644 --- a/hledger-ui/Hledger/UI/MenuScreen.hs +++ b/hledger-ui/Hledger/UI/MenuScreen.hs @@ -155,8 +155,7 @@ msHandle ev = do put' $ regenerateScreens j d $ setReportPeriod (DayPeriod d) ui where p = reportPeriod ui - e | e `elem` [VtyEvent (EvKey (KChar 'g') []), AppEvent FileChange] -> - liftIO (uiReload copts d ui) >>= put' + e | e `elem` [VtyEvent (EvKey (KChar 'g') []), AppEvent FileChange] -> uiReload copts d ui >>= put' VtyEvent (EvKey (KChar 'I') []) -> put' $ uiCheckBalanceAssertions d (toggleIgnoreBalanceAssertions ui) VtyEvent (EvKey (KChar 'a') []) -> suspendAndResume $ clearScreen >> setCursorPosition 0 0 >> add (cliOptsDropArgs copts) j >> uiReloadIfFileChanged copts d j ui VtyEvent (EvKey (KChar 'A') []) -> suspendAndResume $ void (runIadd (journalFilePath j)) >> uiReloadIfFileChanged copts d j ui diff --git a/hledger-ui/Hledger/UI/RegisterScreen.hs b/hledger-ui/Hledger/UI/RegisterScreen.hs index 56a46ec1e..74c01b8b6 100644 --- a/hledger-ui/Hledger/UI/RegisterScreen.hs +++ b/hledger-ui/Hledger/UI/RegisterScreen.hs @@ -245,8 +245,7 @@ rsHandle ev = do where p = reportPeriod ui - e | e `elem` [AppEvent FileChange, VtyEvent (EvKey (KChar 'g') [])] -> - liftIO (uiReload copts d ui) >>= put' + e | e `elem` [AppEvent FileChange, VtyEvent (EvKey (KChar 'g') [])] -> uiReload copts d ui >>= put' VtyEvent (EvKey (KChar 'I') []) -> put' $ uiCheckBalanceAssertions d (toggleIgnoreBalanceAssertions ui) VtyEvent (EvKey (KChar 'a') []) -> suspendAndResume $ clearScreen >> setCursorPosition 0 0 >> add (cliOptsDropArgs copts) j >> uiReloadIfFileChanged copts d j ui diff --git a/hledger-ui/Hledger/UI/TransactionScreen.hs b/hledger-ui/Hledger/UI/TransactionScreen.hs index b875308f6..31fce4229 100644 --- a/hledger-ui/Hledger/UI/TransactionScreen.hs +++ b/hledger-ui/Hledger/UI/TransactionScreen.hs @@ -144,7 +144,7 @@ tsHandle ev = do e | e `elem` [VtyEvent (EvKey (KChar 'g') []), AppEvent FileChange] -> do -- To update all state: exit to register screen, regenerate screens, re-enter transaction screen. -- Anywhere else here that we need to be this thorough ? - put' =<< liftIO (popScreen ui & uiReload copts d) + uiReload copts d (popScreen ui) >>= put' rsHandle (VtyEvent (EvKey KEnter [])) -- -- for debugging; leaving these here because they were hard to find