【问题标题】:Open Eclipse Custom Editor file programmatically from file system从文件系统以编程方式打开 Eclipse 自定义编辑器文件
【发布时间】:2023-03-20 03:25:02
【问题描述】:

我正在使用我的自定义文本编辑器开发一个 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 方法中设置断点或记录一些内容,看看它是否到达这里。

标签: java eclipse eclipse-plugin eclipse-rcp


【解决方案1】:

尝试使用IDE.openEditor(...)

这个 Eclipse wiki 有更多相关信息:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-06-09
    • 2013-11-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-04-09
    相关资源
    最近更新 更多