我正在编写一个 Eclipse 插件,可以更轻松地编辑 Android 资源。当用户单击项目内的任何 XML 资源文件时,将打开一个编辑器,允许一次编辑项目中的所有资源。
我想添加在单独的默认 Android 资源编辑器中打开同一文件的功能。我知道该编辑器的 ID,但我无权访问其类。
调用 IDE.openEditor 不会执行任何操作,因为已经为该文件打开了一个编辑器,即使我指定了另一个 Android 编辑器的 ID。
如何强制 Eclipse 打开另一个编辑器来输入相同的内容?
另一方面,如果我只能访问它的 id 而不能访问它的类,是否可以在 MultiPageEditorPart 中嵌入另一个编辑器?
The IDE.openEditor
方法最后调用相应的IWorkbenchPage
打开编辑器的方法。
对您的情况有用的方法是org.eclipse.ui.IWorkbenchPage.openEditor(IEditorInput, String, boolean, int)
/**
* Opens an editor on the given input.
* <p>
* If this page already has an editor open that matches the given input
* and/or editor id (as specified by the matchFlags argument), that editor
* is brought to the front; otherwise, a new editor is opened. Two editor
* inputs are considered the same if they equal. See
* <code>Object.equals(Object)<code>
* and <code>IEditorInput</code>. If <code>activate == true</code> the editor
* will be activated.
* </p><p>
* The editor type is determined by mapping <code>editorId</code> to an editor
* extension registered with the workbench. An editor id is passed rather than
* an editor object to prevent the accidental creation of more than one editor
* for the same input. It also guarantees a consistent lifecycle for editors,
* regardless of whether they are created by the user or restored from saved
* data.
* </p>
*
* @param input the editor input
* @param editorId the id of the editor extension to use
* @param activate if <code>true</code> the editor will be activated
* @param matchFlags a bit mask consisting of zero or more of the MATCH_* constants OR-ed together
* @return an open editor, or <code>null</code> if an external editor was opened
* @exception PartInitException if the editor could not be created or initialized
*
* @see #MATCH_NONE
* @see #MATCH_INPUT
* @see #MATCH_ID
* @since 3.2
*/
public IEditorPart openEditor(final IEditorInput input,
final String editorId, final boolean activate, final int matchFlags)
throws PartInitException;
你需要调用它并传递它MATCH_ID | MATCH_INPUT
这样,在尝试确定是否应重用现有编辑器或应创建新编辑器时,会考虑编辑器 ID。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)