KNOWLEDGE BASE
Log In    |    Knowledge Base    |    4D Home
Tech Tip: How to make Hidden Standard Action Menu Items Appear Disabled in Popup Menu
PRODUCT: 4D | VERSION: 19 | PLATFORM: Mac & Win
Published On: April 18, 2022

For menus created with Dynamic pop up menu, if the menu includes standard action menu items, they are automatically hidden if the standard action cannot be invoked in the current context.

For example, a menu is created with the Select all, Clear, Copy, Cut, and Paste standard actions. In the image below, the menu items associated with the Copy and Cut standard action are hidden by default because there is no text highlighted so there is nothing to Copy or Cut (ie. cannot be invoked).



If the hidden behavior is undesirable, it can be programmed to have the standard action menu items appear disabled instead of being hidden. To do this, Get action info can be used to check if the action is usable/invokable.

Get action info(ak copy).enabled

If the action is not usable, insert a disabled menu item displaying the standard action title.

APPEND MENU ITEM($menu_l; Get action info(ak copy).title)
DISABLE MENU ITEM($menu_l; -1)



Example code that displays the standard action menu item as disabled when it cannot be invoked:

C_TEXT($selected_t; $menu_l)
$menu_l:=Create menu

If (Get action info(ak select all).enabled)
  APPEND MENU ITEM($menu_l; ak standard action title)
  SET MENU ITEM PROPERTY($menu_l; -1; Associated standard action; ak select all)
Else
  APPEND MENU ITEM($menu_l; Get action info(ak select all).title)
  DISABLE MENU ITEM($menu_l; -1)
End if

If (Get action info(ak clear).enabled)
  APPEND MENU ITEM($menu_l; ak standard action title)
  SET MENU ITEM PROPERTY($menu_l; -1; Associated standard action; ak clear)
Else
  APPEND MENU ITEM($menu_l; Get action info(ak clear).title)
  DISABLE MENU ITEM($menu_l; -1)
End if

If (Get action info(ak copy).enabled)
  APPEND MENU ITEM($menu_l; ak standard action title)
  SET MENU ITEM PROPERTY($menu_l; -1; Associated standard action; ak copy)
Else
  APPEND MENU ITEM($menu_l; Get action info(ak copy).title)
  DISABLE MENU ITEM($menu_l; -1)
End if

If (Get action info(ak cut).enabled)
  APPEND MENU ITEM($menu_l; ak standard action title)
  SET MENU ITEM PROPERTY($menu_l; -1; Associated standard action; ak cut)
Else
  APPEND MENU ITEM($menu_l; Get action info(ak cut).title)
  DISABLE MENU ITEM($menu_l; -1)
End if

If (Get action info(ak paste).enabled)
  APPEND MENU ITEM($menu_l; ak standard action title)
  SET MENU ITEM PROPERTY($menu_l; -1; Associated standard action; ak paste)
Else
  APPEND MENU ITEM($menu_l; Get action info(ak paste).title)
  DISABLE MENU ITEM($menu_l; -1)
End if

$selected_t:=Dynamic pop up menu($menu_l)