谁能告诉我如何从编辑器获取文件名?Eclipse 3.5:如何从编辑器获取文件名?
我刚做了我自己的编辑器打开xml文件并创建了 几个部分来显示数据。现在我想读取 XML文件,并将其放入该部分。
我想我现在如何读取xml数据但我不知道 如何访问文件名以便它可以打开。
感谢
谁能告诉我如何从编辑器获取文件名?Eclipse 3.5:如何从编辑器获取文件名?
我刚做了我自己的编辑器打开xml文件并创建了 几个部分来显示数据。现在我想读取 XML文件,并将其放入该部分。
我想我现在如何读取xml数据但我不知道 如何访问文件名以便它可以打开。
感谢
可能是在你casre
投编辑器输入
IFileEditorInput
this approach可能是有用的,并使用IFile
调用getLocation()
或getLocationURI()
。
至于说here,基本上
((IFileEditorInput)editorInput).getFile().getLocation()
就足够了。
也this code参见:
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;
}
我意识到这是旧的,但因为我偶然发现了它,而寻找解决的办法,以完全相同的问题,我想,把注释添加到答案VonC:
IFileEditorInput
隐藏在org.eclipse.ui.ide插件,所以为了解决工作中的插件需要指出的依赖。
感谢matthias:D – Iso 2011-02-09 23:37:34
感谢您的代码,但我在IFileEditorInput上出错。 它说IFileEditorInput不能解析为一个类型。 也有适合快速修复的解决方案。 – Iso 2009-06-03 23:21:56