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

发布于 2024-10-08 18:54:30 字数 157 浏览 0 评论 0原文

我可以看到可以为使用命令扩展点定义的命令定义参数。我无法为这些命令参数定义值。

在定义菜单贡献时,我还可以在菜单扩展点的 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 技术交流群。

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

发布评论

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

评论(2

楠木可依 2024-10-15 18:54:30

插件 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

辞别 2024-10-15 18:54:30

区别基本上与函数参数的声明 - func(int a) 和函数调用中命名参数的规范 - 例如 func(a=1) 相同代码>.

这是一个小例子,说明了两者之间的区别。以下声明指定带有单个参数的新命令。该参数同时具有 idnameid 稍后会使用,而 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="&Show Name">
    <commandParameter
        id="header"
        name=”Header“ />
</command>
</extension>

在这里,我们使用了相同的命令以及 header 参数的值。所以这是 showName(header="所选资源是...")

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

请注意,参数声明的 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 a name. The id is used later, whereas the name is only used in a few views and can be disregarded here. So this is really just 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="&Show Name">
    <commandParameter
        id="header"
        name=”Header“ />
</command>
</extension>

Here we have a use of the same command with a value for the header argument. So this is 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>

Note that it is the id attribute of the parameter declaration that is the name attribute of the parameter use... So it is header and not Header.

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