gpt4 book ai didi

eclipse - 如何强制为相同的输入打开第二个编辑器?

转载 作者:行者123 更新时间:2023-12-02 11:37:23 25 4
gpt4 key购买 nike

我正在编写一个 Eclipse 插件,可以更轻松地为 Android 进行资源编辑。当用户单击项目内的任何 XML 资源文件时,将打开一个编辑器,允许一次编辑项目中的所有资源。

我想添加在单独的默认 Android 资源编辑器中打开同一个文件的功能。我知道该编辑器的 ID,但我无权访问它的类。

调用 IDE.openEditor 没有任何作用,因为已经为该文件打开了一个编辑器,即使我指定了另一个 Android 编辑器的 ID。

如何强制 Eclipse 为相同的输入打开另一个编辑器?

另一方面,如果我只能访问它的 id 而不是它的类,是否可以在 MultiPageEditorPart 中嵌入另一个编辑器?

最佳答案

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。

关于eclipse - 如何强制为相同的输入打开第二个编辑器?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12592365/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com