xmonad-contrib-0.18.1: Community-maintained extensions for xmonad

Copyright | (c) Tom Smeets <tom.tsmeets@gmail.com>
License | BSD3-style (see LICENSE)
Maintainer | Tom Smeets <tom.tsmeets@gmail.com>
Stability | unstable
Portability | unportable
Safe Haskell | Safe-Inferred
Language | Haskell2010

XMonad.Util.TreeZipper

Contents

- Data structure
- Conversion
- Navigation
- Utils

Description

Zipper over the Data.Tree data structure. This module is based on rosezipper.

Synopsis

- data TreeZipper a = TreeZipper {
  - tz_current :: Tree a
  - tz_before :: Forest a
  - tz_after :: Forest a
  - tz_parents :: [(Forest a, a, Forest a)]
  }
- cursor :: TreeZipper a -> a
- fromForest :: Forest a -> TreeZipper a
- toForest :: TreeZipper a -> Forest a
- getSubForest :: TreeZipper a -> Forest a
- rootNode :: TreeZipper a -> TreeZipper a
- parent :: TreeZipper a -> Maybe (TreeZipper a)
- children :: TreeZipper a -> Maybe (TreeZipper a)
- nextChild :: TreeZipper a -> Maybe (TreeZipper a)
- previousChild :: TreeZipper a -> Maybe (TreeZipper a)
- nodeDepth :: TreeZipper a -> Int
- nodeIndex :: TreeZipper a -> Int
- followPath :: Eq b => (a -> b) -> [b] -> TreeZipper a -> Maybe (TreeZipper a)
- findChild :: (a -> Bool) -> TreeZipper a -> Maybe (TreeZipper a)
- isLeaf :: TreeZipper a -> Bool
- isRoot :: TreeZipper a -> Bool
- isLast :: TreeZipper a -> Bool
- isFirst :: TreeZipper a -> Bool

# Data structure

data TreeZipper a Source #

A Zipper over the Data.Tree data structure.

Very crappy visualization of the `TreeZipper` data structure

                 (tz_parents)
           ([*],       *, [*])
           ([*, *],    *, [])
           ([],        *                  [*,   *])
                       |                   |    |
      +-------+--------+-------+------+  +-*-+  *
      |       |        |       |      |  |   |
     (tz_before) (tz_current) (tz_after) *   *
      |       |                |      |
    +-*-+     *                *      *
    |   |
    *   *

Constructors

TreeZipper |

Fields

- tz_current :: Tree a

  the currently focused sub-tree under the cursor

- tz_before :: Forest a

  all sub-tree's to the left of the cursor that have the same parent

- tz_after :: Forest a

  all sub-tree's to the right of the cursor that have the same parent

- tz_parents :: [(Forest a, a, Forest a)]

  list zippers for each parent level, the first element is the current parent

cursor :: TreeZipper a -> a Source #

Get the highlighted value

# Conversion

fromForest :: Forest a -> TreeZipper a Source #

Create a `TreeZipper` from a list of `Tree`s focused on the first element

toForest :: TreeZipper a -> Forest a Source #

Convert the entire zipper back to a `Forest`

getSubForest :: TreeZipper a -> Forest a Source #

Create a `Forest` from all the children of the current parent

# Navigation

rootNode :: TreeZipper a -> TreeZipper a Source #

Go to the upper most node such that nothing is before nor above the cursor

parent :: TreeZipper a -> Maybe (TreeZipper a) Source #

Move to the parent node

children :: TreeZipper a -> Maybe (TreeZipper a) Source #

Move the cursor one level down to the first node

nextChild :: TreeZipper a -> Maybe (TreeZipper a) Source #

Go to the next child node

previousChild :: TreeZipper a -> Maybe (TreeZipper a) Source #

Go to the previous child node

# Utils

nodeDepth :: TreeZipper a -> Int Source #

How many nodes are above this one?

nodeIndex :: TreeZipper a -> Int Source #

How many nodes are before the cursor? (on the current level)

followPath :: Eq b => (a -> b) -> [b] -> TreeZipper a -> Maybe (TreeZipper a) Source #

follow a Path specified by the list of nodes

findChild :: (a -> Bool) -> TreeZipper a -> Maybe (TreeZipper a) Source #

go to the first node next to the cursor that matches

isLeaf :: TreeZipper a -> Bool Source #

Check whenther this is a leaf node

isRoot :: TreeZipper a -> Bool Source #

Check whenther this is a leaf node

isLast :: TreeZipper a -> Bool Source #

Check whenther this the last child

isFirst :: TreeZipper a -> Bool Source #

Check whenther this the first child