9 Hierarchical List Control

► |  | Mr Lib: Extra GUI Libraries

1 | Aligned Pasteboard
2 | Arrow Toggle Snip
3 | Bitmap Label
4 | Cache-image Snip
5 | Close Icon
6 | Expandable Snip
7 | GIF and Animated GIF Writing
8 | Graphs
9 | Hierarchical List Control
10 | Include Bitmap
11 | Interactive Value Port
12 | Name Message
13 | Path Dialog
14 | Plot
15 | Switchable Button
16 | Image Core
17 | Matrix Snip
18 | Snip Canvases
19 | Syntax Browser
20 | Te X Table
21 | Terminal Window
22 | White on Black Panel Predicate
23 | Acknowledgments
| Index

▼ | 9 | Hierarchical List Control

9.1 | hierarchical-list%
9.2 | hierarchical-list-item<%>
9.3 | hierarchical-list-compound-item<%>
9.4 | Snips in a hierarchical-list% Instance

top contents ← prev up next →

### 9`` Hierarchical List Control🔗ℹ

(require mrlib/hierlist) | package: gui-lib

A hierarchical-list% control is a list of items, some of which can themselves be hierarchical lists. Each such sub-list has an arrow that the user can click to hide or show the sub-list’s items.

A short example to demonstrate this control:

> #lang racket/gui
> (require mrlib/hierlist)
> (define set-text-mixin
> (mixin (hierarchical-list-item<%>)
> ((interface () set-text))
> (inherit get-editor)
> (super-new)
> ; set-text: this sets the label of the item
> (define/public (set-text str)
> (define t (get-editor)) ; a text% object
> (send t erase)
> (send t insert str))))
> ; new class uses hierarchical-list% to show a directory
> (define directory-list%
> (class hierarchical-list% (init [dir (current-directory-for-user)])
> (define the-dir dir)
> ; new-item : create new item for a file or directory
> (define (new-item parent directory subpath)
> (define item
> (if (file-exists? (build-path directory subpath))
> (send parent new-item set-text-mixin)
> (send parent new-list set-text-mixin)))
> (send item set-text (path->string subpath))
> (send item user-data (build-path directory subpath))
> item)
> ; Set the top level item, and populate it with an entry
> ; for each item in the directory.
> (define/public (set-directory dir)
> (send this delete-item top-dir-list) ; remove previous top item
> (set! top-dir-list (send this new-list set-text-mixin))
> (send top-dir-list set-text (path->string dir))
> ; add new-item for each member of dir
> (for ([i (directory-list dir)])
> (new-item top-dir-list dir i)))
> (super-new)
> ; top item in hierlist
> (define top-dir-list (send this new-list set-text-mixin))
> ; initialise directory-list% instance
> (set-directory the-dir)))
> ; Create frame
> (define f (new frame% [label "frame"] [width 400] [height 400]))
> ; show frame onscreen
> (send f show #t)
> ; create a directory-list%
> (define my-dir (new directory-list%
> [parent f]
> [dir (find-system-path 'home-dir)]))
> ; change directory example - try this in the interactions window:
> ; (send my-dir set-directory (find-system-path 'doc-dir))

The list control supports the following default keystrokes:

- Down: move to the next entry at the current level (skipping lower levels).

- Up: move to the previous entry at the current level (skipping lower levels).

- Left: move to the enclosing level (only valid at embedded levels).

- Right: move down in one level (only valid for lists).

- Return: open/close the current selected level (only valid for lists).

9.1 hierarchical-list%
9.2 hierarchical-list-item<%>
9.3 hierarchical-list-compound-item<%>
9.4 Snips in a hierarchical-list% Instance

top contents ← prev up next →