我正在尝试开发一个 Eclipse 插件,它将以键绑定(bind)命令的形式启动特定目标。
这是 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>
为了完整起见,下面是它在扩展 View 中的样子:
插件在我进行测试时有效;参数值在 ExecutionEvent
中可用。但是,该值未显示在首选项/键设置中:
为什么会这样?我需要做什么才能让 Eclipse 不仅显示名称 (target:
),还显示参数值(RunMe
和 RunMeAlso
在这种情况下)?
请注意,我使用的是 Eclipse SDK 版本:3.6.1,构建 ID:M20100909-0800。
最佳答案
定义 commandParameter 时,使用 values 元素提供 org.eclipse.core.commands.IParameterValues
。该类将命令参数中的信息映射到人类可读的标签。
请参阅 org.eclipse.ui.internal.registry.PerspectiveParameterValues
和 org.eclipse.ui.internal.registry.ViewParameterValues
作为示例,但基本上您返回的是标签到 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;
}
关于java - 为什么我的 Eclipse 插件 ICommand IParameter 的值没有出现在 Preferences/Keys 设置中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6085794/