【问题标题】:Eclipse : Open perl file in default editorEclipse:在默认编辑器中打开 perl 文件
【发布时间】:2013-02-28 22:29:56
【问题描述】:

如何在文本编辑器中打开 perl 脚本文件?

好像现在我正在使用下面的代码在文本编辑器中打开文件

IWorkbenchPage page = Activator.getDefault().getWorkbench().getActiveWorkbenchWindow().getActivePage();
    IFileStore fileStore = EFS.getLocalFileSystem().getStore(new Path(path));
        try {
            IDE.openEditorOnFileStore(page, fileStore);
        } catch (PartInitException e1) {
            e1.printStackTrace();
        }

文本文件被正确打开,但 perl 脚本文件被执行。我认为它使用默认文件关联来打开文件。如何更改它以便在文本编辑器中打开我的 perl 脚本?

【问题讨论】:

    标签: eclipse editor eclipse-rcp rcp


    【解决方案1】:

    试试这样的。它绕过了在 getEditorId() 中查找默认编辑器(由 openEditorOnFileStore() 调用)并直接打开您选择的编辑器。

    String editorId = "some.editor.ID";
    IFileStore fileStore = EFS.getLocalFileSystem().getStore(new Path(path));
    page.openEditor(new FileStoreEditorInput(fileStore), editorId);
    

    (疯狂猜测代码,但希望应该可以工作)

    【讨论】:

    • 我没有单独的编辑器。我想在 Eclipse 中可用的默认文本编辑器中打开 perl 脚本。
    • “默认文本编辑器”取决于内容类型,通常由文件后缀确定。
    • 您能告诉我运行此文件与您的文件关联的编辑器是什么吗? PlatformUI.getWorkbench().getEditorRegistry().getDefaultEditor(your.perl.file).getId();
    • 感谢 dreo 的输入。我使用带有默认编辑器 ID 的上述代码,现在可以正常工作了。
    猜你喜欢
    • 2012-08-03
    • 2012-11-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-07-16
    • 2012-12-31
    • 1970-01-01
    • 2015-04-09
    相关资源
    最近更新 更多