命令参数和菜单贡献参数有什么区别
我可以看到可以为使用命令扩展点定义的命令定义参数。我无法为这些命令参数定义值。
在定义菜单贡献时,我还可以在菜单扩展点的 Command 元素下定义参数。我可以在这里定义参数的值。
Command 中的命令参数与菜单贡献中的参数是否不同?如果它们不同,它们有何不同?
I can see that parameters can be defined for Commands defined using the Commands extension point. I can not define a value for these command parameters.
I can also define parameters under the Command element in the menus extension point when defining menu contributions. I can define a value for the parameter here.
Are the command parameters in Command different from parameters in menu contributions? If they are different how are they different?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
插件 org.eclipse.ui.command,让您为命令声明参数。当您向命令添加参数时,您必须为实现 IParameterValues 的参数设置 id、类型和可能值列表。
之后,您可以将此命令添加到带有参数及其值的菜单项。
例如,假设您有一个 id 为 org.rcp.commands.new 的命令。它定义了一个名为“type”的参数和可能的值(文件、项目和文件夹)。您将能够使用 commandId = "org.rcp.commands.new" 添加三个菜单项
对于每个参数
plugin.xml的示例
...
在此链接中查找更多信息:
http://blog.eclipse-tips .com/2008/12/commands-part-3-parameters-for-commands.html
The plugin org.eclipse.ui.command, Let you declare parameters for your commands. When you add parameter to your command, you have to set and id, type and a list of possible values for your parameter implementing IParameterValues.
After that, you can add this command to a menu item with parameters and its values.
For example, Imagine you have a command with id org.rcp.commands.new. And It's defined a parameter with name "type" and posible values (file, project and folder). You'll be able to add three menu item with commandId = "org.rcp.commands.new"
for each parameter
Sample of plugin.xml
...
Find more info in this link:
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)
。在这里,我们使用了相同的命令以及
header
参数的值。所以这是showName(header="所选资源是...")
。请注意,参数声明的
id
属性是参数 use 的name
属性...所以它是header
而不是标题
。The difference is basically the same as the declaration of a function argument -
func(int a)
and the specification of a named argument in a function call - e.g.func(a=1)
.Here is a small example that illustrates the difference between the two. The following declaration specifies a new command with with a single parameter. The parameter has both an
id
and aname
. Theid
is used later, whereas thename
is only used in a few views and can be disregarded here. So this is really justshowName(String header)
.Here we have a use of the same command with a value for the
header
argument. So this isshowName(header="The selected resource is....")
.Note that it is the
id
attribute of the parameter declaration that is thename
attribute of the parameter use... So it isheader
and notHeader
.