在Eclipse RCP中,如何根据“脏”按钮禁用保存工具栏按钮。编辑中的财产 [英] In Eclipse RCP, how do I disable a save toolbar button according to the "dirty" property in editor

查看:92
本文介绍了在Eclipse RCP中,如何根据“脏”按钮禁用保存工具栏按钮。编辑中的财产的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的eclipse RCP 3.3应用程序中,我想根据当前编辑器脏标志

In my eclipse RCP 3.3 application, I would like to enable or disable a 'save' toolbar button according to current editor dirty flag.

我正在尝试使用< enabledWhen > tag但我无法使其正常工作。

I'm trying to use the <enabledWhen> tag but I can't make it work.

这是plugin.xml中代码的一部分:

Here's the portion of code in plugin.xml :

<command
 commandId="org.acme.command.save"
 icon="icons/save.png"
 id="org.acme.command.save"
 style="push">
 <enabledWhen>
    <instanceof value="activeEditor"/>
     <test property="dirty" value="true"/>
 </enabledWhen>
</command>

你知道这应该是怎么回事吗?

Do you have any idea how that is supposed to work ?

推荐答案

工作台提供对保存和全部保存操作的支持,因此您不需要像尝试那样自己实现它。

Support for the 'Save' and 'Save All' actions is provided by the workbench so you don't need to implement it yourself as you are trying to do.

建议的方法是在您的类中添加扩展ActionBarAdvisor的支持。确切的代码将取决于类的结构,但您需要的代码位如下。

The recommended way is to add the support in your class that extends ActionBarAdvisor. The exact code will depend on the structure of the class, but the bits of code you will need are as follows.

在您的字段声明中:

private IWorkbenchAction saveAction;
private IWorkbenchAction saveAllAction;

    saveAction = ActionFactory.SAVE.create(window);
    register(saveAction);

    saveAllAction = ActionFactory.SAVE_ALL.create(window);
    register(saveAllAction);

    IToolBarManager saveToolbar = new ToolBarManager(SWT.FLAT | SWT.RIGHT);
    saveToolbar.add(saveAction);
    saveToolbar.add(saveAllAction);
    coolBar.add(new ToolBarContributionItem(saveToolbar, "save"));   

工作台将负责启用和禁用。

The workbench will take care of the enabling and disabling for you.

如果您确实想要实现自己的代码来执行此操作,那么您所采用的方法将起作用。您将需要更正XML(例如,instanceof元素正在检查所选对象是否是一个名为'activeEditor'的类的实例,这可能不是预期的。)

If you do want to implement your own code to do this for whatever reason then the approach you are taking will work. You will need to correct the XML (for example, the instanceof element is checking that the selected object is an instance of a class called 'activeEditor', which is probably not what was intended).

这篇关于在Eclipse RCP中,如何根据“脏”按钮禁用保存工具栏按钮。编辑中的财产的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆