Next, add the entries for each of the procedures created above to the code for the package module. For a package implemented as a module, new and relevant context-sensitive entries can be created inside the module's ModuleLoad export; this will cause the new context panel entries to be automatically created upon the first invocation or use of the package.
Before adding the entries for the procedures to the package module, make a copy of the current context panel. You can now freely customize the copied panel.
Note: The added entries will not be visible in the Maple context panel until you execute the Install command.
>
|
pCM := ContextMenu:-CurrentContext:-Copy():
|
Queries can be useful while determining when to show your context-sensitive items. New context panel entries can be configured so as to only appear under specific circumstances - such as when the package is loaded (using with).
Add a query to test if your package is loaded or not:
>
|
pCM:-Queries:-Add(
"Is MyPackage Loaded",
proc()
member( ':-MyPackage', packages() );
end proc);
|
The AddMultiple command adds multiple entries in one call:
>
|
pCM:-Entries:-AddMultiple(
[ "Square",
":-MyPackage:-squared(%EXPR)",
integer,
'helpstring'="Square the expression" ],
[ "Cube",
":-MyPackage:-cubed(%EXPR)",
integer,
'helpstring'="Cube the expression" ],
[ "Parse string",
":-MyPackage:-parsestring(%EXPR)",
string,
'helpstring'="Parse the string"],
'submenu'=["MyPackage"], #Add a sub-folder for MyPackage
'active'="Is MyPackage Loaded"); #the active option tests whether some condition is met( i.e. if "Is MyPackage loaded"? );
|
The Install command adds the entries to the context panel:
>
|
ContextMenu:-Install(pCM);
|
Next, load the package to activate the entries:
Finally, you can put this together in the original procedure, creating a package that contains its own context-sensitive panel code. In order for the context-sensitive code to be available when a package is run, it is required that the code for the actions are added to the ModuleLoad section of the module. If a ModuleLoad local or export is present, then this procedure is called when the module is read from the Maple repository in which it is located (in the code below, this is done manually by calling ModuleLoad() ).
When MyPackage is loaded, the ModuleLoad section is initialized, making the commands available in the context-sensitive system.
Thus, clicking on 3 now shows a submenu for "MyPackage" as well as several available commands.
>
|
:-MyPackage:-cubed((3.4));
|