4D v13.4

Specifying the action of a menu

Home

 
4D v13.4
Specifying the action of a menu

Specifying the action of a menu  


 

 

To enable a menu command to perform its function, you must assign either a project method or a standard action to it. 

These methods or standard actions perform the functions indicated by the menu commands. For example, the Monthly Report menu command can call a project method that prepares a monthly report from a table containing financial data. The Cut menu command can call the Cut standard action in order to move the selection to the clipboard and erase it from the window in the foreground. When a menu command is chosen, 4D executes the standard action or project method that is assigned to it.

The choice between associating a standard action or a project method with a menu command depends on the type of result desired. In principle, it is preferable to choose a standard action whenever possible since they implement optimized mechanisms, more particularly an activation/deactivation according to the context. 

You can also assign both a standard action and a project method to a menu item. In this case, the standard action is never executed; however, 4D uses this action to enable/disable the menu item according to the context. When a menu item is disabled, the associated project method cannot be executed. 

You create the project methods in the Method editor. You can create them either before or after you assign them to the menu command. When you have assigned a method to a menu command in the Menu Bar editor, you can open this method by simply selecting the [...] button.

If a menu command is not associated with a standard action or a method, when it is selected in Application mode, 4D will automatically return to the Design mode (if it is accessible).

To assign a project method to a menu command:

  1. Create or select the menu command.
    The properties area changes to display the properties of the selected menu command.
  2. If the project method already exists in the database, select it using the “Method Name” combo box.
    OR
    If the project method does not exist, enter its name in the “Method Name” combo box then click on the [...] button.
    In the latter case, 4D displays the project method creation dialog that is used to access the Method editor.
    Note: If you change the name of a method that is used in a menu, you must update the method name here in the Menu Bar editor.
  3. Click the Start a New Process check box (optional).
    If you click the Start a New Process check box, a new process is created when the menu command is chosen.
    Normally, a method attached to a menu command executes within the current process unless you explicitly call a new process in your code. The Start a New Process check box makes it easier to start a new process.
    If you click the Start a New Process check box, 4D will create a new process when the menu command is chosen. In the Process list, 4D assigns the new process a default name using the format ML_ProcessNumber. The names of processes started from a menu are created by combining the prefix “ML_” with the process number. For more information about processes, see the Processes chapter in the Language Reference manual.

To associate a standard action with a menu command:

  1. Create or select the menu command.
    The properties area changes to display the properties of the selected menu command.
  2. Choose the action you want to assign to it in the “Associated Standard Action” menu.
    The list of standard actions proposed for menus is similar to the one for buttons (accessible in the Property List for buttons in the 4D Form editor). Most of the actions can, in fact, be used in both contexts. Only the Automatic splitter action cannot be associated with a menu command: therefore it does not appear in the pop-up selection menu. For a description of each standard action, refer to Standard actions.
    Note for Mac OS: Under Mac OS, the custom menu commands associated with the Preferences and Quit actions are automatically placed in the application menu, in compliance with the platform interface standards.
  3. (Optional) Select the Execute without validating option.
    When this option is checked, 4D does not trigger the “validation” of the field where the cursor is located before executing the associated action.
    This option is mainly intended for Edit menu commands. By default, 4D processes and “validates” the contents of a field before executing a standard action (via a menu command or a shortcut), which has the effect of generating an On Data Change form event. This can disrupt the functioning of copy or paste type commands because when they are called, the On Data Change form event is generated unexpectedly. In this case, it is useful to check the Execute without validating option.

 
PROPERTIES 

Product: 4D
Theme: Menus and menu bars

 
SEE ALSO 

Standard actions