« [Tip] Update Servoy data using AppleScript | Main | [Tip] Multi-line list design tip »

December 13, 2005

[Tip] PopupMenu Plugin example code

by David Workman
Data Mosaic

Picture_7 The popup menu plugin Servoy recently released is quite the cool addition. This allows you to attach a drop down menu to an object which is a very professional looking GUI element.

The example code that comes with the plugin calls a unique method for each menu item. The last thing I want to do is clutter up my method editor with methods for every menu item I use on a layout. The obvious answer is to use the same method for each menu item and then send a parameter along with the method call denoting which menu item was selected. What isn't so obvious at first glance is how to accomplish this. Here you go!

METHOD 1: Create pop up menu

//create popup menu array
var menu = new Array(
    plugins.popupmenu.createMenuItem('All notes',  NOTE_tabs_control),
    plugins.popupmenu.createMenuItem('Table notes', NOTE_tabs_control),
    plugins.popupmenu.createMenuItem('Field notes', NOTE_tabs_control)
)

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

//pop up the menu
var elem = elements[application.getMethodTriggerElementName()]
if (elem != null)
{
    plugins.popupmenu.showPopupMenu(elem, menu);
}

METHOD 2: "NOTE_tabs_control"

//set tab index
elements.tab_note_list.tabIndex = arguments[0] + 1

//set label
switch (arguments[0]) {
    case 0: globals.DCT_note_tab = "All Notes"; break;
    case 1: globals.DCT_note_tab = "Table Notes"; break;
    case 2: globals.DCT_note_tab = "Column Notes"; break;
}

| Posted by David Workman on December 13, 2005 at 11:50 AM in Tips | Permalink

Comments

Post a comment