简体   繁体   English

根据Eclipse插件中视图的可见性使菜单条目可见吗?

[英]Make menu entry visible depending on visibility of view in Eclipse plugin?

I want to realize the following: 我想了解以下内容:

In my Eclipse plugin I have a menu entry (realized by adding a command to the plugin.xml and a handler class). 在我的Eclipse插件中,我有一个菜单项(通过在plugin.xml和处理程序类中添加命令来实现)。 Pressing the entry triggers some actions which depend on data shown in a view (also provided by the plugin). 按下条目会触发一些操作,这些操作取决于视图中显示的数据(也由插件提供)。

Now, if the view is closed, the actions can't be done. 现在,如果视图关闭,则无法执行操作。 I therefore think it would be good style to disable the menu entry when the view is not visible. 因此,我认为在视图不可见时禁用菜单项将是一种很好的样式。

I've found this article which descibes how to disable/enable menues, but I have no idea how to combine it with the visibility of the view. 我发现这篇文章描述了如何禁用/启用菜单,但是我不知道如何将其与视图的可见性结合起来。

Can someone help out with that? 有人可以帮忙吗?

Edit: I've solved my problem in a different way. 编辑:我已经以不同的方式解决了我的问题。 But greg's answer should usually solve this problem, as also stated in the official eclipse documentation: http://help.eclipse.org/mars/index.jsp?topic=%2Forg.eclipse.platform.doc.isv%2Fguide%2Fworkbench_cmd_expressions.htm 但是,greg的答案通常应该可以解决此问题,正如官方eclipse文档中所述: http ://help.eclipse.org/mars/index.jsp?topic=%2Forg.eclipse.platform.doc.isv%2Fguide%2Fworkbench_cmd_expressions 热媒

Use 采用

<with variable="activePartId">
    <equals value="part id"/>
</with>

in the 'enabledWhen', 'activeWhen', or 'visibleWhen' expression (depending on exactly where you are using the expression). 在“ enabledWhen”,“ activeWhen”或“ visibleWhen”表达式中(具体取决于您在哪里使用该表达式)。

For example to select when 'Project Explorer' is active: 例如,选择“项目浏览器”处于活动状态时:

<with variable="activePartId">
    <equals value="org.eclipse.ui.navigator.ProjectExplorer"/>
</with>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM