eclipse plugin development -menu

 

org.eclipse.ui.menus

 

locationURI

 

MenuContribution locationURI = “[Scheme]:[id]?[argument-list]”

 

1.menu or toolbar

2. problem view

popup:org.eclipse.ui.views.ProblemView?after=

 

org.eclipse.ui.main.menu?after=

org.eclipse.search.menu?dialogGroup

 

 

org.eclipse.ui.popupMenus

 

popup:org.eclipse.ui.views.ProblemView?after=additions

popup:org.eclipse.ui.popup.any?after=additions

 

 

steps:

 

1.extension from menus

2.the menu location in where

location url

 

How do you find the locationURI of menu contributions?

 

If you use ALT+SHIFT+F1 on the view, it will list the IDs of registered context menus

http://www.eclipse.org/pde/incubator/spy/

 

 

Tip: Subclass AbstractHandler rather than implementing IHandler.

 

menu ‘s handler

import org.eclipse.core.commands.AbstractHandler;

 

IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindowChecked(event);
        MessageDialog.openInformation(
                window.getShell(),
                "Demo",
                "Hello, Eclipse world");

 

 

Steps:

1. Add org.eclipse.ui.commands extension, create a command

2. Add org.eclipse.ui.menus extension, create a menuContribution

3. Add org.eclipse.ui.handlers extension, create a handler, command id point created in step 1 of the command, and to prepare for its implementation class

4. Create a step 3 in the activated state handler specified expression

Highlights:

1.

Q: When creating a new command, you need to specify whether catagory property?

A: It depends. I personally feel catagory menu is used for grouping. We can put together for example, a plug-in will generally provide their own menu to specify a single catagory, so that the display or processing

2.

Q: When creating a new command, whether you need to specify the name attribute?

A: name attribute is required, of course :-) specified when the corresponding menu does not specify label, displayed in the menu is the name of.

3.

Q: How menu of locationURI specified?

A: This is the first problem I encountered, because uri need to use a script written description, how to write a script? What are the rules of scripting? The answer lies in the help documentation that eclipse: http://help.eclipse.org/stable/index.jsp?topic=/org.eclipse.platform.doc.isv/guide/workbench_cmd_menus.htm

举例:popup:org.eclipse.debug.ui.DebugView?after=additions

This example can be seen uri 3 parts, the first part is a "popup", is representative of the right style pop-up menu; second part is "org.eclipse.debug.ui.DebugView", the meaning of which is displayed in the pop-up menu in view ; the third part is "after = additions", the meaning of what is displayed in the position of the pop-up menu (the menu there are other menu items pop up).

This is just one of the many uri writing, as well as adding items to the main menu, add an item to the toolbar, please refer to the specific circumstances of the help documentation link above.

Carried out here, the menu should already be displayed in the debug window, but which in turn raises the question: Every click on the menu, always report: The chosen operation is not enabled. This is because the direct handler implementation class implements an interface IHandler which isHandled, isEnabled method of eclipse by the automatically generated where all returns false, unless necessary under normal circumstances should inherit org.eclipse.core.commands.AbstractHandler way to write handler implementation class, can save a lot of trouble.

One should note that: in the plugin editor, click handler in the Properties panel "class" link, it will automatically create an implementation class, this class is not created automatically inherit AbstractHandler achieve, but direct implementation IHandler, I was so He was taken to the ditch.

Error issue is resolved, but found new menus can be displayed in the selected stack and have not selected a stack of cases, some of this is not appropriate, because if you want to copy a stack of information, at least there should be a check can. Therefore, measures should be taken to make this menu is grayed out in the absence of any information about the selected stack, which also leads to another framework difficult to understand: command core expression.

is a script command core expression rule, eclipse defines a number of variables, attributes, such as may be instanceof, equals determination of these and other variables, attributes core expression, to thereby obtain a boolean logic to participate in the program. To address this problem, we only need to specify enabledWhen expression (core expression) as the handler, so that when the handler has only selected pieces of information the stack can be activated.

core expression of documentation: http: //wiki.eclipse.org/Command_Core_Expressions in org.eclipse.ui.handlers extended declaration document also has a lot of information is available.

In this example we selection by counting variable to determine whether the stack information is selected. For details please refer to the plugin.xml file later in this article.

At this point, add the menu process is over, sounds simple, but involves many other technical applications, such as core expression, locationURI and so on. Other problems actually the same, continue to experience problems, continue to step on it flat, continue to accumulate, slowly, there will be a road at the foot.

Reproduced in: https: //www.cnblogs.com/alterhu/p/4032581.html

Guess you like

Origin blog.csdn.net/weixin_33755557/article/details/94029729