Next Previous Contents

3. Tree menu: A special type of form

Linuxconf defines three commands to layout a tree menu. A tree menu is a global menu containing all linuxconf menu entries including sub-menus. Small controls along the branches of the menu allow the user to collapse/expand a branch as needed. The presentation of the tree menu should follow the standards of the user interface toolkit you are using.

When you click on a terminal entry (No sub-menu attached), a linuxconf's dialog pops up. Here is an example

        Mainform main-0 Linuxconf
            Treemenu main-0.tree
                Treesub 1 "" Networking
                    Treeelem "" "Basic host information"
                    Treeelem "" "DNS config"
                    End
                End
            End
        

Here are the primitives

3.1 (40) Treemenu ID

The ID is used when sending an "action" request to linuxconf. A treemenu is mapped into a form (a Mainform generally).

Extra parameters:

3.2 (45) Treesub expand-flag icon title

This define a new sub-tree. The expand flag tells if the sub-tree must be initially expanded. This information may come from a previous session as linuxconf is preserving the state of the tree menu in /var/run/treemenu.cache.

The icon is the name of a little icon that may be place near the sub-menu title, generally on the left. An empty (quoted) string is supplied to mean no icon.

Clicking on this menu title has no effect protocol wise. The tree is collapsed or expanded.

Session management

When the dialog holding the treemenu is dismissed, it may be useful to preserve the state of the treemenu for the next session. Currently in linuxconf, there is a single treemenu for the whole application, so preserving the state is not difficult. It is handy. You enter/leave linuxconf and you get the menu in the state of the previous session.

The treemenu must transmit back to linuxconf the state of the expand-flang for all Treesub items. It does so by using the dump protocol. This protocol is normally associated with edit field (text field, check box). Each edit field is associated with unique ID and this ID is used to talk back with linuxconf. For Treesub item, there is no ID. We are using a trick. Our goal here is to know the list of Treesub item which are in the expanded state. Each Treesub item is associated with a unique key representing its path (see below for Treeelem). So we simply throw the list of expanded Treesub like this:

        dump form-path t0 0/0/1/
        dump form-path t1 0/1/
        

So we are simply generating pseudo ID t0, t1, t2, etc... Linuxconf is really expecting those ID starting with a "t" and going from "t0" up to "tN" where N is the last expended Treesub. So the pseudo ID are not arbitrary. They are pseudo ID because they were not sent by Linuxconf at all.

This dump sequence is performed each time an action is performed. For example, if any button is hit, the tree state is transfered. This is not optimal, but may allow more control to the application in the future.

Note that it follows the rest of the protocol. A treemenu may be seen as a dumpable field and as such must send its status/value every time a dump is done.

3.3 (41) Treeelem icon title

This is a terminal menu item. Clicking on that item generate an action. A key identifying this item is transmitted to linuxconf. The behavior of the Treeelm widget is a little like the Buttonfill widget, except that the key transmitted has to be computed.

The key is a path with numbers separated with slashes. Each member of the path represents the sub-menu item that was selected to reach the terminal item. Item are numbered from 0. In the example above, selecting the "DNS config" option would generate the following key

        0/0/1/
        

Note that linuxconf expect this verbatim with the trailing slash. Check out the file /var/run/treemenu.cache (after having run linuxconf with the treemenu module enabled). You will see the various menu options as well as the various keys.

Please note that generating this key is a bit tricky. You may want to check the function TREEMENU::setup() in the file diawxxt/tree.cc to see how it is computed.


Next Previous Contents