在 Eclipse 中禁用 TreeViewer 的 Alt+Enter

发布于 2024-11-16 13:34:45 字数 567 浏览 3 评论 0原文



我已经在 SWT 中的树中添加了一个按键侦听器,当我按 Alt+Enter 时,按键事件的状态为 keyCode = 65536 且 statemask = 0,而它应该是 keyCode='\r'和状态掩码=65536。
下面是我编写的代码片段 -

mViewer.getTree().addListener(SWT.KeyDown, new Listener() {
            @Override
            public void handleEvent(Event e) {
                if(e.keyCode == SWT.CR && e.stateMask == SWT.ALT) {
                    e.doit = false;
                }
            }
        });

Eclipse 工作台在将事件委托给组件中的侦听器之前过滤一些事件。有没有一种方法可以禁用 alt+enter 以不在其中一个树查看器上执行 eclipse 中的显示属性?

此致, 克沙夫

I have added a key listener to a tree in SWT and when i press Alt+Enter the state of the key event is keyCode = 65536 and statemask = 0, when it should have been keyCode='\r' and statemask=65536.
Below is the code snippet i have written-

mViewer.getTree().addListener(SWT.KeyDown, new Listener() {
            @Override
            public void handleEvent(Event e) {
                if(e.keyCode == SWT.CR && e.stateMask == SWT.ALT) {
                    e.doit = false;
                }
            }
        });

Eclipse workbench filters some of the events before delegating the events to the listeners in the components. Is there a way i can disable the alt+enter to not execute the show properties in eclipse on one of the treeviewers?

Best Regards,
Keshav

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(3

苄①跕圉湢 2024-11-23 13:34:45

您可以通过多种不同的方式覆盖特定查看器的特定全局命令:

  • 添加侦听器以过滤掉按键序列 - 尽管并不总是可行。
  • 添加一个 Display 过滤器来执行相同的操作 - 可以在查看器控件的焦点输入/输出处添加/删除过滤器。
  • 向应用程序添加新上下文并覆盖新上下文所需的键绑定 - 上下文在查看器控件上的焦点输入/输出处激活/停用

我更喜欢最后一个解决方案,因为我可以覆盖新上下文的特定键绑定使用普通绑定扩展点的任何插件的查看器...

You can override a specific global command for a specific Viewer is many different ways:

  • Add a listener to filter out the key sequence - though not always possible.
  • Add a Display filter to do the same - the filter can be added/removed at the focus in/out on the control of the Viewer.
  • Add a new context to the application and override the needed key bindings for the new context - the context is activated/deactivated at the focus in/out on the control of the Viewer

I prefer this last solution as I can override specific key bindings for the Viewer from any plug-in using the normal binding extension point...

嗼ふ静 2024-11-23 13:34:45

尝试以下代码:

mViewer.getTree().addKeyListener(new KeyAdapter() {
    @Override
    public void keyPressed(KeyEvent e) {
        if(e.keyCode == SWT.CR && e.stateMask == SWT.ALT) {
            // your code
            e.doit = false;
        }
    }
});

以及您需要的导入:

import org.eclipse.swt.events.KeyAdapter;
import org.eclipse.swt.events.KeyEvent;

Try the following code:

mViewer.getTree().addKeyListener(new KeyAdapter() {
    @Override
    public void keyPressed(KeyEvent e) {
        if(e.keyCode == SWT.CR && e.stateMask == SWT.ALT) {
            // your code
            e.doit = false;
        }
    }
});

And the imports you need:

import org.eclipse.swt.events.KeyAdapter;
import org.eclipse.swt.events.KeyEvent;
ぃ双果 2024-11-23 13:34:45

您将看到所有按键/按下事件 - 即使该键是状态键。所以第一个事件是 Alt 键按下...

顺序应该是:

  • KeyDown: stateMask=0 and keyCode=65536
  • KeyDown: stateMask=65536 and keyCode='\r'
  • KeyUp: stateMask= 65536 和 keyCode='\r'
  • KeyUp:stateMask=0 和 keyCode=65536

You will see all the key/down events - even if the key is a state key. So the first event is for the Alt key down...

The sequence should be:

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