Using context menus

A script for the context menu allows the contents of the menu to be defined. You can add context menus to the following places in an application:

 

For browse-only scrolling windows, the context menu applies to the entire active line. For editable and adds-allowed scrolling windows, the line-level context menu items are added after any items for the field-level context menus.

The cmdListContextMenu command list is the built-in command list that contains the commands and command lists that define the contents of the context menu.

Automatically-added items

For many editable field types, the context menu is automatically populated with several standard editing commands. The following table lists the commands that are automatically added.

[spacer]

Field type

Context menu commands

Integer

Long integer

Tiny integer

String

Text

Currency

Variable currency

Date

Time

Combo Box

Undo

Cut

Copy

Paste

Clear

Select All

Picture

Undo

Cut

Copy

Paste

Clear


No commands are automatically added to context menus for windows or scrolling windows.

Adding context menu items

Use the context menu script to add items to the cmdListContextMenu built-in command list that defines the contents of the context menu. Keep in mind the following when adding context menu items:

You can use the CommandList_RemoveAll() function to remove the commands that are automatically added to the cmdListContextMenu command list used for the context menu.


The following example is the context menu script for the Explorer_List field in the Real Estate Sales Manager sample application. Commands were added to the RESM_Explorer form that perform the view actions, print the current item, and display the properties for the current item. The context menu script defines the View submenu and adds the view commands to it. Then the script adds the View submenu, separators, and additional commands to the context menu. The following illustration shows the context menu when it is displayed.

[spacer]

local integer result;
local integer command_tag;
local integer view_menu_command_list;
local integer context_menu_command_list;

{Build the View submenu}
view_menu_command_list = Command_GetTag(command View of form RESM_Explorer);

{Only need to build this once. Unlike the context menu, it is not cleared
 automatically when the context menu action is complete.}
if CommandList_NumCommands(view_menu_command_list) = 0 then
	{Large Icon}
	command_tag = Command_GetTag(command Large_Icon of form RESM_Explorer);
	result = CommandList_Add(view_menu_command_list, command_tag);

	{Small Icon}
	command_tag = Command_GetTag(command Small_Icon of form RESM_Explorer);
	result = CommandList_Add(view_menu_command_list, command_tag);

	{List}
	command_tag = Command_GetTag(command List of form RESM_Explorer);
	result = CommandList_Add(view_menu_command_list, command_tag);

	{Report}
	command_tag = Command_GetTag(command Report of form RESM_Explorer);
	result = CommandList_Add(view_menu_command_list, command_tag);

end if;

{Build the context menu}
context_menu_command_list = Command_GetTag(command cmdListContextMenu);

{Add the View sub-menu}
result = CommandList_Add(context_menu_command_list, view_menu_command_list);

{Separator}
command_tag = Command_GetTag(command cmdSeparator);
result = CommandList_Add(context_menu_command_list, command_tag);

{Print}
command_tag = Command_GetTag(command Print of form RESM_Explorer);
result = CommandList_Add(context_menu_command_list, command_tag);

{Separator}
command_tag = Command_GetTag(command cmdSeparator);
result = CommandList_Add(context_menu_command_list, command_tag);

{Properties}
command_tag = Command_GetTag(command Properties of form RESM_Explorer);
result = CommandList_Add(context_menu_command_list, command_tag);


Documentation Feedback