Page 1 of 1

Pass parameter to .addMenuItem method?

PostPosted: Thu Jul 12, 2012 3:31 am
by john.allen
I have a series of methods available in a dropdown menu (created with plugins.window.createPopupMenu()). For one of these methods I would ideally like to pass a parameter with it. As you know the syntax for ".addMenuItem" though just allows for passing the name of the method (without the parentheses following the name) as otherwise it would execute when the dropdown itself is activated. I can't see any way to pass a parameter to the method but does anyone know any way of doing that?

Re: Pass parameter to .addMenuItem method?

PostPosted: Thu Jul 12, 2012 4:50 am
by ptalbot
The addMenuItem returns a MenuItem object.
You can then use the methodArguments to set the array an array of objects you want to pass to the method.

Code: Select all
var popupMenu = plugins.window.createPopupMenu();
var menuItem = popupMenu.addMenuItem('aName', aMethod);
menuItem.methodArguments = [1, true, 'whatever'];


Note that the array elements will be passed as arguments 5, 6 and so on to the callback method.

Re: Pass parameter to .addMenuItem method?

PostPosted: Thu Jul 12, 2012 9:25 am
by john.allen
Thanks so much Patrick. I missed that somehow. But with your pointer I just clicked on MenuItem and then the property of methodArguments in the documentation... Somehow I was thinking the argument construction would simply show in addMenuItem.