[英]Control key + M on the keyboard triggers double-click functionality on Tree Items in SWT
I have a double-click functionality for the tree viewers wherein the tree items expand\\collapse when I double-click on them. 我有一个双击功能的树查看器,当我双击它们时,树项扩展\\折叠。 That is completely fine but the issue is that when I press CTRL+M on the keyboard even then the tree items expand\\collapse, I don't want this to happen.
这是完全没问题,但问题是,当我按下键盘上的CTRL + M时,即使然后树项扩展\\崩溃,我也不希望这种情况发生。 My code for double-clicking tree items is as follows:
我双击树项的代码如下:
private class DoubleClickListener implements IDoubleClickListener
{
@Override
public void doubleClick(final DoubleClickEvent event)
{
final IStructuredSelection selection = (IStructuredSelection)event.getSelection();
if (selection == null || selection.isEmpty())
return;
final Object sel = selection.getFirstElement();
final ITreeContentProvider provider = (ITreeContentProvider)treeViewer.getContentProvider();
if (!provider.hasChildren(sel))
return;
if (treeViewer.getExpandedState(sel))
treeViewer.collapseToLevel(sel, AbstractTreeViewer.ALL_LEVELS);
else
treeViewer.expandToLevel(sel, 1);
}
}
This behavior (CTRL+m expanding tree items) only happens When I use the IDoubleClickListener interface and override the method doubleClick(), but the same behavior (CTRL+m expanding tree items) does not happen when I use : addMouseListener(new MouseListener()) and override the method : mouseDoubleClick(). 此行为(CTRL + m扩展树项)仅在我使用IDoubleClickListener接口并覆盖方法doubleClick()时发生,但是当我使用时,不会发生相同的行为(CTRL + m扩展树项):addMouseListener(new MouseListener( ))并覆盖方法:mouseDoubleClick()。 Is the behavior (CTRL+m) expanding tree items related to IDoubleClickListener interface(If so what is the reason) or is this problem generic?
行为(CTRL + m)是否扩展了与IDoubleClickListener接口相关的树项(如果是这样的原因)或者这个问题是通用的吗? I feel it should not be related to IDoubleClickListener, Can someone please tell me why is there a difference in using these two logic?
我觉得它不应该与IDoubleClickListener有关,有人可以告诉我为什么使用这两个逻辑有什么不同?
Ctrl+M is often treated the same as the Return key. Ctrl + M通常与Return键相同。 The native tree control used by SWT usually treats Return as meaning expand / collapse the current tree node.
SWT使用的本机树控件通常将Return视为扩展/折叠当前树节点。
To stop this add a KeyListener
to the tree and suppress the unwanted key events: 要停止此操作,请将
KeyListener
添加到树中并禁止不需要的键事件:
treeViewer.getTree().addKeyListener(new KeyAdapter()
{
@Override
public void keyPressed(final KeyEvent event)
{
if (event.keyCode == SWT.CR ||
(event.keyCode == 'm' && event.stateMask == SWT.CTRL))
{
event.doit = false;
}
}
});
Update: 更新:
Use: 采用:
if (e.keyCode == 'm' && e.stateMask == (SWT.CTRL | SWT.SHIFT))
to test for Ctrl+Shift+m 测试Ctrl + Shift + m
if (e.keyCode == 'm' && e.stateMask == SWT.CTRL)
to test for Ctrl+m 测试Ctrl + m
if (e.keyCode == SWT.CR)
to test for Enter. 测试输入。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.