GNU TeXmacsUser manualReferenceAboutEnglish
Displaying lists and trees
Displaying lists with enum, choice and choices
(enum cmd items default width)
(a combo box)

Builds a combo box which will execute cmd whenever the user makes a choice; the chosen string is available in cmd as the variable answer. The width is a length in the units px, em, w or h (see input in the reference), such as "10em". If the last element of items is the empty string "", the user may also type in an arbitrary value.

Scheme]

(tm-widget (test-enum)

(enum (display* "First " answer "\n")

'("gnu" "gnat" "zebra")

"zebra" "10em"))

Scheme]

(show test-enum)

(choice cmd items default)
(a list of items allowing one to be chosen)

Builds a list of items which will execute cmd whenever the user makes a choice. items is a list, default a value. Contrary to enum, all items are displayed simultaneously. If one desires scrollbars, the widget must be enclosed in a scrollable container. The width of the widget may be set using a resize widget.

Scheme]

(tm-widget (test-choice)

(resize "200px" "50px"

(scrollable

(choice (display* answer "\n")

'("First" "Second" "Third" "Fourth" "Fifth" "Sixth")

"Third"))))

Scheme]

(show test-choice)

(choices cmd items defaults)
(a list of items allowing several to be chosen)

Builds a list of items which will execute cmd whenever the user makes a choice. Several items may be selected at the same time. Both items and defaults are hence lists. Contrary to enum, all items are displayed simultaneously. If one desires scrollbars, the widget must be enclosed in a scrollable container. The width of the widget may be set using a resize widget.

Scheme]

(tm-widget (test-choices)

(resize "200px" "100px"

(scrollable

(choices (display* answer "\n")

'("A" "B" "C" "D" "E" "F" "G" "H" "I" "J" "K" "L")

'("B" "D" "F" "H" "J" "L")))))

Scheme]

(show test-choices)

Displaying trees with tree-view
(tree-view cmd data data-roles)
(a tree view)

The tree-view widget (implemented in the Qt, Cocoa and Vue ports, not in X11/Widkit; the data roles for icons and tooltips are only honoured by Qt) provides a graphical representation of a TeXmacs tree data (not a Scheme tree!). This may be part of a document or any other tree. The first node in data won't be displayed. All other nodes may have attributes called data roles which will determine the textual representation of the node, whether it has some icon next to it and which one, etc. These attributes are simply children of the nodes in data at predefined positions given by the data roles specification in the argument data-roles. This is a list of identifiers for each tree label present in the data. For instance, with the following data roles specification:

(list
  (library    DisplayRole DecorationRole UserRole:1)
  (collection DisplayRole UserRole:1))

we use the data:

(root
  (library "Library" "icon.png" 12345
    (collection "Cool stuff" 001)
    (collection "Things to read" 002)
    (collection "Current work" 003
      (collection "Forever current" 004)
      (collection "Read me" 005))))

Notice that the node root won't be displayed by the tree-view and needs no data roles. Here UserRole:1 is used to store database ids but it can be anything else. The supported data roles are:

DisplayRole        ; a string to be displayed
EditRole           ; a string valid for an editable representation
ToolTipRole        ; a small tooltip to display when the mouse hovers over
StatusTipRole      ; for the status bar (if present and supported)
DecorationRole     ; file name of an icon to use
CommandRole        ; sent to the command executed after (double?) clicks
UserRole:<number>  ; left to user definition (will be returned as strings)
Default data roles
It is possible to omit some or all of the data role specification. By default the widget will use the tree label's string representation for DisplayRole, EditRole, ToolTipRole and StatusTipRole. For the DecorationRole it will try to load pixmaps named treelabel-<label>.xpm in $TEXMACS_PIXMAP_PATH. This search won't happen if the DecorationRole is specified (i.e. a full path with or without environment variables and wildcards must be given). The default CommandRole is the subtree itself (see below).
Using commands
The first argument of tree-view, cmd, is a Scheme procedure (not a piece of code as for the other widgets) that will be called when items are clicked or selected. The procedure must have the following signature:
(lambda (Event CommandRole . UserRoles) (…))

where:

If multiple selections are enabled and one is made, CommandRole and UserRole will both be lists (not implemented yet). Keep in mind that the data is a TeXmacs tree and thus not a copy but always a pointer to the actual data (unless you copy or transform it into another format with e.g. tree->stree)

Examples
See widget10 in
menu-test.scm

and the examples below.

An example using data roles

We build on the previous example, but now we add a command. Notice how the way one adds commands to tree-view departs from that of other widgets: instead of a piece of code using variables with fixed names (usually answer and filter), one must provide a procedure, which is applied to the arguments described above.

Scheme]

(define t

(stree->tree

'(root

(library "Library" "$TEXMACS_PIXMAP_PATH/tm_german.xpm" 01

(collection "Cool stuff" 001)

(collection "Things to read" 002)

(collection "Current work" 003

(collection "Forever current" 004)

(collection "Read me" 005))))))

Scheme]

(define dd

(stree->tree

'(list (library DisplayRole DecorationRole UserRole:1)

(collection DisplayRole UserRole:1))))

Scheme]

(define (action clicked cmd-role . user-roles)

(display* "clicked= " clicked ", cmd-role= " cmd-role

", user-roles= " user-roles "\n"))

Scheme]

(tm-widget (widget-library)

(resize '("150px" "400px" "9000px") '("300px" "600px" "9000px")

(vertical

(bold (text "Testing tree-view"))

===

(tree-view action t dd))))

Scheme]

(top-window widget-library "Tree View")

Notice how we must add $TEXMACS_PIXMAP_PATH to the name of the pixmap because we are not using the default DecorationRole.

An example using the buffer tree

We can even use the buffer-tree as argument to tree-view. Changes in the buffer will show up immediately in the widget. In this example we use the default data role specification.

Warning 1. When this was written (31 Dec. 2013) the Qt implementation was sloppy and forced a full reloading of the data model for each modification of the tree. The slowdown was already noticeable with documents of a few pages like this one. Additionally, the current selection in the widget was lost after each modification to the buffer (fixing this requires writing a fully fledged observer and probably an intermediate copy of the data).

Scheme]

(tm-widget (widget-buffer)

(resize '("150px" "400px" "9000px") '("300px" "600px" "9000px")

(vertical

(bold (text "Testing tree-view"))

===

(tree-view noop (buffer-tree) (stree->tree '(dummy))))))

Scheme]

(top-window widget-buffer "Tree View")

An example with the side tools

Side tools are defined with tm-tool (see

progs/kernel/gui/menu-widget.scm

) and opened with tool-select. The following code shows the document tree in a panel on the right hand side of the current window:

Scheme]

(tm-tool (document-tree-tool win)

(:name "Document tree")

(resize '("150px" "300px" "9000px") '("300px" "600px" "9000px")

(tree-view noop (buffer-tree) (stree->tree '(unused)))))

Scheme]

(tool-select :right 'document-tree-tool)

The panel can be closed with the cross in its title bar.

Permission is granted to copy, distribute and/or modify this˙document under the terms of the GNU Free Documentation License, Version 1.1 or˙any later version published by the Free Software Foundation; with no Invariant˙Sections, with no Front-Cover Texts, and with no Back-Cover Texts. A copy of˙the license is included in the section entitled "GNU Free Documentation License".