Eclipse 3.5:如何从编辑器获取文件名? [英] Eclipse 3.5: How to get file name from Editor?

查看:107
本文介绍了Eclipse 3.5:如何从编辑器获取文件名?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

任何人都可以告诉我如何从编辑器获取文件名?

Can anyone tell me how to get file name from editor?

我只是自己编辑打开xml文件并创建
a几个部分来显示数据。现在我想读取
的XML文件并将其放在该部分。

I just made my own editor to open xml file and create a few section to display the data. Now I want to read the XML file and place it inside the section.

我想我现在如何读取xml数据,但是我不知道
如何访问文件名,以便可以打开。

I think I now how to read xml data but I don't know how to access the file name so that it can be open.

谢谢

推荐答案

可以此方法可以在您的casre中使用

May be this approach could be useful in you casre


将编辑器输入投射到 IFileEditorInput 并使用 IFile 调用 getLocation() getLocationURI()

正如这里,基本上


((IFileEditorInput)editorInput)。 getFile()。getLocation()是足够的。

另请参见此代码

public static String getCurrentFileRealPath(){
        IWorkbenchWindow win = PlatformUI.getWorkbench
().getActiveWorkbenchWindow();

        IWorkbenchPage page = win.getActivePage();
        if (page != null) {
            IEditorPart editor = page.getActiveEditor();
            if (editor != null) {
                IEditorInput input = editor.getEditorInput();
                if (input instanceof IFileEditorInput) {
                    return ((IFileEditorInput)input).getFile
().getLocation().toOSString();
                }
            }
        }
        return null;
}

这篇关于Eclipse 3.5:如何从编辑器获取文件名?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆