DataTreeView-0.1.1: A GTK widget for displaying arbitrary Data.Data.Data instances

Safe HaskellSafe-Infered





newtype CustomHandler Source

Custom handlers are used for overriding the generic formatting behaviour at some values (for example, printing a String directly into the Constructor or value column rather than as a list of chars).

If a custom handler matches (returns a Just), no recursion into its children is performed by default. You can recurse manually using self.




runCH :: forall d. Data d => d -> MCH (Maybe (StrictTree Row))


Monoid CustomHandler

The mempty CustomHandler handles nothing. mappend ch1 ch2 tries ch1 first, falling back to ch2 if ch1 doesn't handle the argument.

showType :: TypeRep -> StringSource

Show a type with some prettification like replacing [Char] with String.

The monad in which custom handlers run

self :: Data d => d -> MCH (StrictTree Row)Source

Invokes the final Data-to-Tree conversion function, which includes the generic handler, the CustomHandler being defined, and any CustomHandlers mappended to the one being defined.

Thus, invoking self x from your implementation of runCH x will usually amount to an infinite loop, but invoking self y on some child y of x is fine.

genericHandler :: forall e. Data e => e -> MCH (StrictTree Row)Source

Generates the subtree using the Data instance of the argument (calls self on the children, not genericHandler).

You can invoke this from your CustomHandler and then override some attributes of the result.

Specialized constructors

simpleCH :: Typeable a => (a -> MCH ([CellAttr], [CellAttr])) -> CustomHandlerSource

A CustomHandler that only works at a fixed type (and always works there), and generates a node with no children and with the default text in the type column. The function should return the rowCV in the first component and the rowCustomInfo in the second.

monoCH :: Typeable a => (a -> MCH (Maybe (StrictTree Row))) -> CustomHandlerSource

Creates a custom handler that only applies at a fixed monomorphic type a.

monoPureCH :: Typeable a => (a -> Maybe (StrictTree Row)) -> CustomHandlerSource

Creates a pure custom handler that only applies at a fixed monomorphic type a.

monoPureCH' :: Typeable a => (a -> StrictTree Row) -> CustomHandlerSource

Creates a pure custom handler that only and always applies at a fixed monomorphic type a.

poly1CH :: Typeable1 f => (forall a. Data a => f a -> MCH (Maybe (StrictTree Row))) -> CustomHandlerSource

Creates a custom handler that applies at f a for a fixed type constructor f and for any a.

poly2CH :: Typeable2 f => (forall a b. (Data a, Data b) => f a b -> MCH (Maybe (StrictTree Row))) -> CustomHandlerSource

Creates a custom handler that applies at f a b for a fixed binary type constructor f and for any a and b.

... for containers

data AnyData Source


forall a . Data a => AnyData a 

container0CH :: Typeable a => (a -> (String, [(String, String)], [AnyData])) -> CustomHandlerSource

Makes a CustomHandler for container-like types. The given function should return:

  • The string for the rowCV cell
  • A list of arbitrary (key,value) pairs to be displayed in the rowCustomInfo cell (this should be things like the size of the collection, not a list of elements)
  • The list of elements

container1CH :: Typeable1 f => (forall a. Data a => f a -> (String, [(String, String)], [AnyData])) -> CustomHandlerSource

Like container0CH, but for type constructors

container2CH :: Typeable2 f => (forall a b. (Data a, Data b) => f a b -> (String, [(String, String)], [AnyData])) -> CustomHandlerSource

Like container1CH, but for binary type constructor

Data that custom handlers must produce


data Row Source

Data for a row of the tree widget.




rowCV :: !CellData

Constructor name, literal value, or a placeholder like "{List}" for custom things

rowFieldName :: !CellData

Record field name. You can mostly ignore this, see the remark in newRow.

rowCustomInfo :: !CellData

Arbitrary information (left empty by the generic handler)

rowTypeName :: !CellData




Construct a Row with empty rowFieldName.

You usually can't know the field name for a node x during a recursive call with x at its root - the field name will be added afterwards by the generic handler for the parent node of x if that parent node is a constructor with named fields.


addToAll :: Row -> [CellAttr] -> RowSource

Adds the given attribute to each cell of the given row.

Cell attributes

txt :: String -> CellAttrSource

The cell's text. If this attribute occurs multiple times for a single cell, the occurences are concatenated.

bgcolor :: ColorName -> CellAttrSource

Background color, by name

bgcolor' :: Word16 -> Word16 -> Word16 -> CellAttrSource

Background color, red/green/blue

fgcolor :: ColorName -> CellAttrSource

Foreground color, by name

fgcolor' :: Word16 -> Word16 -> Word16 -> CellAttrSource

Foreground color, red/green/blue

scale :: Double -> CellAttrSource

Font scaling factor


dataToTree :: forall d. Data d => CustomHandler -> d -> IO (StrictTree Row)Source