Using attributes of action defaults

Purpose of action defaults

Action defaults allow to define default attributes for common action. These defaults can be overwritten with form item attributes, or with dialog action handler attributes (only for default action views).

Centralize action attributes with action defaults, to avoid specifying them in all the source files that define the same action view and action handler. For example, you can specify the default text, image and keyboard accelerator for elements like push buttons, toolbar items, topmenu options.

Common action defaults are typically defined in a global action defaults (.4ad) file, while form specific actions are configured with form action defaults in the ACTION DEFAULTS section of the .per form specification file.

Global action defaults file

Global action defaults are defined in an XML file with the 4ad extension. By default, the runtime system searches for a file named default.4ad in the current directory. If the file does not exist, it searches in the directories defined by the FGLRESOURCEPATH (or DBPATH) environment variable. If no file was found using the environment variable(s), standard action default settings are loaded from the FGLDIR/lib/default.4ad file.

Important: Global action defaults must be defined in a unique file; you cannot combine several 4ad files.

If needed, override the default search by loading a specific global action defaults file with the ui.Interface.loadActionDefaults() method.

It is possible to use localized strings in action default attributes such as TEXT and COMMENT, by using LStr XML elements:
<ActionDefaultList>
  <ActionDefault name="yes" text="Yes">
     <LStr text="common.yes"/>
  </ActionDefault>
  ...

Form specific action defaults

Action defaults can be defined at the form level in the ACTION DEFAULTS section. When action defaults are defined in the form file, action views get the attributes defined locally for this form:
ACTION DEFAULTS
  ACTION print (TEXT="Print",
                IMAGE="printer",
                COMMENT="Print the current record",
                ACCELERATOR=CONTROL-P)
END

Form action defaults can also be defined in a .4ad file to be loaded dynamically with the ui.Form.loadActionDefaults() method. This method is typically used in form initializers to decorate several application forms without defining an ACTION DEFAULTS section in each .per file.

It is possible to use localized strings in action default attributes such as TEXT and COMMENT:
ACTION print (TEXT=%"common.print")

Action defaults are applied only once

Decoration attributes (like TEXT, IMAGE) of an action view will automatically be set with the value defined in the action defaults to all new action views of a new created form, if there is no explicitly value specified in the element definition for that attribute. Decoration action default attributes are applied only once, to newly created form 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 and sub-dialog actions

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.

Functional attributes

Functional attributes (like VALIDATE, ACCELERATOR) can only be defined in action defaults, or in ON ACTION dialog action handlers with the ATTRIBUTES clause. Functional attributes take effect for a given action when the dialog becomes active.