简体   繁体   English

如何不使用IEditorPart来查找在Eclipse编辑器中打开的文件?

[英]How to find which file is open in eclipse editor without using IEditorPart?

I want to know which file (or even project is enough) is opened in eclipse editor? 我想知道在Eclipse编辑器中打开了哪个文件(甚至项目就足够了)? I know we can do this once we get IEditorPart from doSetInput method, 我知道一旦从doSetInput方法获取IEditorPart,我们就可以执行此操作,

IFile file = ((IFileEditorInput) iEditorPart).getFile();

But I want the name of file without using IEditorPart , how can I do the same? 但是我想要不使用IEditorPart的文件名 ,该怎么做?
Checking which is the selected file in project explorer is not of much help because, user can select multiple files at once and open all simultaneously and I did not way to distinguish which file opened at what time. 在项目浏览器中检查哪个是选定文件没有太大帮助,因为用户可以一次选择多个文件并同时打开所有文件,而我无法区分哪个文件在何时打开。
Adding more info: 添加更多信息:
I have an editor specified for a particular type of file, now every time it opens, during intializing editor I have some operation to do based on project properties. 我为特定类型的文件指定了一个编辑器,现在每次打开文件时,在初始化编辑器的过程中,我都会根据项目属性执行一些操作。
While initializing editor, I need the file handle (of the one which user opened/double clicked) or the corresponding project handle. 在初始化编辑器时,我需要文件句柄(用户打开/双击的那个)或相应的项目句柄。 I have my editor something this way: 我的编辑器是这样的:

public class MyEditor extends TextEditor{
    @Override
    protected void initializeEditor() {
        setSourceViewerConfiguration(new MySourceViewerConfiguration(
            CDTUITools.getColorManager(), store,
            "MyPartitions", this));
    }

    //other required methods

    @Override
    protected void doSetInput(IEditorInput input) throws CoreException {
        if(input instanceof IFileEditorInput)
        {
            IFile file = ((IFileEditorInput) input).getFile();
        }
    }
}

as I have done in the doSetInput() method , I want the file handle(even project handle is sufficient). 就像我在doSetInput()方法中所做的那样,我想要文件句柄(即使项目句柄就足够了)。 But the problem is in initializeEditor() function there is no reference to editorInput, hence I am unable to get the file handle. 但是问题是在initializeEditor()函数中没有对editorInput的引用,因此我无法获取文件句柄。
In the source viewer configuration file, I set the code scanners and this needs some project specific information that will set the corresponding rules. 在源查看器配置文件中,我设置了代码扫描器,这需要一些特定于项目的信息,这些信息将设置相应的规则。

You never have the guarantee (even with IFileEditorInput ) to know which files are "open" with editors. 您永远无法保证(即使使用IFileEditorInput )也不知道哪些文件已被编辑器“打开”。

There is even no definition of an "opened file" there are for example editors that show the contents of multiple files (like the Plug-In Manifest Editor from PDE). 甚至没有“打开的文件”的定义,例如,显示多个文件内容的编辑器(例如PDE的插件清单编辑器)。 Other editors show only the contents of a URI (which maybe local) 其他编辑器仅显示URI的内容( 可能是本地的)

Could you explain which problem you are trying to solve? 您能说明您要解决的问题吗?

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

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