| Project context menu [message #875451] |
Tue, 22 May 2012 15:22  |
Edwin Park Messages: 109 Registered: July 2009 |
Senior Member |
|
|
Hi,
I'm trying to figure out how to:
1. contribute a menu item command in the right-click context menu of a project in the Project Explorer view.
2. get access to the selected IProject in the command handler
I currently have a top-level menu/command/handler contributed via a fragment.e4xmi that uses the ESelectionService to determine if the selection holds an IProject. This is fine, but given that the command is really only related to a project, I'd like to be able to let the user right-click on the project itself and select the command from the project's context menu.
Any pointers/help is greatly appreciated!
Thanks,
Edwin
|
|
|
|
|
|
| Re: Project context menu [message #880144 is a reply to message #876978] |
Fri, 01 June 2012 10:17  |
Paul Webster Messages: 6813 Registered: July 2009 Location: Ottawa |
Senior Member |
|
|
Edwin Park wrote on Fri, 25 May 2012 12:08
@Execute
@Inject
public void execute(@Optional @Named(IServiceConstants.ACTIVE_SELECTION) IProject project) throws IOException {
if (project != null) {
IPath location = project.getLocation();
...
}
}
I think Sopot mentioned this, but your handlers shouldn't have any @Inject annotations in them. Everything should be requested in your @Execute method parameter list.
Quote:
I'm also still in the dark as to how to contribute a menu item to the right-click context menu for a project (my original question #1)...
To contribute to a popup menu, use an MMenuContribution added to the MApplication. It follows the same patterns as an org.eclipse.ui.menus menuContribution. There's also a visibleWhen attribute where you can add an MCoreExpression. The expression must still be defined in the org.eclipse.core.expressions.definitions extension point.
PW
Paul Webster
http://wiki.eclipse.org/Platform_Command_Framework
http://wiki.eclipse.org/Command_Core_Expressions
http://wiki.eclipse.org/Menu_Contributions
|
|
|
Powered by
FUDForum. Page generated in 0.08297 seconds