命令参数和菜单贡献参数有什么区别

问题描述:

我可以看到,可以为使用命令扩展点定义的命令定义参数。我无法为这些命令参数定义值。命令参数和菜单贡献参数有什么区别

当定义菜单贡献时,我还可以在菜单扩展点的Command元素下定义参数。我可以在这里为参数定义一个值。

Command中的命令参数与菜单贡献中的参数不同吗?如果他们不同,他们有什么不同?

插件org.eclipse.ui.command让你为你的命令声明参数。将参数添加到命令中时,必须为实现IParameterValues的参数设置ID,类型和可能值的列表。

之后,您可以将此命令添加到带有参数及其值的菜单项。

例如,假设您有一个id为org.rcp.commands.new的命令。它定义了一个名称为“type”和posible值(文件,项目和文件夹)的参数。您可以与commandId = “org.rcp.commands.new” 添加三个菜单项,每个参数的plugin.xml

样品 ...

查找该链接的详细信息: http://blog.eclipse-tips.com/2008/12/commands-part-3-parameters-for-commands.html

的差别是基本相同的函数参数的声明 - func(int a)和命名参数的函数调用规范 - 例如func(a=1)

下面是一个小例子,说明两者之间的区别。以下声明使用单个参数指定新命令。该参数有一个id和一个name。稍后将使用id,而name仅用于几个视图,可在此处忽略。所以这真的只是showName(String header)

<extension 
    point="org.eclipse.ui.commands"> 
<command 
    categoryId="com.rcpcompany.training.demo33.providers.ui.category.demoCommands" 
    description="Shows the name of the current resource" 
    id="com.rcpcompany.training.demo33.providers.ui.commands.showName" 
    name="&amp;Show Name"> 
    <commandParameter 
     id="header" 
     name=”Header“ /> 
</command> 
</extension> 

在这里,我们有一个使用相同的命令与header参数的值。所以这是showName(header="The selected resource is....")

<menuContribution locationURI="toolbar:org.eclipse.ui.main.toolbar"> 
<toolbar id="com.rcpcompany.training.demo33.providers.ui.toolbar1"> 
    <command 
     commandId="com.rcpcompany.training.demo33.providers.ui.commands.showName"> 
    <parameter 
     name="header" 
     value="The selected resource is...." /> 
    </command> 
</toolbar> 
</menuContribution> 

注意,它是参数声明是参数使用的name属性的id属性...所以它是header,而不是Header