Next Previous Up Top Contents Index

6 Using Command Tables

6.2 Implementing a command table

You use define command-table to define a new command table. Consider the following command table defined for the File menu in the task list manager:

define command-table *file-command-table* 
    (*global-command-table*)
  menu-item "Open" = open-file,
    accelerator:   make-keyboard-gesture(#"o", #"control"),
    documentation: "Opens an existing file.";
  menu-item "Save" = save-file,
    accelerator:   make-keyboard-gesture(#"s", #"control"),
    documentation: "Saves the current file to disk.";
  menu-item "Save As..." = save-as-file,
    documentation: "Saves the current file with a new name.";
  menu-item "Exit" = exit-task,
    accelerator:   make-keyboard-gesture(#"f4", #"alt"),
    documentation: "Exits the application.";
end command-table *file-command-table*;

This defines a command table, called *file-command-table*, that contains all the menu commands required in the File menu of the task list manager. It replaces the definition of each menu button, as well as the definition of the File menu itself, in the original implementation of the task list manager application that was given in Chapter 4, "Adding Menus To The Application". As you can see, this definition is considerably shorter than the individual definitions of the menu and menu buttons previously required,

When defining a command table, you should provide a list of other command tables from which the command table you are defining inherits. This is done in the clause

define command-table *file-command-table* 
    (*global-command-table*)

above. This is analogous to the way that the superclasses of any frame class are listed in the frame's definition.

Any items defined by the command tables which are to be inherited are automatically added to the command table being defined.

In the example above, *file-command-table* inherits from only one command table: *global-command-table*. This is defined globally for the whole Dylan environment, and every command table that does not explicitly inherit from other command tables must inherit from this command table.

Each menu item is introduced using the menu-item option, and a command is specified for each menu item immediately after the = sign. Each command is just the activate callback that was defined for the equivalent menu button gadget in Chapter 5, "Adding Callbacks to the Application".

Notice that you can use the accelerator: and documentation: init-keywords to specify a keyboard accelerator and a documentation string for each menu item in the command table, just like you can when you define each menu button in a menu using a specific gadget. In the same way, you can specify the value of any init-keyword that can be specified for an instance of <menu-button>.


Building Applications Using DUIM - 26 May 1999

Next Previous Up Top Contents Index