简体   繁体   English

从文件系统以编程方式打开Eclipse Custom Editor文件

[英]Open Eclipse Custom Editor file programmatically from file system

I am developing an Eclipse Plugin with my custom text editor. 我正在使用自定义文本编辑器开发Eclipse插件。

I need to open files programmatically inside this custom editor. 我需要在这个自定义编辑器中以编程方式打开文件。 When I open it using Eclipse's DefaultTextEditor, the file opens file and I am able to edit the text, etc. 当我使用Eclipse的DefaultTextEditor打开它时,文件打开文件,我可以编辑文本等。

But when I try to open the file using my editor, the editor turns up blank and is uneditable. 但是当我尝试使用我的编辑器打开文件时,编辑器显示为空白且无法编辑。 Here is the source that I am using. 这是我正在使用的来源。

    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();
    }

Thanks 谢谢

Try to use IDE.openEditor(...) . 尝试使用IDE.openEditor(...)

This Eclipse wiki has more information about this: 这个Eclipse wiki有关于此的更多信息:

http://wiki.eclipse.org/FAQ_How_do_I_open_an_editor_programmatically%3F http://wiki.eclipse.org/FAQ_How_do_I_open_an_editor_programmatically%3F

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

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