繁体   English   中英

打开文件以在Eclipse中的新窗口中进行编辑

[英]Open file for editing in new window inside Eclipse

我需要在Eclipse中使用文本编辑器打开文件。 我需要用一段代码来做到这一点。 我将文件名和文件路径存储在不同的变量中。 我怎样才能做到这一点 ? 谢谢 !

像这样:

// Get the current page

IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
IWorkbenchPage page = window.getActivePage();

// Get IFile

IPath path = new Path("workspace relative path");
IFile file = ResourcesPlugin.getWorkspace().getRoot().getFile(path);

// Open default editor for the file

IDE.openEditor(page, file, true);

如果您的文件不在当前工作空间中,则可以使用:

File file = new File("path to file");

IFileStore fileStore = EFS.getStore(file.toURI());

IDE.openEditorOnFileStore(page, fileStore);

一些编辑器可能不喜欢不在工作区中的文件。

要打开特定的编辑器,可以使用:

IDE.openEditor(page, file, "editor id");

例如,用于基本文本编辑器的org.eclipse.ui.DefaultTextEditor

暂无
暂无

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

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