Override system-default popup-menu

Zaphod

New Member
How can I create a popup-menu that will override the system-default popup-menu that exists on fill-ins, without having to modify all my code.
 
You can do this without changing all of your code. The ideal place is from your main menu system or front end of your application.

Create a static popup-menu system containing cut, copy, paste and any other required menu-items. The simplest way to do this is to use the AppBuilder menu editor, code-preview and copy the generated code.

Paste the menu definitions into an include file and create the menu-item triggers in the same file. E.g. if you want to include Cut, Copy & Paste, then create triggers for these menu items and use Progress' own EDIT-CUT, EDIT-COPY and EDIT-PASTE functions. Naturally, you'll have to do some checking on field data-types and sensitivity etc.

Also in the file include the following trigger. This will attach the popup-menu to any field in which the 'right-click' occurs. The variable 'hOwner' is a variable of type HANDLE that you'll need to define in the definitions section of the include file. MENU m_Edit is the name of the static menu that you've created, so change as required.

ON "MOUSE-MENU-DOWN" ANYWHERE
DO:
/* If the widget doesn't already have a popup-menu */
IF SELF:pOPUP-MENU = ? THEN
DO:
/* Detatch the popup-menu from its current owner */
hOwner:pOPUP-MENU = ? NO-ERROR.

/* Attach the popup-menu to the new owner */
SELF:pOPUP-MENU = MENU m_Edit:HANDLE.

hOwner = SELF.
END.
END.

When an menu-item is selected (e.g. 'Copy'), you can find out which field the menu is attached by using the hOwner variable, or by looking at the OWNER attribute of the pop-up menu (e.g. MENU m_Edit:OWNER).

Rather than include extensive checking in each menu-item trigger, I usually validate in the MENU-DROP trigger. When this trigger fires, I find out the field to which the menu is attached (hOwner), check the widget-type, data-type, senstivity etc, and disable the menu items if not valid for the field.

One point to mention about the trigger above; Because it uses the ANYWHERE clause but not the OF clause, it will fire for any widget, anywhere but ONLY if the widget does not have its own MOUSE-MENU-DOWN trigger.
 

Zaphod

New Member
Thanks, it works great.

(except for fields that are in a prompt-for editing loop, but you can't win them all)

:)
 
Top