RCP 4 切换工具栏中的按钮 [英] RCP 4 Toggle a button in the toolbar

查看:49
本文介绍了RCP 4 切换工具栏中的按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试执行以下操作:

I am trying to do the following:

  1. 在工具栏中创建一个按钮(已作为已处理工具项"完成)
  2. 点击按钮,让按钮看起来像是按下了一样(我阅读了一些关于使用 IAction.AS_CHECK_BOX 的内容,但我找不到任何关于如何执行此操作的明确 RCP 4 示例).当按钮被按下时,可以执行某个动作(为了这个例子,我们称之为动作 A")
  3. 再次点击按钮,让按钮看起来不再被按下.当按钮不再被按下时,可以执行不同的动作(为了这个例子,我们称之为动作 B")

一个更具体的例子是文本编辑器程序.假设工具栏有一个粗体"按钮.用户按下粗体"按钮,按钮图标现在看起来像是被按下了.此时,用户在文本区域中输入的所有内容都将以粗体显示.然后用户再次按下粗体"按钮,该按钮看起来不再像按下了一样.此时,用户在文本区域中输入的所有内容都是常规字体.

A more concrete example would be a text editor program. Let's say the toolbar has a 'Bold' button. The user presses the 'Bold' button and the button icon now looks like it has been pressed in. At this point, everything the user types into the text area will be in bold. The user then presses the 'Bold' button again and the button no longer looks like it is pressed in. At this point, everything the user types into the text area is in regular font.

我试过四处寻找,但找不到任何清楚地展示如何去做的例子.任何帮助将不胜感激!

I have tried searching around but cannot find any examples that clearly show how to do it. Any help would be appreciated!

推荐答案

当您将处理程序工具项"添加到 Application.e4xmi 中的工具栏时,您可以将类型"指定为检查"以获取按下的/不按行为.

When you add the 'Handler Tool Item' to the Toolbar in the Application.e4xmi you can specify the 'Type' as 'Check' to get the pressed / not pressed behavior.

在您的项目处理程序中,您可以注入MToolItem",以便您可以测试选中状态:

In your Handler for the item you can inject the 'MToolItem' so that you can test the checked state:

@Execute
public void execute(final MToolItem item)
{
  if (item.isSelected())
    ... button pressed in
  else
    ... button not pressed
}

这篇关于RCP 4 切换工具栏中的按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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