![](/img/trans.png)
[英]Eclipse 4.7.1a - open file in editor from code/programatically
[英]Open Eclipse Custom Editor file programmatically from file system
我正在使用自定义文本编辑器开发Eclipse插件。
我需要在这个自定义编辑器中以编程方式打开文件。 当我使用Eclipse的DefaultTextEditor打开它时,文件打开文件,我可以编辑文本等。
但是当我尝试使用我的编辑器打开文件时,编辑器显示为空白且无法编辑。 这是我正在使用的来源。
File file = new File(filename);
IFileStore fileOnLocalDisk = EFS.getLocalFileSystem().getStore(file.toURI());
FileStoreEditorInput editorInput = new FileStoreEditorInput(fileOnLocalDisk);
IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
IWorkbenchPage page = window.getActivePage();
try {
// this works fine
page.openEditor(editorInput, "org.eclipse.ui.DefaultTextEditor");
// this is where the issue is
page.openEditor(editorInput, "MyEditor.editor");
} catch (PartInitException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
谢谢
尝试使用IDE.openEditor(...)
。
这个Eclipse wiki有关于此的更多信息:
http://wiki.eclipse.org/FAQ_How_do_I_open_an_editor_programmatically%3F
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.