从文件系统中以编程方式打开Eclipse自定义编辑器文件

3
我正在开发一个带有自定义文本编辑器的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();
    }

谢谢


你确定你的编辑器可以处理这种输入类型吗?尝试在编辑器的“init”方法中设置断点或记录一些内容,看看它是否能够到达这里。 - Alexey Romanov
1个回答

4

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接