Next: Adding tool bar buttons, Previous: Adding new menus, Up: Customizing through XML and Python files
The actions can also be used to contribute new entries in the contextual menus everywhere in GPS. These menus are displayed when the user presses the right mouse button, and should only show actions relevant to the current context.
Such contributions are done through the <contextual>
tag, which takes
the following attributes:
"action" (mandatory)
If this attribute is set to an empty string, a separator will be inserted
in the contextual menu instead. If you specify a reference item with one of
the "before" or "after" attribute, the separator will be visible only when
the reference item is visible.
"before" (optional, default="")
<title>
child.
There is no guarantee that the new menu will appear just before the referenced
menu. In particular, it won't be the case if the new menu is created before
the reference menu was created, or if another later contextual menu indicates
that it must be displayed before the same reference item.
"after" (optional, default="")
If both "after" and "before" are specified, only the latter is taken into account.
It accepts one child tag, <Title>
which specifies the name of the
menu entry. If this child is not specified, the menu entry will use the name
of the action itself. The title is in fact the full path to the new menu entry.
Therefore, you can create submenus by using a title of the form
"Parent1/Parent2/Menu".
Special characters can be used in the title, and will be automatically expended based on the current context. These are exactly the ones described in the section for macros arguments, See Macro arguments.
The new contextual menu will only be shown if the filters associated with the action match the current context.
For instance, the following example inserts a new contextual menu which prints the name of the current file in the GPS console. This contextual menu is only displayed in source editors. This contextual menu entry is followed by a separator line, visible when the menu is visible
<?xml version="1.0" ?> <print> <action name="print current file name" > <filter module="Source_Editor" /> <shell>echo %f</shell> </action> <contextual action="print current file name" > <Title>Print Current File Name</Title> </contextual> <contextual action="" after="Print Current File Name" /> </print>