2012-09-25 3 views
3

Android 용 리소스 편집을 쉽게 할 수있는 Eclipse 플러그인을 작성 중입니다. 사용자가 프로젝트 내부의 XML 리소스 파일을 클릭하면 프로젝트의 모든 리소스를 한꺼번에 편집 할 수있는 편집기가 열립니다.동일한 입력에 대해 두 번째 편집기를 강제로 열려면 어떻게합니까?

별도의 기본 Android 리소스 편집기에서 동일한 파일을 열 수있는 기능을 추가하고 싶습니다. 나는 그 편집자의 이드를 알고 있지만, 나는 그 수업에 접근 할 수 없다.

호출 IDE.openEditor는 다른 편집기의 ID 인 Android 편집기를 지정하더라도 해당 파일에 대한 편집기가 이미 열려 있기 때문에 아무 작업도 수행하지 않습니다.

Eclipse가 동일한 입력에 대해 다른 편집기를 열도록 강요하는 방법은 무엇입니까?

반면에 클래스가 아닌 ID에만 액세스 할 수 있다면 다른 편집기를 MultiPageEditorPart에 포함 할 수 있습니까?

답변

2

IDE.openEditor 메서드는 해당 IWorkbenchPage 메서드를 호출하여 편집기를 엽니 다.

귀하의 경우에 유용 할 수있는 방법은 당신이 결정하려고 할 때이 계정으로 편집기 ID를 소요 호출 등 MATCH_ID | MATCH_INPUT 그것을 전달해야 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; 

있는 기존 편집기할지 여부 재사용하거나 새로운 것을 만들어야합니다.

2

편집기 확장 지점 org.eclipse.ui.editors을 사용하면 matchingStrategy을 확장자에 추가 할 수 있습니다. 이렇게하면 Eclipse가 주어진 ID의 편집기와 주어진 편집기 입력이 이미 열려 있는지 여부를 판별하려고 할 때 동작에 영향을 줄 수 있습니다.

구현이 매우 쉽습니다. 인터페이스 org.eclipse.ui.IEditorMatchingStrategy의 구현 만 제공하면됩니다. 여기 false를 반환, 이클립스는 새로운 편집기마다 열립니다 경우는 에디터 ID 및 편집기 입력이 동일한 경우에도, 단 하나의 방법

boolean matches(IEditorReference editorRef, IEditorInput input); 

있습니다.

관련 문제