简体   繁体   English

命令转到同级 SWT 控件

[英]Commands go to sibling SWT control

For Bndtools, I've created a subclass of PackageExplorerPart and added a (staggeringly useful) search Text control.对于 Bndtools,我创建了 PackageExplorerPart 的子类并添加了一个(非常有用的)搜索文本控件。

However, when the Text control is selected/in focus, and I paste, the pasted content goes to the TreeView and creates a snippet project, very annoying.但是,当 Text 控件被选中/处于焦点时,我粘贴时,粘贴的内容会转到 TreeView 并创建一个片段项目,非常烦人。

I debugged the code but can only find that a PASTE Command handler is always going to the TreeView and not to the control in focus.我调试了代码,但只能发现 PASTE 命令处理程序总是转到 TreeView 而不是焦点控件。 Unfortunately, I cannot find where this is configured.不幸的是,我找不到它的配置位置。 I tried understanding the documentation but could not figure out where to look.我试图理解文档,但不知道在哪里看。

So basically I need to know how to make sure my Text component always is the target of the PASTE handler.所以基本上我需要知道如何确保我的 Text 组件始终是 PASTE 处理程序的目标。

搜索字段演示

Any workbench part in Eclipse gets a chance to register global action handlers via either the IViewSite or IEditorSite getActionBars() method. Eclipse 中的任何工作台部件都有机会通过IViewSiteIEditorSite getActionBars()方法注册全局操作处理程序。 If you subclass another part, you would need to make sure that after the super class has registered its handlers you reassign whatever actions you wish with your own handlers.如果您对另一部分进行子类化,则需要确保在超类注册其处理程序后,您可以使用自己的处理程序重新分配您希望的任何操作。

So in your case, when you want to redirect the 'paste' to your Text control, you could do something like this:因此,在您的情况下,当您想将“粘贴”重定向到 Text 控件时,您可以执行以下操作:

IActionBars actionBars = getViewSite().getActionBars();

IAction originalPaste = actionBars.getGlobalActionHandler(ActionFactory.PASTE.getId());

actionBars.setGlobalActionHandler(ActionFactory.PASTE.getId(), new Action() {
    @Override
    public void runWithEvent(Event event) {
        Text filterText = filterPart.getFilterControl();
        if (Objects.equals(event.widget, filterText)) {
            filterText.paste();
        } else {
            originalPaste.runWithEvent(event);
        }
    }
});

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

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