Page 1 of 1

Button with menu

Posted: Fri Nov 15, 2019 4:42 am
by skiman
Hi,

I'm adding a menu to our printbutton. In this menu there are extra options to export the data. Since there are a lot of buttons in our application I would like to do the following.

Create a function which return an 'omenu'. See the code below.

Code: Select all

Function buttonprintmenu(oBrowse,_cTitel)
**************************************
Local  getlist := {} , oDlg , getoptions := {}
Local oPrintMenu

	DCSUBMENU oPrintMenu PROMPT 'Menu'
		DCMENUITEM 'Export to Screenreport' PARENT oPrintMenu ;
			ACTION {||ABO_printbrowse(oBrowse,.T.,.F.,_cTitel,'')} 

		DCMENUITEM 'Export to XLS' PARENT oPrintMenu ;
			ACTION {||ABO_printbrowse(oBrowse,.T.,.T.,_cTitel,'X')}  
			
		DCMENUITEM 'Export to PDF' PARENT oPrintMenu ;
			ACTION {||ABO_printbrowse(oBrowse,.T.,.T.,_cTitel,'P')}
			
	dcgetoptions NOTITLEBAR BORDER XBPDLG_DLGBORDER NOESCAPEKEY ;
             NOEDITNAVKEYS {|| .T. } FITPAD 1
		 
	dcread gui exit PARENT @oDlg FIT options getoptions
return oPrintMenu

With this function it is rather easy to modify the print buttons by adding the following code to the button as below:

Code: Select all

...
MENUACTION {|a,b,o,oPrintMenu|oPrintMenu:=buttonprintmenu(@oBrowse,''),oPrintMenu:PopUp( o:setParent(), o:currentPos(), 2 , ;
       XBPMENU_PU_DEFAULT + XBPMENU_PU_MOUSE_RBDOWN  ) } ;
This is working fine.

My question about this is how about the dialog oDlg that is created in the buttonprintmenu function. When will this oDlg get destroyed, or how do I destroy this? Will this give a problem if a user has executed this a lot of times during the day.

Re: Button with menu

Posted: Fri Nov 15, 2019 5:55 am
by skiman
Hi,

The dialog is created each time, and stays open in the background. So the above solution isn't working correctly.

How can i prevent that the dialog is created/shown on the screen?

Re: Button with menu

Posted: Fri Nov 15, 2019 8:23 am
by rdonnay
How can i prevent that the dialog is created/shown on the screen?
Chris -

If the PARENT clause of DCREAD GUI points to an "already created" object, then there will be no Dialog window created. When creating menus on the fly as you are doing, just simply use the oBrowse object as the parent.

Change this:

dcread gui exit PARENT @oDlg FIT options getoptions

To this:

dcread gui exit PARENT oBrowse FIT options getoptions

A 2nd option is to add the DCSUBMENU and DCMENUITEM commands to the Getlist that contains the button.
Take a look at the way menus are created in SqlQuery.Prg (attached).

Re: Button with menu

Posted: Mon Nov 18, 2019 3:41 am
by skiman
Hi Roger,

Thanks, changing it to the following works. With the FIT argument, it gives an error.

Code: Select all

dcread gui exit PARENT oBrowse 

Re: Button with menu

Posted: Mon Nov 18, 2019 7:10 am
by rdonnay
With the FIT argument, it gives an error.
You are right. It would do that. FIT is designed to fit the dialog window to the objects, but if there is no dialog window it would error. I could fix that in the code but a simpler workaround is not to use the FIT clause.

Re: Button with menu

Posted: Tue Nov 19, 2019 2:47 am
by skiman
Hi,
I could fix that in the code but a simpler workaround is not to use the FIT clause.
It's not a workaround, it is just the perfect solution. :-) This way adding a menu to a lot of buttons is really an easy task.