RasterCommand.createGroup( eventHandler )

Creates a command group object. A command group object is a collection that holds command objects. All commands in the group have the same event handler.

The createGroup is a static method in the RasterCommand class, therefore it is invoked using RasterCommand class as follows:
:
var commands = RasterCommand.createGroup( myHandler );
 
The next code fragment illustrates how to create a command group, add commands, and reference the commands in it:
// create command group
var commands = RasterCommand.createGroup( myHandler )

// add commands to the group
// args:      id      icon           icon32  text
commands.add( "new",  ICONS16.PAGE,    null, "New" );
commands.add( "open", ICONS16.FOLDER,  null, "Open" );
commands.add( "save", ICONS16.FLOPPY,  null, "Save As..." );

// Disable the "save" command until there is something to save...
commands("save").setEnabled( false );

  :
In the code above, the commands variable behaves as an array, indexed by the commands id attribute. The only difference is that elements in a command group object are accessed using parenthesis "()" instead of square brackets "[]". The following lines show how to add the commands to a menu:
:
// create menu
var menu = new RasterMenu();

// Add commands to the menu
menu.add( commands("new") );
menu.add( commands("open") );
menu.add( commands("save") ); 
 
The signature of the add() method is the same as the RasterCommand constructor, minus the eventHandler argument:

commandGroup.add( id, icon, icon32, text, toolText, tooltip, keys );

The add() function returns the RasterCommand object just added to the command group collection, thus the following is also allowed:
:
commands.add("save", ICONS16.FLOPPY, null,
                               "Save As..." ).setEnabled(false);
 
The line above adds a "save" command and disables it in the same statement.

The command group is a convenient data structure used to store all the application's command objects in a single location. You can create many command groups, but in most cases one per web page is enough.

Parameters

Name Type   Description
eventHandler function pointer to the function that will receive notifications when commands in the group are executed.

Returns

Type Description
object A new command group object.
Home Examples Download License
 
Copyright © 2010-2017 Edwin R. López