diff --git a/hledger-ui/Hledger/UI/ErrorScreen.hs b/hledger-ui/Hledger/UI/ErrorScreen.hs index 9bebe6b10..f72b25404 100644 --- a/hledger-ui/Hledger/UI/ErrorScreen.hs +++ b/hledger-ui/Hledger/UI/ErrorScreen.hs @@ -145,7 +145,7 @@ hledgerparseerrorpositionp = do uiReload :: CliOpts -> Day -> UIState -> IO UIState uiReload copts d ui = do ej <- - let copts' = enableForecastPreservingPeriod ui copts + let copts' = enableForecast (astartupopts ui) copts in runExceptT $ journalTransform copts' <$> journalReload copts' -- dbg1IO "uiReload before reload" (map tdescription $ jtxns $ ajournal ui) return $ case ej of @@ -170,7 +170,7 @@ uiReload copts d ui = do -- since the provided options or today-date may have changed. uiReloadIfFileChanged :: CliOpts -> Day -> Journal -> UIState -> IO UIState uiReloadIfFileChanged copts d j ui = do - let copts' = enableForecastPreservingPeriod ui copts + let copts' = enableForecast (astartupopts ui) copts ej <- runExceptT $ journalReloadIfChanged copts' d j return $ case ej of Right (j', _) -> regenerateScreens j' d ui diff --git a/hledger-ui/Hledger/UI/UIState.hs b/hledger-ui/Hledger/UI/UIState.hs index a67309b4c..0237e353e 100644 --- a/hledger-ui/Hledger/UI/UIState.hs +++ b/hledger-ui/Hledger/UI/UIState.hs @@ -35,7 +35,7 @@ module Hledger.UI.UIState ,resetDepth ,popScreen ,pushScreen -,enableForecastPreservingPeriod +,enableForecast ,resetFilter ,resetScreens ,regenerateScreens @@ -202,20 +202,19 @@ toggleForecast _d ui = set forecast newForecast ui where newForecast = case ui^.forecast of Just _ -> Nothing - Nothing -> enableForecastPreservingPeriod ui (ui^.cliOpts) ^. forecast + Nothing -> enableForecast (astartupopts ui) (ui^.cliOpts) ^. forecast --- | Ensure this CliOpts enables forecasted transactions. --- If a forecast period was specified in the old CliOpts, --- or in the provided UIState's startup options, --- it is preserved. -enableForecastPreservingPeriod :: UIState -> CliOpts -> CliOpts -enableForecastPreservingPeriod ui copts = set forecast mforecast copts +-- | Enable forecasting in this CliOpts. +-- If it previously specified a forecast period, or else if the given ui startup options did, +-- preserve that as the forecast period. +enableForecast :: UIOpts -> CliOpts -> CliOpts +enableForecast startopts currentopts = set forecast mforecast currentopts where - mforecast = asum [mprovidedforecastperiod, mstartupforecastperiod, mdefaultforecastperiod] + mforecast = asum [mcurrentforecastperiod, mstartupforecastperiod, mdefaultforecastperiod] where - mprovidedforecastperiod = copts ^. forecast - mstartupforecastperiod = astartupopts ui ^. forecast - mdefaultforecastperiod = Just nulldatespan + mcurrentforecastperiod = currentopts ^. forecast + mstartupforecastperiod = startopts ^. forecast + mdefaultforecastperiod = Just nulldatespan -- | Toggle between showing all and showing only real (non-virtual) items. toggleReal :: UIState -> UIState