Menu Plugin with Sub Menu Help Please!!

Hi,
I have the following code to create a popup menu with a sub menu, I have no problems setting the method arguments for the main menu, but how does this work when is sub menus. I guess I need the loop to include the sub menus but I am not sure how to do this ???

I am using
Servoy Developer
Version 3.5.6-build 519
Java version 10.0-b23 (Windows XP)

Loop for Args

//create arguments for the method calls
var x = 0
while (menu[x])
{
menu[x].setMethodArguments(vRow,x,vColumn)
x ++
}

Full Method

case 8: //show menu for selected column
var menu6 = new Array( 
plugins.popupmenu.createMenuItem('Open',popMenuActions,'media:///door_open.png'),
plugins.popupmenu.createMenuItem('Closed',popMenuActions,'media:///door.png'),
plugins.popupmenu.createMenuItem('On-Hold',popMenuActions,'media:///hourglass.png')   
)//invoicing module

var menu5 = new Array(
plugins.popupmenu.createMenuItem('Open',popMenuActions,'media:///door_open.png'),
plugins.popupmenu.createMenuItem('Closed',popMenuActions,'media:///door.png'),
plugins.popupmenu.createMenuItem('On-Hold',popMenuActions,'media:///hourglass.png')    
)//dispatch module

var menu4 = new Array( 
plugins.popupmenu.createMenuItem('Open',popMenuActions,'media:///door_open.png'),
plugins.popupmenu.createMenuItem('Closed',popMenuActions,'media:///door.png'),
plugins.popupmenu.createMenuItem('On-Hold',popMenuActions,'media:///hourglass.png')   
)//production module

var menu3 = new Array(
plugins.popupmenu.createMenuItem('Open',popMenuActions,'media:///door_open.png'),
plugins.popupmenu.createMenuItem('Closed',popMenuActions,'media:///door.png'),
plugins.popupmenu.createMenuItem('On-Hold',popMenuActions,'media:///hourglass.png')    
)//purchasing module

var menu2 = new Array(
plugins.popupmenu.createMenuItem('Open',popMenuActions,'media:///door_open.png'),
plugins.popupmenu.createMenuItem('Closed',popMenuActions,'media:///door.png'),
plugins.popupmenu.createMenuItem('On-Hold',popMenuActions,'media:///hourglass.png')     
)//planning module
	
var menu1 = new Array(plugins.popupmenu.createMenuItem('Modules', null,'media:///sitemap_color.png'),
plugins.popupmenu.createMenuItem('-',null),
plugins.popupmenu.createMenuItem('Planning',menu2,'media:///calculator_edit.png'),//planning module
plugins.popupmenu.createMenuItem('Purchasing',menu3,'media:///basket_add.png'),//purchasing module
plugins.popupmenu.createMenuItem('Production',menu4,'media:///bricks.png'),//production module
plugins.popupmenu.createMenuItem('Dispatch',menu5,'media:///lorry.png'),//dispatch module
plugins.popupmenu.createMenuItem('Invoicing',menu6,'media:///coins.png')//invoicing module
)//module menu

var menu = new Array(
plugins.popupmenu.createMenuItem('Set Status', null,'media:///cog_go.png'),
plugins.popupmenu.createMenuItem('-',null),
plugins.popupmenu.createMenuItem('Modules',menu1,'media:///sitemap_color.png')
)//main menu

//create arguments for the method calls
var x = 0
while (menu[x])
{
menu[x].setMethodArguments(vRow,x,vColumn)
x ++
}
return menu

To create a submenu, you have to provide an array of menu items instead of a method name. For example:

var vMenu = new Array();
var vMenuItem;

// Add some items
vMenuItem = plugins.popupmenu.createMenuItem('Menu 1', aMethod);
vMenu[vMenu.length] = vMenuItem;
vMenuItem = plugins.popupmenu.createMenuItem('Menu 2', aMethod);
vMenu[vMenu.length] = vMenuItem;

// Create submenu
var vSubMenu = new Array();
vMenuItem = plugins.popupmenu.createMenuItem('Menu 2.1', aMethod);
vSubMenu [vSubMenu.length] = vMenuItem;
vMenuItem = plugins.popupmenu.createMenuItem('Menu 2.2', aMethod);
vSubMenu [vSubMenu.length] = vMenuItem;

// Add submenu
vMenuItem = plugins.popupmenu.createMenuItem('mySubmenu', vSubMenu );
vMenu[vMenu.length] = vMenuItem;

Hi Patrick,

I am a little confused now, could you show me how your suggested method would fit in the sample code from servoys plugin please.

‘Move Sample’ gives the following

var submenu = new Array(
	plugins.popupmenu.createCheckboxMenuItem('i18n:bla_bla',myMethod),
	plugins.popupmenu.createCheckboxMenuItem('he' , globals.myOtherGlobalMethod , 'media:///day_obj.gif'),
	plugins.popupmenu.createCheckboxMenuItem('more' , globals.myOtherGlobalMethod ,null, 'm') //last parameter is mnemonic-key
)

var menu = new Array(//if you assign this array to a global its reusable
	plugins.popupmenu.createMenuItem('A',myMethod),
	plugins.popupmenu.createRadioButtonMenuItem('B',myMethod),
	plugins.popupmenu.createRadioButtonMenuItem('C',myMethod),
	plugins.popupmenu.createMenuItem('-'),
	plugins.popupmenu.createMenuItem('<html><b>Hello</b></html>',myMethod),
	plugins.popupmenu.createMenuItem('G', globals.myGlobalMethod),
	plugins.popupmenu.createMenuItem('SubMenu',submenu)
)

menu[1].setSelected(true);
menu[5].setEnabled(false)
submenu[1].setSelected(true);

// To transfer the right element and formname triggers you have to set them as arguments
menu[2].setMethodArguments(new Array(application.getMethodTriggerElementName(), application.getMethodTriggerFormName()));

var elem = elements[application.getMethodTriggerElementName()]
if (elem != null)
{
	plugins.popupmenu.showPopupMenu(elem, menu);
//or you can set the coordinates : plugins.popupmenu.showPopupMenu(10, 10, menu);
}

Sorry Phillip,

I oversaw what your actual problem was. By closer looking at it I see that your code is actually fine (as far as creating the menu is concerned). So now we can look at your problem “I have no problems setting the method arguments for the main menu, but how does this work when is sub menus”:

If I get this right, you want to provide method arguments to submenu menu items, correct? This can be done like this (or many other ways). Here is part of your code:

var menu6 = new Array(
plugins.popupmenu.createMenuItem('Open',popMenuActions,'media:///door_open.png'),
plugins.popupmenu.createMenuItem('Closed',popMenuActions,'media:///door.png'),
plugins.popupmenu.createMenuItem('On-Hold',popMenuActions,'media:///hourglass.png')   
)

One way to set arguments for the single items is to later call

menu6[0].setMethodArguments(yourArgumentsArray)

Or you create the initial menu6 array “my way”:

var vMenuItem, menu6 = new Array();
vMenuItem = plugins.popupmenu.createMenuItem('Open',popMenuActions,'media:///door_open.png');
vMenuItem.setMethodArguments(yourArguments);
menu6[menu6.length] = vMenuItem;
vMenuItem = plugins.popupmenu.createMenuItem('Closed',popMenuActions,'media:///door.png');
vMenuItem.setMethodArguments(yourArguments);
menu6[menu6.length] = vMenuItem;
etc.