Node: Resource Syntax, Next: , Up: Custom Menus



Resource Syntax

A resource file is a simple text file. It contains curly braces to group things, spaces between things, and double quotes when strings need to include spaces. There are four fundamental ways of adding data to a resource.

First, a string (either a single word or a quoted string with spaces, we call both "strings" in this appendix) can be added all by itself, to add a string resource to the current resource. This is used, for example, to define the string printed on a menu button. In this example, four strings are added to the File resource:

     File = {
       Sample
       "longer sample"
       some text
     }
     

Second, a named string may be added by giving two strings separated by an equals sign. This is used to specify X resources and a few other optional parameters of menus, for example. Note that a string all by itself is thus an "unnamed" string.

     {"Layer groups" foreground=red sensitive=false}
     

Third, an unnamed subresource may be added. This is used to create submenus and menu buttons. To add a subresource, simply group other things in curly braces. This example describes a resource containing one string and three subresources:

     {File
       {New do_new()}
       {Save do_save()}
       {Quit do_quit()}
     }
     

Lastly, a named subresource may be added by prefixing an unnamed subresource with a string and an equals sign, just as when naming strings. This syntax is used to name the resources used for the main menu and popup menus:

     MainMenu = {
       ...
       }
     

Additionally, the menu parser allows for "hooks" whereby portions of the menu system can be programmatically created at runtime by the application. These hooks are invoked by a single word proceeded by an at sign, such as this example where most of the Sizes menu is created automatically:

     {Sizes
         @sizes
         {"Adjust active sizes ..." AdjustStyle(0)}
         }
     

In addition to all that, any unquoted pound sign (#) begins a comment. Commented text continues until the end of the containing line. Comments may begin at the beginning of a line, or after other text on the line:

     # This is a comment
     MainMenu = { # This is also a comment