Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
625 views
in Technique[技术] by (71.8m points)

eclipse - How to add items in popup menu?

In eclipse plugin development, I want to add one item (eg: Mystyle ) in popup menu.

For an instance,

Project Explorer --> Right Click --> New --> MyStyle

How can I achieve this in eclipse plugin development?

Regards Mathan

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Something like this should do it (following this thread):

   <extension
         point="org.eclipse.ui.menus">
      <menuContribution
         locationURI=
         "popup:org.eclipse.ui.navigator.ProjectExplorer#PopupMenu?after=additions">
         <command
               commandId="myplugin.command.mycommand"
               icon="icons/etool16/mycommand.png"
               label="Run mycommand"
               mnemonic="M1+P"
               tooltip="Do something with this project">
         </command>
      </menuContribution>
   </extension>

See Menucontribution

Defines an ordered set of additions to the command UI structure. The defined elements will be added into the command UI structure at the location specified by the locationURI element.

This should be the starting point for all contributions into menus, toolbars or trim, wherever they occur in the UI.

  • locationURI - A URI specification that defines the insertion point at which the contained additions will be added.
    The format for the URI is comprised of three basic parts:
    • Scheme: One of "menu", "popup" or "toolbar.
      Indicates the type of the manager used to handle the contributions
    • Id: This is either the id of an existing menu, a view id or the id of the editor 'type'
    • Query: The query format is <placement>=<id> where: <placement> is either "before" or "after" and <id> is the id of an existing menu item

Show Readme Action

See also org.eclipse.ui.popupMenus, org.eclipse.ui.menus-extension point with a menuContribution that has its locationURI-attribute pointing to popup:org.eclipse.ui.popup.any?after=additions.
Warning, as Prashant Bhate mentions in the comment, that package org.eclipse.ui.popupMenus is deprecated.
See question Missing link between objectContribution and command for more.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...