Add a menu on right click on Browse

Posted by jpatel7 on 18-Dec-2017 14:19

How can I add a menu when I right-click on browse widget?

I have tried the following code according to the documentation:

ON RIGHT-MOUSE-DOWN OF br-maint IN FRAME a-frame-maint
DO:
   define variable lv-popupMenu as handle no-undo.
   define variable lv-popupMenuItem as handle no-undo.
   define variable b1 as handle no-undo.
   if self:num-iterations = 0 then 
      return no-apply.
   else do:
   
      self:popup-menu = lv-popupMenu.
      create menu lv-popupMenu
      assign
         popup-only = true
         title = "Browser menu".
      
      create menu-item lv-popupMenuItem
      assign
         label  = "Scheduler"
         name   = "scheduler"
         parent = lv-popupMenu.
   end.
END.

Posted by Matt Gilarde on 18-Dec-2017 14:30

Create the menu before the browse widget is displayed and set the browse widget's POPUP-MENU attribute to the menu's  handle. Then when you right click on the browse the menu will be automatically displayed (you don't need the RIGHT-MOUSE-DOWN trigger).

You can create a browse and popup menu in AppBuilder to see the code that is generated.

Posted by jquerijero on 18-Dec-2017 15:08

If you are going for dynamic context-menu.

1. Move the code inside RIGHT-MOUSE-DOWN.

2. Mode self:popup-menu = lv-popupMenu after create menu lv-popupMenu.

You might need to verify memory leak. Everytime you right-click, it will create menu handle. I'm not exactly sure if Progress will automatically delete the previous instance because it is out-of-scope or not.

To be sure, I would declare the handles as global variables, and add the following code;

IF VALID-HANDLE(lv-popupMenuItem) THEN

  DELETE OBJECT lv-popupMenuItem.

IF VALID-HANDLE(lv-popupMenu) THEN

  DELETE OBJECT lv-popupMenu.

Posted by jquerijero on 19-Dec-2017 09:32

Since you decided to use the AppBuilder, you're menu-items should be in the list of controls that you can select to define an ON CHOOSE trigger.

All Replies

Posted by Matt Gilarde on 18-Dec-2017 14:30

Create the menu before the browse widget is displayed and set the browse widget's POPUP-MENU attribute to the menu's  handle. Then when you right click on the browse the menu will be automatically displayed (you don't need the RIGHT-MOUSE-DOWN trigger).

You can create a browse and popup menu in AppBuilder to see the code that is generated.

Posted by jquerijero on 18-Dec-2017 15:08

If you are going for dynamic context-menu.

1. Move the code inside RIGHT-MOUSE-DOWN.

2. Mode self:popup-menu = lv-popupMenu after create menu lv-popupMenu.

You might need to verify memory leak. Everytime you right-click, it will create menu handle. I'm not exactly sure if Progress will automatically delete the previous instance because it is out-of-scope or not.

To be sure, I would declare the handles as global variables, and add the following code;

IF VALID-HANDLE(lv-popupMenuItem) THEN

  DELETE OBJECT lv-popupMenuItem.

IF VALID-HANDLE(lv-popupMenu) THEN

  DELETE OBJECT lv-popupMenu.

Posted by jpatel7 on 18-Dec-2017 16:02

I only had to move self:popup-menu = lv-popupMenu after create menu lv-popupMenu. And it started working.

However, I removed my code and used AppBuilder now to create pop-up menu as you suggested. Thanks.

Posted by jpatel7 on 18-Dec-2017 16:37

How to call a procedure or method on any menu-item click?

Posted by jquerijero on 19-Dec-2017 09:32

Since you decided to use the AppBuilder, you're menu-items should be in the list of controls that you can select to define an ON CHOOSE trigger.

This thread is closed