为什么我的 Eclipse 插件 ICommand IParameter 的值没有显示在 Preferences/Keys 设置中?

发布于 2024-11-08 13:54:13 字数 2289 浏览 0 评论 0原文

我正在尝试开发一个 Eclipse 插件,它将以可键绑定命令的形式启动特定目标。

这是 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>

为了完整起见,它在扩展视图中的样子如下:

enter image此处描述

当我对其进行测试时,该插件可以正常工作;参数值在ExecutionEvent中可用。但是,该值未显示在“首选项/键”设置中:

在此处输入图像描述

为什么会出现这种情况?我需要做什么才能让 Eclipse 不仅显示名称 (target:),还显示参数的值 (RunMeRunMeAlso在这种情况下)?

请注意,我使用的是 Eclipse SDK 版本:3.6.1,构建 ID:M20100909-0800。

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:

enter image description here

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:

enter image description here

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

空袭的梦i 2024-11-15 13:54:13

定义 commandParameter 时,使用 values 元素提供 org.eclipse.core.commands.IParameterValues。该类将命令参数中的信息映射到人类可读的标签。

请参阅 org.eclipse.ui.internal.registry.PerspectiveParameterValues 和 org.eclipse.ui.internal.registry.ViewParameterValues 作为示例,但基本上您返回的是标签映射至身份证:

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;
}

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;
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文