Action defaults basics

Action defaults allow you to define default attributes for the action views, the graphical objects in form files that can trigger action events.

For example, you can specify the default text, comment, and image for elements like push buttons, toolbar items, topmenu options, across all forms of the application.

Centralize common action defaults in a global action defaults (.4ad) file and define form specific action defaults in form files in the ACTION DEFAULTS section.

Centralize as much as possible decoration attributes to avoid specifying them in all the source files that define the same action view.

Each attribute of an action view element will automatically be set to the value defined in the action defaults, if there is no value explicitly specified in the element definition for that attribute.

The action default attributes to be applied are selected according to name of the action. In some situations, the action view can be bound to an action handler by specifying a sub-dialog and/or field name prefix. For those views, the action defaults defined with the corresponding action name will be used to set the attributes with the default values. In other words, the prefix will be ignored. For example, if an action view is defined with the name custlist.append, it will get the action defaults defined for the append action.

Important: Action defaults are applied only once, to newly created elements. Dynamic changes are not reapplied to action views. For example, if you first load a toolbar, then you load a global action defaults file, the attributes of the toolbar items will not be updated with the last loaded action defaults. If you dynamically create action views (like TopMenu or ToolBar), the action defaults are not applied, so you must set all decoration attributes by hand.

Action defaults can be defined globally for the whole program, or at the form level. Local form action defaults take precedence over global action defaults. Global action defaults are loaded from a default.4ad file or by using the ui.Interface.loadActionDefaults() method when the file name must be explicitly specified. Form specific action defaults can be defined in the ACTION DEFAULTS section of the .per file, or can be loaded at runtime with the ui.Form.loadActionDefaults() method, typically in form initializer functions.

For example, in most cases a "print" action needs a text decoration "Print", with a printer icon image and a Ctrl-P accelerator key. Those attributes can be centralized in the global action defaults. Some action views of the print action may need specific attributes; If the current form handles customer addresses, the comment attribute of a print button might be "Print current customer information". In this case you can define action defaults at the form level, which have a higher priority than the global action defaults. Additionally, if some action views must have a different image in the same form, you can specify the image attribute in the definition of each element to overwrite the defaults: A toolbar button bound to the "print" action might have a small image, while the print button in the form layout might have a large one.

The final attribute values used for graphical elements are set based on this priority:

  1. Attribute defined in the action view element definition itself.
  2. Attribute defined for the element action in the form action defaults.
  3. Attribute defined for the element action in the global action defaults.
The following code defines a BUTTON in the form specification file:
ATTRIBUTES
 BUTTON b1: print, TEXT="Do Print";
END
If the form action defaults define:
form.per:
ACTION DEFAULTS
  ACTION print (IMAGE="smiley", COMMENT="Print orders",
                acceleratorName=Control-P)
END

form.42f:
<ActionDefaultList>
  <ActionDefault name="print" image="smiley" comment="Print orders"
   acceleratorName="control-p" />
</ActionDefaultList>
and the global action defaults define:
<ActionDefaultList>
  <ActionDefault name="print" text="Print" image="printer" />
</ActionDefaultList>

the button object will get these final attribute values:

and the accelerator will be Ctrl-P.