In the development of eclipse plug-ins, commands are often used to declare and implement a menu. The specific steps are: 1. Declare a command; 2. Create a menu item using the command; 3. Create a handler corresponding to the command.
1. Declare a command through the org.eclipse.ui.commands extension point, and each command is a declaration of a ui function point.
Declare a category to manage your own commands:
id:cn.com.aquarion.category
name:MyCategory
description: My command's group
Declare a command to open the view:
id:com.aquarion.commands.openView
name:Open my view
categoryId :cn.com.aquarion.category
2. Create a menu item using the command through the org.eclipse.ui.menus extension point.
Declare a menuContribution, define the location where the command appears, and define its visibility
locationURI: menu:org.eclipse. ui.main.menu?after=additions; the location where the command will appear, this identifies the menu item as a new one and appears in the main menu bar
declare a menu label under menuContribution
: Fav
id:com.aquarion.menus.viewMenu
mnemonic:v; indicates that the keyboard accessibility
uses a command
commandId: com.aquarion.commands.openView under the menu, that is, the command
id triggered when the menu is selected: com.aquarion.menu. openView
mnemonic:O
icon: icon
After the above two steps, run the plugin to see that the menu items and menus have appeared in the main menu. If you need the menu item to appear in the toolbar, you can change the value of locationURI to toolbar:org.eclipse.ui.main.toolbar?after=additon.
This attribute identifies the location where the menu appears, so we can also use the menu we defined. Declare under the existing menu, for example, to create a new menu into the existing eclipse menu, the value of locationURI can be defined as follows:
menu:help?after=additions
menu:navigate?after=open.ext2
menu:window ?after=newEditor
menu:file?after=open.ext
As seen in the above example, locationURI is divided into three parts: scheme (scheme), such as menu:, identifier (identifier) such as: help and parameter list (argument list) such as after=additions
scheme identifies the type of UI object to which the new item will be added. It can be one of the following values:
menu: the program's main menu or view's drop-down menu
popup: the view's or editor's context menu
toolbar: the program's toolbar or view's tools Bar
Identifier (ID): For any view, this identifier matches one of its toolbar identifier or context menu identifier or drop down menu identifier. Commonly used are:
org.eclipse.ui.main.menu------------eclipse's main menu identifier
org.eclipse.ui.main.toolbar---------eclipse The main toolbar identifier
org.eclipse.ui.popup.any------------ any context menu
argument list: allows fine-grained definition of the location of new items. After and before are the layout of the new item, "=", and finally the identifier of an item in the menu, context menu or toolbar. The last identifier can also be additions, indicating that the new item is in the default position.
org.eclipse.ui.menus extension point
Guess you like
Origin http://10.200.1.11:23101/article/api/json?id=326929500&siteId=291194637
Recommended
Ranking