[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Newsgroup Home]
[news.eclipse.platform] Re: Contribute both a command Id plus an action implementation to another plugin.

Paul Webster wrote:
Once you get this far, you would use org.eclipse.ui.handlers to declaratively add a handler for the Navigator view.

You would set the handler element activeWhen clause to something like:
[xml]
<activeWhen>
  <with variable="activePartId">
    <equals value="org.eclipse.ui.views.ResourceNavigator"/>
  </with>
</activeWhen>
[/xml]


When you are executed you'll be able to retrieve the navigator view in your execute(*) method using:
IWorkbenchPart part = HandlerUtil.getActivePart(event);

I'm using 3.2. There doesn't appear to be a HandlerUtil in 3.2. So I'm doing,

        Object  ac = event.getApplicationContext ();
        if (! (ac instanceof IEvaluationContext)) {
            return null;
        }
        IEvaluationContext context = (IEvaluationContext)ac;
         ... = context.getVariable ("activePart");

You can also simply supply a default handler in your command definition (but you can only supply one).

Does that work in 3.2? It is documented in the 3.2 Help files but if I specify a default handler it never gets invoked. Never even gets constructed (I put a breakpoint in the constructor).


<command id="com.apex.ui.menu.compile.analyze"
	defaultHandler="com.action.TestHandler"
	name="%Button.analyze.name"
	description="%Button.analyze.tooltip"
	categoryId="com.ui.category.compile">
</command>

The org.eclipse.ui.handlers documention in 3.2 says "A handler that specifies no conditions is a default handler." But that doesn't work either. If I do this,

<handler commandId="com.ui.menu.compile.analyze"
class="com.action.TestHandler">
<!--
<activeWhen>
<with variable="activePartId">
<equals value="org.eclipse.ui.views.ResourceNavigator"/>
</with>
</activeWhen>
-->
</handler>
With the activeWhen commented out the handler is never invoked. With the activeWhen not commented out then the handler is invoked.


Is there perhaps a way to specify an activeWhen expression that is simply a constant TRUE literal? Looking at the documentation there doesn't seem to be a way.

	Gary