2013-03-13 85 views
1

如何在文本编辑器中打开perl脚本文件?Eclipse:在默认编辑器中打开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脚本在文本编辑器中打开?

回答

1

尝试类似这样的事情。它跳过getEditorId()(由openEditorOnFileStore())调用的默认编辑器的查找,并直接打开您选择的编辑器。

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

(胡乱猜测的代码,但希望应该工作)

+0

我没有单独的编辑器。我想在Eclipse中使用默认文本编辑器打开perl脚本。 – Jaison 2013-03-25 12:00:08

+0

“默认文本编辑器”取决于内容类型,通常由文件后缀确定。 – dreo 2013-03-25 13:26:30

+1

你能通过运行这个文件告诉我什么编辑器与你的文件相关联吗? 'PlatformUI.getWorkbench()。getEditorRegistry()。getDefaultEditor(your.perl.file).getId();' – dreo 2013-03-25 13:27:50

相关问题