diff options
author | tv <tv@shackspace.de> | 2015-01-07 02:54:47 +0100 |
---|---|---|
committer | tv <tv@shackspace.de> | 2015-01-07 02:54:47 +0100 |
commit | 09899454b8c4ca848ced8f491a70b9dfbf2e5368 (patch) | |
tree | fb3ce35d7765607756669007687e9dbd51c0f05a /test5.hs | |
parent | 34a4b81da3534912a449b06ec60e836ec6d9bbcd (diff) |
toggleFold: use {load,unload}SubForest
Diffstat (limited to 'test5.hs')
-rw-r--r-- | test5.hs | 40 |
1 files changed, 13 insertions, 27 deletions
@@ -381,36 +381,22 @@ moveCursorDownToNextUnread = moveCursorToUnread findNext botOverrun moveTreeUp -toggleFold :: State -> IO State -toggleFold q@State{..} = case Z.label cursor of - TVMessage _ -> do - q' <- toggleTagAtCursor "open" q - - let Just sr = findParent isTVSearchResult cursor - TVSearchResult the_sr = Z.label sr - Notmuch.ThreadID tid = Notmuch.searchThread the_sr - - t_ <- return . fromMessageForest =<< Notmuch.getThread tid +setSubForest :: Tree.Forest a -> Tree.Tree a -> Tree.Tree a +setSubForest sf t = t { Tree.subForest = sf } - let cursor' = Z.modifyTree (\(Tree.Node l _) -> Tree.Node l t_) sr - return q' { cursor = select (==Z.label cursor) cursor' } - - TVSearchResult sr -> do - let open = not $ null $ Tree.subForest $ Z.tree cursor - let Notmuch.ThreadID tid = Notmuch.searchThread sr - t_ <- - if open - then return [] - else return . fromMessageForest =<< Notmuch.getThread tid - - let cursor' = Z.modifyTree (\(Tree.Node l _) -> Tree.Node l t_) cursor - return q { cursor = select (==Z.label cursor) cursor' } - - _ -> - return q { flashMessage = "nothing happened" } +toggleFold :: State -> IO State +toggleFold q@State{..} = + getNewSubForest >>= return . \case + Left err -> + q { flashMessage = SGR [31] $ Plain err } + Right sf -> + q { cursor = Z.modifyTree (setSubForest sf) cursor } where - select p loc = fromMaybe (error "cannot select") $ findTree p $ Z.root loc + getNewSubForest = + if hasUnloadedSubForest (Z.tree cursor) + then loadSubForest (Z.label cursor) + else return $ Right $ unloadSubForest (Z.tree cursor) toggleTagAtCursor :: Tag -> State -> IO State |