简体   繁体   English

Eclipse:工具栏中的启用/禁用按钮

[英]Eclipse: enable/disable button in toolbar

In my plugin I created an editor and EditorActionBarContributor which adds some Actions to the editor. 在我的插件中,我创建了一个编辑器和EditorActionBarContributor,它向编辑器添加了一些动作。 I added the actions to the context menu of the editor programmatically. 我以编程方式将操作添加到了编辑器的上下文菜单中。 In the seletionChanged() I control which actions should be enabled in the context menu depending on the state of the editor, eg selections or the type of the file. seletionChanged()我根据编辑器的状态(例如选择或文件类型seletionChanged()控制应在上下文菜单中启用哪些操作。

Now I want to move those actions to the eclipse toolbar as well. 现在,我也想将这些动作移至Eclipse工具栏。 For this, I created an extension for the extension point org.eclipse.ui.editorActions and added an action for each action in the editor, with an IEditorActionDelegate for each action, which gets the correspondent action form the editor and runs it. 为此,我为扩展点org.eclipse.ui.editorActions创建了一个扩展,并为编辑器中的每个动作添加了一个动作,为每个动作添加了一个IEditorActionDelegate,从编辑器获取了对应的动作并运行它。

I want to control the enable/disable the buttons in the toolbar for these actions like I do in the editor, but I have no idea how I can do that. 我想像在编辑器中一样控制这些工具中工具栏上的启用/禁用按钮,但是我不知道该怎么做。 For example, I want a button to be only enabled if there is text selected in the editor. 例如,我希望仅在编辑器中选择了文本的情况下才启用按钮。

How can I do that? 我怎样才能做到这一点?

This is not a direct answer to your question, but I would consider using Eclipse commands instead. 这不是您问题的直接答案,但我会考虑改为使用Eclipse 命令 They are more cleanly separated so that you can have one place that indicates the command is enabled/disabled and then that automatically manifests in the menu/toolbar/bound keys, etc. 它们之间的分隔线更加清晰,因此您可以在一个位置指示该命令已启用/禁用,然后自动显示在菜单/工具栏/绑定键等中。

Also, Actions are effectively deprecated, as commands has been the preferred mechanism since about Eclipse 3.5. 此外,实际上不推荐使用Actions,因为自Eclipse 3.5以来,命令一直是首选的机制。

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

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