| Prev | Next | Start of Chapter | End of Chapter | Contents | Glossary | Index | Comments | (3 out of 12)

Dynamically Constructed Menu Specifications

To provide for unpredictable situations, GMS allows you to completely define any popup or cascade menu programmatically. Dynamically defined popup and cascade menus are generically called dynamic menus.

Statically defined menus are preferable wherever they can be used, because they are faster. Dynamic menus are preferable when the need for real-time menu construction is paramount, because you can reconstruct them as needed to reflect current conditions.

Specifying a Dynamic Menu

Whether you specify a GMS menu statically or dynamically, the end result is the same: a menu specification that is input to the GMS compiler. The difference is in the techniques used for creating the menu specification.

To define a static menu, you first clone a root template or cascading entry template, then connect the template to additional templates as needed to define the menu.

To define a dynamic menu, you begin in the same way, by cloning a root or cascading entry template from the GMS Palette. A dynamic popup menu specification begins with a Dynamic Popup template; a dynamic cascade menu is specified with a Dynamic Cascade template. These two types of templates are generically called dynamic templates.


A dynamic template does not connect to any subsidiary templates. Instead, it specifies a G2 procedure called a panel constructor. When you ask GMS to display a dynamically defined menu, GMS calls the panel constructor specified by the menu's template object. The constructor returns a list of template objects that specify the contents of the desired menu. Such a list is called a template list.

To compile a panel in a static menu specification, GMS traverses a sequence of cloned templates linked by connections. To compile a panel in a dynamic menu specification, GMS traverses a sequence of dynamically constructed templates linked by membership in a list. If the templates are the same, the resulting menu is the same.

Thus dynamic menu specification is a form of automatic code generation. All you need to do is clone dynamic templates from the GMS Palette and supply appropriate panel constructors for them. GMS does the rest.


Note: Be careful not to confuse dynamic templates with dynamically constructed templates. Dynamic templates use panel constructors to define menus. Dynamically constructed templates are created by panel constructors and define menu entries.

Attributes of Dynamic Templates

The attributes of Dynamic Popup templates and Dynamic Cascade templates are identical to their static counterparts with the addition of attributes that specify the panel constructor function and control the deletion of dynamically constructed templates. These attributes are described in the following table.

Attribute Description
Gms-preconstruct-panel
Specifies that GMS reconstruct the menu every time it is displayed. If true, specifies that GMs constructs the menu at compile time.
Allowable values:
true or false
Default value:
false
Notes:
For more information about constructing dynamic menus see Constructing Dynamic Menus at Compilation Time.


Gms-subpanel-constructor
Specifies the name of the panel constructor for GMS to use to build this menu.
Allowable values:
The name of any gms panel constructor function
Default value:
g2


Gms-reclaim-templates
Specifies that dynamic templates are saved for later use after they are displayed. If false, the templates are deleted and recreated when needed.
Allowable values:
true or false
Default value:
true
Notes:
For additional information see Reusing Dynamically Constructed Templates.

| Prev | Next | Start of Chapter | End of Chapter | Contents | Glossary | Index | Comments | (3 out of 12)

Copyright © 1997 Gensym Corporation, Inc.