【问题标题】:Eclipse RCP: New Editor WizardEclipse RCP:新建编辑器向导
【发布时间】:2018-07-17 02:24:04
【问题描述】:

我对 Eclipse RCP - 3.X 有一点经验,我通过 org.eclipse.ui.editors 扩展点创建了我自己的编辑器,为了拥有该编辑器的多个实例,我像你一样实现了一个新的编辑器向导可以看下面;

IFile file = page1.createNewFile();

IWorkbenchWindow window = _workbench.getActiveWorkbenchWindow();
IWorkbenchPage page = window.getActivePage();
try {
    IDE.openEditor(page, file, SimpleEditor.ID, true);
} catch (PartInitException e) {
    e.printStackTrace();
}

我的问题是,我发现的唯一方法是创建一个新文件并将该文件与您唯一的编辑器 ID 相关联。我想要的是,我想将一些初始值(由用户定义)解析到向导中的编辑器。但是我们真的没有在这个过程中实例化 EditorPart 类。

我怎样才能做到这一点?

【问题讨论】:

  • 我希望有一个新的 File 向导而不是一个新的 Editor 向导,它使用初始值创建一个文件并打开该文件。然后编辑器从文件中读取初始值。
  • 您是说要将向导中的一些参数传递给编辑器吗?
  • 没错! @greg-449

标签: eclipse eclipse-plugin editor eclipse-rcp wizard


【解决方案1】:

IDE.openEditor 调用返回打开的 IEditorPart - 这将是您的编辑器类的一个实例,因此您可以这样做:

IEditorPart part = IDE.openEditor(page, file, SimpleEditor.ID, true);
if (part instanceof SimpleEditor) {
   SimpleEditor editor = (SimpleEditor)part;

   // TODO call methods you define in the editor to set the parameters
}

或者,您可以使用自定义 IEditorInput 并调用 IDE

openEditor(IWorkbenchPage page,
           IEditorInput input, String editorId)

方法。编辑器的init 方法被赋予您指定的IEditorInput

【讨论】:

  • 您好,我还有一个问题,如何在编辑器中收听变化? @greg-449
  • 请不要在 cmets 中提出新问题 - 提出新问题以便所有人都能看到。在任何情况下,您都需要提供更多详细信息,因为不清楚您在问什么。
猜你喜欢
  • 1970-01-01
  • 2011-01-13
  • 1970-01-01
  • 1970-01-01
  • 2014-05-13
  • 2018-04-22
  • 1970-01-01
  • 1970-01-01
  • 2013-04-12
相关资源
最近更新 更多