如何强制为同一输入打开第二个编辑器? [英] How can I force a second editor to be opened for the same input?

查看:90
本文介绍了如何强制为同一输入打开第二个编辑器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写一个Eclipse插件,可以简化Android的资源编辑。当用户单击项目内的任何XML资源文件时,将打开一个编辑器,该编辑器允许立即编辑项目中的所有资源。

I'm writing an Eclipse plugin that allows easier resource editing for Android. When user clicks on any XML resource file inside the project, an editor opens that allows editing all the resources in the project at once.

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

I'd like to add a capability to open the same file in a separate, default Android resource editor. I know the id of that editor, but I don't have access to its class.

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

Calling IDE.openEditor does nothing, because an editor is already opened for that file, even though I specify the id of another, Android editor.

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

How to force Eclipse to open another editor for the same input?

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

On the other hand, is it possible to embed another editor in a MultiPageEditorPart if I have access only to its id, not its class?

推荐答案

IDE.openEditor 方法在最后调用相应的 IWorkbenchPage 方法以打开

The IDE.openEditor methods call at the end the corresponding IWorkbenchPage methods to open the editor.

在您的情况下可能有用的方法是
org.eclipse.ui.IWorkbenchPage.openEditor(IEditorInput,字符串,布尔值,整数)

The method that could be useful in your case is 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。

you need to call it and pass it MATCH_ID | MATCH_INPUT so that it takes the editor id into account when trying to determine whether the existing editor should be reused or a new one should be created.

这篇关于如何强制为同一输入打开第二个编辑器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆