开发者

Why isn't the value of my Eclipse plugin ICommand IParameter showing up in the Preferences/Keys setting?

开发者 https://www.devze.com 2023-03-07 07:38 出处:网络
I\'m trying to develop an Eclipse plugin that will launch specific targets as key-bindable commands. Here\'s the plugin.xml:

I'm trying to develop an Eclipse plugin that will launch specific targets as key-bindable commands.

Here's the plugin.xml:

<?xml version="1.0" encoding="UTF-8"?>
<?eclipse version="3.4"?>
<plugin>

   <extension point="org.eclipse.ui.commands">
      <category name="Custom Launcher" id="Eclipse_Keybound_Launch_Plugin.commands.category"/>
      <command
            categoryId="Eclipse_Keybound_Launch_Plugin.commands.category"
            defaultHandler="eclipse_keybound_launch_plugin.handlers.CustomLaunchCommandHandler"
            description="Launch/terminate then relaunch a custom target in debug mode"
            id="Eclipse_Keybound_Launch_Plugin.commands.terminateLaunch"
            name="Launch">
            <commandParameter
                  id="Eclipse Keybound Launch Plugin.launchTarget"
                  name="target"
                  optional="false"
            />
      </command>
   </extension>

   <extension point="org.eclipse.ui.bindings">
      <key  commandId="Eclipse_Keybound_Launch_Plugin.commands.terminateLaunch"
            schemeId="org.eclipse.ui.defaultAcceleratorConfiguration"
            contextId="org.eclipse.ui.contexts.window"
            sequence="M1+6">
            <parameter id="Eclipse Keybound Launch Plugin.launchTarget" value="RunMe"/>
      </key>
   </extension>

   <extension point="org.eclipse.ui.bindings">
      <key  commandId="Eclipse_Keybound_Launch_Plugin.commands.terminateLaunch"
            schemeId="org.eclipse.ui.defaultAcceleratorConfiguration"
            contextId="org.eclipse.ui.contexts.window"
       开发者_开发技巧     sequence="M1+7">
            <parameter id="Eclipse Keybound Launch Plugin.launchTarget" value="RunMeAlso"/>
      </key>
   </extension>

</plugin>

For completeness, here's how it looks like in the Extension view:

Why isn't the value of my Eclipse plugin ICommand IParameter showing up in the Preferences/Keys setting?

The plugin works when I put it to the test; the parameter value is available in the ExecutionEvent. However, the value is not shown in the Preferences/Keys setting:

Why isn't the value of my Eclipse plugin ICommand IParameter showing up in the Preferences/Keys setting?

Why is this the case? What do I need to do to have Eclipse show not just the name (target:) but also the values of the parameters (RunMe and RunMeAlso in this case)?

Note that I'm using Eclipse SDK Version: 3.6.1, Build id: M20100909-0800.


When you define your commandParameter, use the values element to provide a org.eclipse.core.commands.IParameterValues. That class is what maps the information in a command parameter to a human-readable label.

See org.eclipse.ui.internal.registry.PerspectiveParameterValues and org.eclipse.ui.internal.registry.ViewParameterValues as examples, but basically you are returning a map of label to ID:

public final Map getParameterValues() {
    final Map values = new HashMap();

    final IViewDescriptor[] views = PlatformUI.getWorkbench()
            .getViewRegistry().getViews();
    for (int i = 0; i < views.length; i++) {
        final IViewDescriptor view = views[i];
        values.put(view.getLabel(), view.getId());
    }

    return values;
}
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号