DataView.AppendActionMenuItem

Prototypes

void AppendActionMenuItem( String sItem, String sCode )

Parameters

String sItem
The new menu item.

String sCode
One or more IMLPlus statements that will be executed when the menu item is invoked. If sCode is an empty string, a separator (a horizontal line) is appended to the menu.

Remarks

This method appends a new item to the end of the action menu. To display the action menu for a DataView, press the F11 key while the DataView window is active. Choosing an item on the action menu executes the IMLPlus statements associated with that item.

You can create a cascading menu by embedding newline characters (\n) in the string. For example:

"Cascade\nMenu Item"J

Each newline character will result in a new cascading menu. Note that the J suffix after the closing double quotation mark informs IMLPlus that it should process the string for embedded special characters. Normally, IMLPlus treats text strings literally.

To define a shortcut key, type an ampersand (&) before a letter. For example, if you define the menu item "&My Item", you can choose that menu item by pressing the "m" key when the menu is displayed. Make sure all the shortcut keys on a menu are unique.

The statements in sCode may contain string literals. To include a string literal in sCode, you must enclose the literal in either single or double quotation marks. If you choose to use double quotation marks, you must prefix each quotation mark with a backslash (\) and place a J suffix after the string. For example, to print the word "Hello" you could use either of the following:

sCode = "print 'Hello';";
sCode = "print \"Hello\";"J;

If the IMLPlus program has finished running when an action menu item is invoked, the statements associated with the menu item are executed in the program’s main environment. Therefore, the statements can use any variables that are global in scope. If the program is paused when an action menu item is invoked, the statements are executed in the environment of the PAUSE statement.

Example
declare DataObject dobj;
dobj = DataObject.CreateFromFile( "business" );

declare ScatterPlot plot;
plot = ScatterPlot.Create( dobj, "Sales", "Profits" );
plot.SetMarkerSize( 5 );
plot.SetObsLabelVar( "Company" );

plot.AppendActionMenuItem( "Color Code\nBy &Nation"J,
    "run BusinessColorCode( plot, 'Nation' );" );

plot.AppendActionMenuItem( "Color Code\nBy &Industry"J,
    "run BusinessColorCode( plot, 'Industry' );" );

/* color code business data set by Nation or Industry
   and display legend on plot */
start BusinessColorCode( Plot plot, variable );
if variable='Nation' then do;
    colors = RED||GREEN||YELLOW||WHITE||BLUE;
    labels = {"Britain", "France", "Germany", "Japan", "USA"};
    end;
else if variable = 'Industry' then do;
    colors = RED||YELLOW||GREEN||BLACK;
    labels = {"Automobiles", "Electronics", "Food", "Oil"};
    end;

run ColorCodeObs( plot.GetDataObject(),
    variable, IntToRGB(colors), ncol(colors) );
plot.DrawRemoveCommands();
run DrawLegend( plot, labels, 8, colors, 0, -1, -1, 'IRB' );
finish;
/* Press F11 in the plot window to see the menu. */
See Also

DataView.AppendActionMenuItemToGroup
DataView.AppendActionMenuSeparator
DataView.InsertActionMenuItem