Creating Custom Context Menu Entries
|
You can customize the entries and actions on a context menu module using the ContextMenu package commands.
|
|
Note: On this help page, the custom context menu module is referenced by the name newCM.
|
|
Simple Entries
|
|
|
The simplest context configuration that can be created is a single entry with a command.
|
>
|
newCM:-Entries:-Add( "Increment the integer", "%EXPR + 1", integer );
|
|
This command adds a menu entry with the text label Increment the integer to the top-level context menu.
|
|
The second argument, , is a string that indicates the action to be performed if the associated menu entry is selected. The text serves as a placeholder for the object that the user clicks, and will be replaced by the value of this object if the associated entry is selected. For example, if a user right-clicks (for Macintosh, Control-clicks) the Maple integer 5, and selects Increment the integer from the context menu, the text 5 + 1 is inserted into the worksheet.
|
|
The third argument, integer, specifies that this menu entry appears only when the object that the user right-clicks (for Macintosh, Control-clicks) is of type integer.
|
|
Entries with Help Strings
|
|
|
You can optionally supply a help string for a menu entry. A help string is text, usually slightly longer than the text of the menu entry, that describes the action performed. It is displayed in a tooltip when the mouse pointer is positioned over the menu entry. For example:
|
>
|
newCM:-Entries:-Add( "Increment the integer", "%EXPR + 1", integer, helpstring="Increment the integer by 1" );
|
|
|
|
Submenus and Categories
|
|
|
When designing a menu system, it is recommended that you group together entries that are logically related, and impose a hierarchy on menu entries to avoid a single menu with an overwhelming number of entries. These two goals can be accomplished by using submenus and categories.
|
|
Submenus
|
|
|
A submenu is a context menu that is launched by clicking an entry in a context menu. Submenus are useful for grouping together a set of related entries.
|
|
When adding an entry to the context menu module, you can specify that this entry be placed in a submenu by using the submenu option.
|
>
|
newCM:-Entries:-Add( "To String", "convert(%EXPR, string)", Not(string), submenu=["Conversions"] );
|
|
|
Categories
|
|
|
You can group together related entries in the top-level context menu without placing the groupings in separate submenus. This can be achieved using categories.
|
|
When adding an entry to a context menu module, you can specify a category by using a Maple string. Entries in the top-level context menu that have identical categories are grouped together in the menu. A horizontal divider is drawn between entries of different categories.
|
|
Note: The category name is not displayed in the context menu.
|
|
Important: Categories can be used only in top-level menu entries, not submenu entries.
|
>
|
newCM:-Entries:-Add( "Factor Integer", "ifactor(%EXPR)", integer, category="Integers" );
newCM:-Entries:-Add( "Test Primality", "isprime(%EXPR)", integer, category="Integers" );
newCM:-Entries:-Add( "Floor", "floor(%EXPR)", {float, fraction}, category="Non-Integers" );
|
|
The Factor Integer and Test Primality entries are grouped together in the top-level menu, with a dividing line separating them from the Floor entry.
|
|
|
|