imp: ui: Use new DepthSpec in hledger-ui.
The regular expression depths are ignored, and only the flat depths are used.
This commit is contained in:
parent
74f0f37fb3
commit
7168f7efc4
@ -130,7 +130,7 @@ asDrawHelper UIState{aScreen=scr, aopts=uopts, ajournal=j, aMode=mode} ropts scr
|
||||
,uiShowStatus copts $ statuses_ ropts
|
||||
,if real_ ropts then ["real"] else []
|
||||
]
|
||||
mdepth = depth_ ropts
|
||||
mdepth = dsFlatDepth $ depth_ ropts
|
||||
curidx = case ass ^. assList . listSelectedL of
|
||||
Nothing -> "-"
|
||||
Just i -> show (i + 1)
|
||||
|
||||
@ -256,7 +256,7 @@ rsUpdate uopts d j rss@RSS{_rssAccount, _rssForceInclusive, _rssList=oldlist} =
|
||||
-- adjust the report options and report spec, carefully as usual to avoid screwups (#1523)
|
||||
ropts' = ropts {
|
||||
-- ignore any depth limit, as in postingsReport; allows register's total to match accounts screen
|
||||
depth_=Nothing
|
||||
depth_=mempty
|
||||
-- do not strip prices so we can toggle costs within the ui
|
||||
, show_costs_=True
|
||||
-- XXX aregister also has this, needed ?
|
||||
|
||||
@ -281,7 +281,7 @@ resetFilter = set querystringNoUpdate [] . set realNoUpdate False . set statuses
|
||||
-- resetOpts ui@UIState{astartupopts} = ui{aopts=astartupopts}
|
||||
|
||||
resetDepth :: UIState -> UIState
|
||||
resetDepth = updateReportDepth (const Nothing)
|
||||
resetDepth = updateReportDepth (const mempty)
|
||||
|
||||
-- | Get the maximum account depth in the current journal.
|
||||
maxDepth :: UIState -> Int
|
||||
@ -292,34 +292,38 @@ maxDepth UIState{ajournal=j} = getMax . foldMap (Max . accountNameLevel) $ journ
|
||||
decDepth :: UIState -> UIState
|
||||
decDepth ui = updateReportDepth dec ui
|
||||
where
|
||||
dec (Just d) = Just $ max 0 (d-1)
|
||||
dec Nothing = Just $ maxDepth ui - 1
|
||||
dec (DepthSpec (Just d) _) = DepthSpec (Just $ max 0 (d-1)) []
|
||||
dec (DepthSpec Nothing _) = DepthSpec (Just $ maxDepth ui - 1) []
|
||||
|
||||
-- | Increment the current depth limit. If this makes it equal to the
|
||||
-- the maximum account depth, remove the depth limit.
|
||||
incDepth :: UIState -> UIState
|
||||
incDepth = updateReportDepth (fmap succ)
|
||||
incDepth = updateReportDepth inc
|
||||
where
|
||||
inc (DepthSpec Nothing _) = DepthSpec Nothing []
|
||||
inc (DepthSpec (Just d) _) = DepthSpec (Just $ d + 1) []
|
||||
|
||||
-- | Set the current depth limit to the specified depth, or remove the depth limit.
|
||||
-- Also remove the depth limit if the specified depth is greater than the current
|
||||
-- maximum account depth. If the specified depth is negative, reset the depth limit
|
||||
-- to whatever was specified at uiartup.
|
||||
setDepth :: Maybe Int -> UIState -> UIState
|
||||
setDepth mdepth = updateReportDepth (const mdepth)
|
||||
setDepth mdepth = updateReportDepth (const $ DepthSpec mdepth [])
|
||||
|
||||
getDepth :: UIState -> Maybe Int
|
||||
getDepth = (^.depth)
|
||||
getDepth = dsFlatDepth . (^.depth)
|
||||
|
||||
-- | Update report depth by a applying a function. If asked to set a depth less
|
||||
-- than zero, it will leave it unchanged.
|
||||
updateReportDepth :: (Maybe Int -> Maybe Int) -> UIState -> UIState
|
||||
updateReportDepth :: (DepthSpec -> DepthSpec) -> UIState -> UIState
|
||||
updateReportDepth updateDepth ui = over reportSpec update ui
|
||||
where
|
||||
update = fromRight (error "updateReportDepth: updating depth should not result in an error") -- PARTIAL:
|
||||
. updateReportSpecWith (\ropts -> ropts{depth_=updateDepth (depth_ ropts) >>= clipDepth ropts})
|
||||
clipDepth ropts d | d < 0 = depth_ ropts
|
||||
| d >= maxDepth ui = Nothing
|
||||
| otherwise = Just d
|
||||
. updateReportSpecWith (\ropts -> ropts{depth_=clipDepth ropts $ updateDepth (depth_ ropts)})
|
||||
clipDepth _ (DepthSpec Nothing _) = mempty
|
||||
clipDepth ropts ds@(DepthSpec (Just d) _) | d < 0 = depth_ ropts
|
||||
| d >= maxDepth ui = mempty
|
||||
| otherwise = ds
|
||||
|
||||
-- | Open the minibuffer, setting its content to the current query with the cursor at the end.
|
||||
showMinibuffer :: T.Text -> Maybe String -> UIState -> UIState
|
||||
|
||||
Loading…
Reference in New Issue
Block a user