Skip to main content

Notice: This Wiki is now read only and edits are no longer possible. Please see: for the plan.

Jump to: navigation, search

Menu Contributions/TextEditor viewerContribution

Text editor popup action

Popups can be targetted at any registered context menu, or at all of them. This is the Scramble Text command to be added the the standard text editor context menu.


First define the command and its handler.

<extension point="org.eclipse.ui.commands">
    <command id="org.eclipse.ui.examples.menus.scramble.text"
            description="%ScrambleText.description" />


Placing the action (which is specifically a menu or button linked to a command) can be accomplished with the org.eclipse.ui.menus extension point.

<extension point="org.eclipse.ui.menus">
    <menuContribution locationURI="popup:#TextEditorContext?after=additions">
        <command commandId="org.eclipse.ui.examples.menus.scramble.text"
                icon="$nl$/icons/full/eobj16/scramble.gif" />

Menus API

Programmatically do this, you would have to go through the IMenuService.

public static void addTextMenuContribition() {
    final IMenuService menuService = (IMenuService) PlatformUI
    final ImageDescriptor scrambleIcon = AbstractUIPlugin
    AbstractContributionFactory factory = new AbstractContributionFactory(
            "popup:#TextEditorContext?after=additions") {
                public void createContributionItems(IMenuService menuService,
                        List additions) {
                    CommandContributionItem item = new CommandContributionItem(
                            null, scrambleIcon, null, null, null, "c", null,
                public void releaseContributionItems(IMenuService menuService,
                        List items) {

Back to the top