2012-02-19 4 views
12

내 Eclipse 플러그인에서 화면에 표시되는 편집기가 변경된시기를 알아야합니다. 이 녹색 버튼을 계속하는 경우를 제외하고 대부분의 경우 작동이클립스 플러그인에서 "활성 편집기"를 얻는 방법?

PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor() 

을 누를 때 :

Debugger buttons

내가 다음 활성화 F8 바로 가기를 사용하는 경우 다음과 같이 저는 현재 활성 편집기를 얻고있다 편집기가 예상대로 업데이트됩니다.

활성 편집기 속성은 편집기 탭이 포커스를받을 때까지 (계속 단추를 누를 때 발생하지 않음) 업데이트됩니다.

"보이는 편집기"를 사용하기 위해 취할 수있는 다른 경로가 있습니까?

미리 감사드립니다.

앨런

+0

아래의 설명에서 사용자의 플러그인은 기존 디버그 플러그인의 _extension_이라고 가정합니다. 옳은? –

+0

디버그 플러그인의 확장 기능이 아니지만 중단 점 등에 대한 다양한 디버그 이벤트에 연결됩니다. –

답변

2
  1. 그렇게 당신이 얻고있는 것은 API로 바로 출력, 포커스가있을 경우에만 편집자가 활성화됩니다. 플러그인의 사용자는 다음 작업을 수행 할 수 있습니다 열려있는 모든 편집기를 얻기 위해,
  2. 또는 최종 사용자에 대한 우려를 디버그 모드로 실행 해하지 않습니다 :

PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getEditorReferences()

+0

답장을 보내 주셔서 감사합니다. 필자는 실제로 Eclipse 사용자가 디버거를 실행하는 사용자를 언급 했으므로 최종 사용자에게는 문제가됩니다. –

+0

코드에서 중단 점이 있으므로 실행이 그 시점에서 멈추는 경우는 거의 없습니다. – codejammer

+0

나는 사용자의 코드에 대해 말하고있다. 사용자가 코드에서 디버거를 단계별로 실행하고 싶습니다. 이 특정 시나리오는 내가 원했던 것처럼 작동하지 않습니다. 보이는 편집기에 액세스 할 수 있다면 처리 할 수 ​​있습니다. –

1

IWorkbenchPage interface has an isPartVisible()`지정된 부품이 보이는지를 나타내는 메소드. 결과는 지정된 부품이 현재 활성화되어 있는지 또는 포커스가 있는지 여부에 달려 있지 않습니다.

현재 보이지는 않지만 현재 활성화되지 않은 편집기를 찾으려면 활성 워크 벤치 페이지에서이 메서드를 호출하기 만해도 충분하지 않을 수 있습니다. 대신 모든 워크 벤치 창을 반복하고 각각의 페이지에서 편집기의 가시성을 점검해야 할 수도 있습니다.

1

활성 편집기 목록에서 더 많은 정보를이 질문 방문하십시오 :

Eclipse RCP : have the same editor open in editor window


패키지 이름 : rcp_demo.Editor

클래스 이름 : EmpCommand.java, EmployeeEditor을. java 및 EmployeeEditorInput.java

package rcp_demo.Editor; 

import org.eclipse.core.commands.AbstractHandler; 
import org.eclipse.core.commands.ExecutionEvent; 
import org.eclipse.core.commands.ExecutionException; 
import org.eclipse.ui.IEditorReference; 
import org.eclipse.ui.IWorkbenchPage; 
import org.eclipse.ui.IWorkbenchWindow; 
import org.eclipse.ui.PartInitException; 
import org.eclipse.ui.handlers.HandlerUtil; 

public class EmpCommand extends AbstractHandler { 
    public static final String Id = "rcp_demo.Editor.EmpCommand"; 

    @Override 
    public Object execute(ExecutionEvent event) throws ExecutionException { 

     IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindow(event); 
      IWorkbenchPage page = window.getActivePage(); 
      IEditorReference[] editors = page.getEditorReferences(); 
      EmployeeEditorInput input = new EmployeeEditorInput(); 
      //All Comments are easily understand 
      //public class EmployeeEditorInput implements IEditorInput{} 
      for (int i=0; i<editors.length; i++) { 
      //List out all Exist editor 
      //compare with EmployeeEditor.Id="rcp_demo.Editor.emp"; 
       if (editors[i].getId().equals(EmployeeEditor.Id)) { 
       //public class EmployeeEditor extends EditorPart 
       //{ 
       // public static final String Id="rcp_demo.Editor.emp"; 
       //  public void createPartControl(Composite parent) {.....} 
       //} 
        page.activate(editors[i].getEditor(true)); 
        System.out.println("set focus an existing editor(Employee)"); 
        return null; 
       } 
      } 
      try { 
       //open new Editor like EmployeeEditor.Id="rcp_demo.Editor.emp"; 
       page.openEditor(input,EmployeeEditor.Id); 
       System.out.println("open Editor(Employee) "); 
      } catch (PartInitException e) { 
       e.printStackTrace(); 
      } 
     return null; 
    } 
} 
관련 문제