Eclipse:单击任何视图调用文件匹配策略

Eclipse: File matching strategy being called on single click of any view

我通过实现 IEditorMatchingStrategy 编写了我的自定义文件匹配策略,如下所示:

public class FileMatchingStrategy implements IEditorMatchingStrategy {

@Override
public boolean matches(IEditorReference editorRef, IEditorInput input) {
    if (!(input instanceof IFileEditorInput))
        return false;
    if (null == input || null == editorRef) {
        return false;
    }

    IFile file = input.getAdapter(IFile.class);
    IPath rawFilePath = file == null ? null : file.getRawLocation();
    if (null == rawFilePath) {
        return false;
    }
    if("File.java".equals(rawFilePath.toOSString())){
        MessageDialog.openError(Display.getDefault().getActiveShell(),
            "Header", "Message");
        return true;
    }

    return false;
} }

现在,无论何时单击任何视图(例如问题视图),都会调用文件匹配策略,这会导致弹出窗口显示,即使文件未通过双击打开也是如此。

是否可以过滤掉单击并仅处理来自项目资源管理器的双 clicks/Open 文件?

不,没有办法。

只要 IWorkbenchPage openEditorfindEditor 方法试图找到与给定编辑器输入匹配的编辑器,就会调用 IEditorMatchingStrategy。无法针对特定调用停止此操作。

IEditorMatchingStrategy 的主要用途是支持一次编辑多个文件的编辑器(例如 PDE 插件。xml/MANIFEST.MF/build.properties 编辑器)。

Eclipse 不期望 IEditorMatchingStrategy 进行任何 UI 交互。