MenuButton — Button with popup menu
MenuButton
( | string | label , |
| itemList | menu
); |
This is a widget that looks very much like a PushButton, but unlike a PushButton it doesn't immediately start some action but opens a popup menu from where the user can select an item that starts an action. Any item may in turn open a submenu etc.
UserInput() returns the ID of a menu item if one was activated. It will never return the ID of the MenuButton itself.
Style guide hint: Don't overuse this widget. Use it for dialogs that provide lots of actions. Make the most frequently used actions accessible via normal PushButtons. Move less frequently used actions ( e.g. "expert" actions ) into one or more MenuButtons. Don't nest the popup menus too deep - the deeper the nesting, the more awkward the user interface will be.
You can ( and should ) provide keybord shortcuts along with the button label as well as for any menu item.
`MenuButton( "button label", [ `item( `id( `doit ), "& Do it" ), `item( `id( `something ), "& Something" ) ] );
{
// Build a dialog with one menu button.
// Wait the user selects a menu entry,
// then close the dialog and terminate.
// Please note it's pretty pointless to create menu entries without an ID -
// you'd never know what entry the user selected.
UI::OpenDialog(
`MenuButton( "&Create",
[
`item(`id(`folder), "&Folder" ),
`item(`id(`text), "&Text File" ),
`item(`id(`image), "&Image" )
]
)
);
any id = UI::UserInput();
UI::CloseDialog();
y2milestone( "Selected: %1", id );
}
{
// Build a dialog with one menu button with a submenu.
// Wait the user selects a menu entry,
// then close the dialog and terminate.
// Please note it's pretty pointless to create menu entries without an ID -
// you'd never know what entry the user selected.
UI::OpenDialog(
`MenuButton( "&Create",
[
`item(`id(`folder), "&Folder" ),
`menu( "&Document",
[
`item(`id(`text), "&Text File" ),
`item(`id(`image), "&Image" )
]
)
]
)
);
any id = UI::UserInput();
UI::CloseDialog();
y2milestone( "Selected: %1", id );
}