RasterCommand( id, icon, icon32, text, toolText, tooltip, keys, eventHandler )

Creates a command object. A command object defines an application function or action that can be executed by the user. Once a command is defined, it can be placed in the application's menus and toolbars so the user to execute them.

The eventHandler argument specifies the function to be invoked when a command is executed. When a command is executed, the command object is passed as argument to the event handler. The following code shows a typical command handler function:
function myHandler ( cmd )
{
     switch ( cmd.id )
     {
        case "save":    //do save...
                        break;
        case "open":    //do open...
                        break;
        case "new":     //do new document...
                        break;
        //etc...
     }
}
The next code fragment show how to create commands and adding them to a menu:
:
// Create an array with our commands
var cmds = [
  new RasterCommand( "id3", ICONS16.PAGE, null,
                       "New",  null, null, "Ctrl+N", myHandler ),

  new RasterCommand( "id2", ICONS16.FOLDER, null,
                       "Open", null, null, "Ctrl+O", myHandler ),

  new RasterCommand( "id1", ICONS16.FLOPPY, null,
                       "Save", null, null, "Ctrl+S", myHandler )
];

// Disable the save command until there is something
// to save...
cmds[2].setEnabled( false );

// create menu
var menu = new RasterMenu();

// Add commands to the menu
menu.add( cmds[0] );
menu.add( cmds[1] );
menu.add( cmds[2] ); 
 
The above code uses an array to store the commands the application will use in its UI. With this approach the code can become very verbose very fast. When working with a large amount of commands it is better to use commad group objects. See createGroup() for more details.

Parameters

Name Type   Description
id value A unique ID used to identify this command. Choose a short string code or integer constant that describes a function or action in the application.
icon string Either an URL of a 16x16 image, or an object that implements the IID_SPRITEINFO interface like the constants defined in ICONS16. This icon is used by menus and small/medium toolbars. Set to null if no 16x16 icon is needed. You don't need to set a 16x16 icons in commands aimed only at "large" toolbars.
icon32 string Either an URL of a 32x32 image, or an object that implements the IID_SPRITEINFO interface like the constants defined in ICONS32. This icon is used by "large" toolbars. If this value is null, the 16x16 icon is used (if any). You don't need to set a 32x32 icons in commands aimed menus or small/medium toolbars.
text string Text associated with this command. It is displayed next or below the command icon. Set to null if no text is desired.
toolText string Alternate text to be used when the command is displayed in a toolbar. This is usually a shorter version of the text argument used to prevent the toolbar buttons from growing too wide. Set to null to use the default text.
tooltip string Text that popup when the mouse pointer sits still over a toolbar button. This text can be used to "hint" the user detail information about what the command does. Set null is no tooltip is desired. This text is used by toolbars only.
keys string This is a label shown next to the menu option used to show the keyboard shortcut (or keys) the user can press in keyboard to execute this command, for example: "Alt+1", "Ctrl+Shift+K", etc. Note this is a "display-only" label and no actual key binding are stablished by the library. The programmer must process the keyboard events separately. This feature is intended for SWT/embedded-mozilla or XUL applications where there is better keyboard control. Set to null if no shortcut keys are supported.
eventHandler function pointer to a function used to receive notification when this command is executed.

See Also

Home Examples Download License
 
Copyright © 2010-2017 Edwin R. López