Online Book Reader

Home Category

Beautiful Code [320]

By Root 5111 0
.avi video file that explains the choices the tree is offering the user. The Help subdirectory contains a bunch of .avi files. It must contain at least one file, which is called Start.avi. When the Help long-click item is selected, the appropriate .avi file is played, based on where the user currently is in the menu tree.

The correct file to play is found in a fashion similar to the long-click menu. The software first looks for a file with an .avi extension in the helpvideos subdirectory of C:\eLocutor. If such a file is found, it is played; otherwise, eLocutor looks for an .avi file with the name of the parent of the highlighted node. If an .avi file with this name is not found in the helpvideos directory, eLocutor climbs recursively up the menu tree until it finds a node with a corresponding help video. This feature allowed us to ship only overview videos to start with, and gradually add more and more detailed videos, which the user only needed to copy into the helpvideos subdirectory for eLocutor to start showing them.

Some help videos are available at http://www.holisticit.com/eLocutor/helpvideos.zip. Given the dynamic nature of this software, watching some videos will help the reader understand this chapter faster and more thoroughly.

30.2.3. Dynamic Tree Repopulation

The contents of the tree are stored on disk in the form of text files. The big advantage of this approach is that these files can be edited dynamically both by eLocutor and by the user. In other words, they gave us an easy way to meet one of our design criteria: to allow the user herself to adapt eLocutor to her own needs, by making data structures transparent and easily user-editable.

Because eLocutor tries to predict what you may wish to do next, the binary tree needs to be dynamic; subtrees such as Next Word are frequently repopulated. The name of each file is the same as that of a node (with a .txt extension), and contains a list of names of its immediate children. If any of the node names end in .txt, they represent the root of a sub-tree, and the names of its children can be found in the corresponding file. For instance, the root file is named Start.txt and contains the lines type.txt, edit.txt, scroll.txt, and commands.txt, each line corresponding to a set of options displayed to the user for one of the menus described in the earlier section "The Tree."

A node name not ending in .txt represents a leaf node. Selecting it results in some action being taken. For instance, if the leaf node is in the Type subtree, its selection results in the corresponding text being typed into the buffer.

To indicate nodes that are dynamically repopulated, the prefix ^ is used. For instance, the following list shows the contents of type.txt, which form the child nodes of Type in the tree shown in Figure 30-1:

commonwords.txt

speller

^word completion.txt

^next word.txt

suffixes.txt

^justsaid.txt

^clipboard.txt

^phrase completion.txt

^templates.txt

vocabularytree.txt

Subtrees whose names are prefixed with ^ are populated only when the user clicks on the corresponding root node.

The Visual Basic TreeView control has an indexing feature to speed up retrieval. This feature made us think of creating nodes in the tree with words as names, grouped together such that siblings in a tree might replace one another in a sentence without making it sound absurd. For instance, a sentence including the word "London" could easily appear in another context with the word "Boston" in its place.

Using the index in this fashion allowed us to implement two critical features of eLocutor, Replace and Template, which are discussed shortly. The downside, though, was that we had to live with the limitations of the indexing feature of the Tree View control, which does not allow duplicate keys. Nothing prevented us from inserting more than one node with the same name into the tree. Only one of those, however, could be indexed.

The subnode vocabulary tree of Type is the root node of a large subtree, which groups words that might meaningfully replace one other in

Return Main Page Previous Page Next Page

®Online Book Reader