ModuleContextMenu - Maple Help
For the best experience, we recommend viewing online help using Google Chrome or Microsoft Edge.

Online Help

All Products    Maple    MapleSim

Home : Support : Online Help : ModuleContextMenu


procedure that specifies context menu entries for a module


Calling Sequence



Calling Sequence

module() export ModuleContextMenu, ...; ... end module;

module() local ModuleContextMenu, ...; ... end module;



If a module m has an export or local named ModuleContextMenu, the result of the m[ModuleContextMenu](m) command is used to generate context menu entries in the context menu for m.


The value returned by ModuleContextMenu is interpreted as described below. If the value as a whole cannot be correctly interpreted according to these specification, then no extra context menu entries are generated.


A list of two strings represents one context menu entry. The first string is the text as it will appear in the context menu; the second string describes the action Maple takes if that entry is selected. If the name %EXPR occurs in the string, it is replaced by the selected module. The second string is parsed and evaluated as Maple code, in the global name space; there is no lexical scoping access.


In addition to these two strings, there can also be optional equations of the form helpstring = string or operator = TypeMK. These have the same function as in ContextMenu/CurrentContext/Entries/Add.


An equation of the form helpstring = string specifies the text that the user sees when the mouse cursor is positioned above this entry in a context menu while using the Standard worksheet with menu tips enabled.


An equation of the form operator = TypeMK specifies what 2D math transition should appear when working in document mode and performing context menu entries in-line.  The default value for this option is Typesetting:-mo("→") which is displayed as a right arrow . When customizing this it is recommended to use the template Typesetting:-mover(Typesetting:-mo("oper"),Typesetting:-mtext("text")) where oper should be an operator symbol, like → or =, and text should be a text description like transpose.  Most MathML operator symbols are supported as a choice for oper.  For example, setting operator to Typesetting:-mover(Typesetting:-mo("⇒"),Typesetting:-mtext("implies")) displays as implies.


A list where the first entry is a string and the second entry is a list represents a submenu. The string is the text as it will appear in the context menu to indicate the submenu. The elements of the list are interpreted as entries or submenus themselves.


Finally, the return value can be an expression sequence: the elements of that sequence should be lists as described above (either representing individual context menu entries, or representing submenus). The menu entries may be reordered: it is not guaranteed that they appear in the context menu in the order given, or indeed that they appear together.


Below is an implementation of a point in a 2D lattice.

LatticePoint := proc(x0 :: integer, y0 :: integer, $)
  return module()
    local x := x0, y := y0, ModuleContextMenu;
    export left, right, up, down, toList;

    left  := proc($) x := x - 1; return thismodule; end proc;
    right := proc($) x := x + 1; return thismodule; end proc;
    up    := proc($) y := y + 1; return thismodule; end proc;
    down  := proc($) y := y - 1; return thismodule; end proc;

    toList := proc($) [x, y]; end proc;

    ModuleContextMenu := proc(point)
      return ["Point operations", [["left",  "%EXPR:-left();"],
                                   ["right", "%EXPR:-right();"],
                                   ["up",    "%EXPR:-up();"],
                                   ["down",  "%EXPR:-down();"]]],
             ["Convert to List", "%EXPR:-toList();"];
    end proc;
  end module;
end proc:

We can now create lattice points as follows.







The context menus of AA and BB contain a submenu with four entries that come from the ModuleContextMenu procedure. (Note that the context menu entries will not be there until the definitions of AA and BB have been executed in the current Maple session.)

Since objects are also modules, the same system works for objects as well. Here, we have represented lattice points as objects.

LatticePoint2 := module()
  option object;
  local x, y,
    ModulePrint :: static, ModuleApply :: static, ModuleContextMenu :: static;
  export left :: static, right :: static, up :: static, down :: static,
    toList :: static;

  ModuleApply := proc(x0 :: integer, y0 :: integer, $)
    local result;
    result := Object(LatticePoint2);
    result:-x := x0;
    result:-y := y0;
    return result;
  end proc;

  ModulePrint := proc(self :: LatticePoint2, $)
    if self = LatticePoint2 then
      return LatticePoint2; # The original base object itself.
      return nprintf("<%d, %d>", self:-x, self:-y);
    end if;
  end proc;

  left  := proc(self :: LatticePoint2, $) self:-x := self:-x - 1; return self; end proc;
  right := proc(self :: LatticePoint2, $) self:-x := self:-x + 1; return self; end proc;
  up    := proc(self :: LatticePoint2, $) self:-y := self:-y + 1; return self; end proc;
  down  := proc(self :: LatticePoint2, $) self:-y := self:-y - 1; return self; end proc;

  toList := proc(self :: LatticePoint2, $) [self:-x, self:-y]; end proc;

  ModuleContextMenu := proc(self :: LatticePoint2, $)
    return ["Point operations",
      [["left", "left(%EXPR);", ':-helpstring' = "Move the point one unit to the left",
         ':-operator' = Typesetting:-mover(Typesetting:-mo("&rarr;"),Typesetting:-mtext("left"))],
       ["right", "right(%EXPR);", ':-helpstring' = "Move the point one unit to the right",
         ':-operator' = Typesetting:-mover(Typesetting:-mo("&rarr;"),Typesetting:-mtext("right"))],
       ["up", "up(%EXPR);", ':-helpstring' = "Move the point one unit up",
         ':-operator' = Typesetting:-mover(Typesetting:-mo("&rarr;"),Typesetting:-mtext("up"))],
       ["down", "down(%EXPR);", ':-helpstring' = "Move the point one unit down",
         ':-operator' = Typesetting:-mover(Typesetting:-mo("&rarr;"),Typesetting:-mtext("down"))]]],
    ["Convert to List", "toList(%EXPR);"];
  end proc;
end module:

The objects can now be created as follows.


<1, -1>



<0, -4>


Again, the context menus for CC and DD have entries determined by their ModuleContextMenu procedure.

See Also