How to make the second editor open for one input?

I am writing an Eclipse plugin that makes it easy to edit resources for Android. When the user clicks on any XML resource file inside the project, an editor opens that allows you to immediately edit all the resources in the project.

I would like to add the ability to open the same file in a separate default Android resource editor. I know the identifier of this editor, but I do not have access to its class.

Calling IDE.openEditor does nothing, because the editor is already open for this file, although I specify the identifier of another Android editor.

How to get Eclipse to open another editor for the same login?

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

+4
source share
2 answers

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

A method that may be useful in your case: 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; 

you need to call it and pass it MATCH_ID | MATCH_INPUT MATCH_ID | MATCH_INPUT so that it MATCH_ID | MATCH_INPUT into account the identifier of the editor when trying to determine whether to reuse an existing editor or create a new one.

+3
source

The org.eclipse.ui.editors editor extension point allows you to add matchingStrategy to the extension. This allows you to influence the behavior when Eclipse tries to determine if the editor of a given identifier and the input of this editor are open.

The implementation is pretty simple. You need to provide an implementation of the org.eclipse.ui.IEditorMatchingStrategy interface. It has only one method.

 boolean matches(IEditorReference editorRef, IEditorInput input); 

If you return false here, Eclipse will open a new editor every time, even if the editor ID and editor input are equal.

+2
source

Source: https://habr.com/ru/post/1436251/


All Articles