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
|
,uiShowStatus copts $ statuses_ ropts
|
||||||
,if real_ ropts then ["real"] else []
|
,if real_ ropts then ["real"] else []
|
||||||
]
|
]
|
||||||
mdepth = depth_ ropts
|
mdepth = dsFlatDepth $ depth_ ropts
|
||||||
curidx = case ass ^. assList . listSelectedL of
|
curidx = case ass ^. assList . listSelectedL of
|
||||||
Nothing -> "-"
|
Nothing -> "-"
|
||||||
Just i -> show (i + 1)
|
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)
|
-- adjust the report options and report spec, carefully as usual to avoid screwups (#1523)
|
||||||
ropts' = ropts {
|
ropts' = ropts {
|
||||||
-- ignore any depth limit, as in postingsReport; allows register's total to match accounts screen
|
-- 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
|
-- do not strip prices so we can toggle costs within the ui
|
||||||
, show_costs_=True
|
, show_costs_=True
|
||||||
-- XXX aregister also has this, needed ?
|
-- 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}
|
-- resetOpts ui@UIState{astartupopts} = ui{aopts=astartupopts}
|
||||||
|
|
||||||
resetDepth :: UIState -> UIState
|
resetDepth :: UIState -> UIState
|
||||||
resetDepth = updateReportDepth (const Nothing)
|
resetDepth = updateReportDepth (const mempty)
|
||||||
|
|
||||||
-- | Get the maximum account depth in the current journal.
|
-- | Get the maximum account depth in the current journal.
|
||||||
maxDepth :: UIState -> Int
|
maxDepth :: UIState -> Int
|
||||||
@ -292,34 +292,38 @@ maxDepth UIState{ajournal=j} = getMax . foldMap (Max . accountNameLevel) $ journ
|
|||||||
decDepth :: UIState -> UIState
|
decDepth :: UIState -> UIState
|
||||||
decDepth ui = updateReportDepth dec ui
|
decDepth ui = updateReportDepth dec ui
|
||||||
where
|
where
|
||||||
dec (Just d) = Just $ max 0 (d-1)
|
dec (DepthSpec (Just d) _) = DepthSpec (Just $ max 0 (d-1)) []
|
||||||
dec Nothing = Just $ maxDepth ui - 1
|
dec (DepthSpec Nothing _) = DepthSpec (Just $ maxDepth ui - 1) []
|
||||||
|
|
||||||
-- | Increment the current depth limit. If this makes it equal to the
|
-- | Increment the current depth limit. If this makes it equal to the
|
||||||
-- the maximum account depth, remove the depth limit.
|
-- the maximum account depth, remove the depth limit.
|
||||||
incDepth :: UIState -> UIState
|
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.
|
-- | 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
|
-- 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
|
-- maximum account depth. If the specified depth is negative, reset the depth limit
|
||||||
-- to whatever was specified at uiartup.
|
-- to whatever was specified at uiartup.
|
||||||
setDepth :: Maybe Int -> UIState -> UIState
|
setDepth :: Maybe Int -> UIState -> UIState
|
||||||
setDepth mdepth = updateReportDepth (const mdepth)
|
setDepth mdepth = updateReportDepth (const $ DepthSpec mdepth [])
|
||||||
|
|
||||||
getDepth :: UIState -> Maybe Int
|
getDepth :: UIState -> Maybe Int
|
||||||
getDepth = (^.depth)
|
getDepth = dsFlatDepth . (^.depth)
|
||||||
|
|
||||||
-- | Update report depth by a applying a function. If asked to set a depth less
|
-- | Update report depth by a applying a function. If asked to set a depth less
|
||||||
-- than zero, it will leave it unchanged.
|
-- 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
|
updateReportDepth updateDepth ui = over reportSpec update ui
|
||||||
where
|
where
|
||||||
update = fromRight (error "updateReportDepth: updating depth should not result in an error") -- PARTIAL:
|
update = fromRight (error "updateReportDepth: updating depth should not result in an error") -- PARTIAL:
|
||||||
. updateReportSpecWith (\ropts -> ropts{depth_=updateDepth (depth_ ropts) >>= clipDepth ropts})
|
. updateReportSpecWith (\ropts -> ropts{depth_=clipDepth ropts $ updateDepth (depth_ ropts)})
|
||||||
clipDepth ropts d | d < 0 = depth_ ropts
|
clipDepth _ (DepthSpec Nothing _) = mempty
|
||||||
| d >= maxDepth ui = Nothing
|
clipDepth ropts ds@(DepthSpec (Just d) _) | d < 0 = depth_ ropts
|
||||||
| otherwise = Just d
|
| d >= maxDepth ui = mempty
|
||||||
|
| otherwise = ds
|
||||||
|
|
||||||
-- | Open the minibuffer, setting its content to the current query with the cursor at the end.
|
-- | Open the minibuffer, setting its content to the current query with the cursor at the end.
|
||||||
showMinibuffer :: T.Text -> Maybe String -> UIState -> UIState
|
showMinibuffer :: T.Text -> Maybe String -> UIState -> UIState
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user