2016-06-22 9 views
0

StyledText/SourceViewer로 구현 된 RCP E4 텍스트 편집기 응용 프로그램의 경우 삽입 키의 상태를 받아야합니다.Eclipse E4 RCP StyledText INSERT KEY 상태 얻기

상태 (삽입, 스마트 삽입)를 받으면 응용 프로그램은 커서 아이콘을 수정하고 다른 부분에 INSERT 상태를 알립니다 (즉 일반 일반 텍스트 편집기 동작처럼 상태 표시 줄 컨트롤에 알립니다).

SWT.INSERT는 누르는 키만 수신하지만 StyledText가 INSERT MODE 인 경우 아무 것도 수신하지 않습니다. 응용 프로그램을 순수 E4 텍스트 편집기로 구성되어 있기 때문에

styledText.addKeyListener(new KeyAdapter(){ 
    public void keyPressed(KeyEvent e){ 
     if(e.keyCode == SWT.INSERT){ 
      System.out.println("INSERT KEY PRESSED!!!"); 
     } 
    } 
}; 

나는 방법을

getInsertMode() 

org.eclipse.ui.texteditor.AbstractTextEditor 

를 확장하고 사용하는 피할 수있다.

힌트가 있습니까? 당신이 키를 삽입 볼 때 기본 동작을 수행하지 StyledText 말할 필요

답변

1

우선 사전에

감사 :

textWidget.setKeyBinding(SWT.INSERT, SWT.NULL); 

다음 당신은 명령, 처리기를 정의 할 필요가 Insert 키를 다루는 편집기 컨텍스트에서 Key Binding을 사용합니다.

상태 표시를 업데이트하고 shoyld 수 있습니다 삽입 명령에 대한 핸들러는 겹쳐 쓰기 모드를 업데이트 할 StyledText 알려주기 :

textWidget.invokeAction(ST.TOGGLE_OVERWRITE); 

또한 맥 키보드가 Insert 키가없는 점에 유의!

0

E4 RCP 텍스트 편집기의 소스 뷰어 컨트롤에서 INSERT_KEY를 처리하는 데 어려움이 있으므로 gregg449의 답변에 자세한 내용을 작성합니다 (매회 그에게 큰 도움이됩니다!).

위의 대답에 따라 필자는 Binding Context, Binding Table, Command, Handler를 만들고 필요한 부분 (SourceViewer를 구현하는 부분)에 Binding Context를 추가했습니다.

다음 코드 SourceViewer 및 InserKey 핸들러이다

public class CheckKeyBindingSourceViewer extends ITextEditorPart{ 

    public SourceViewer sv = null; 
    public StyledText st = null; 

    @PostConstruct 
    public void postConstruct(Composite parent) { 
     sv = new SourceViewer(parent, null, null, true, SWT.MULTI | SWT.V_SCROLL |SWT.H_SCROLL); 
     IDocument doc = new Document(""); 
     sv.setDocument(doc); 
     st = sv.getTextWidget(); 

     //tell the StyledText not to do the default action when it sees the Insert key 
     st.setKeyBinding(SWT.INSERT, SWT.NULL); 
    } 
} 


public class InsertKeyHandler { 
    @Execute 
    public void execute(@Named(IServiceConstants.ACTIVE_PART) MPart activePart) { 
     if (activePart.getObject() instanceof ITextEditorPart){ 
      ITextEditorPart theSourceViewer = (ITextEditorPart) activePart.getObject(); 
      theSourceViewer.st.invokeAction(ST.TOGGLE_OVERWRITE); 
      //TODO 
      //Change cursor sourcewiewer, notify to Statusbar... 
     } 
    } 
} 

다음도 만든 바인딩 컨텍스트 및 바인딩 테이블과 Application.e4xmi를 나타낸다. 추가 태그 "type : user"를 바인딩 테이블에 추가하지 않으면 바인딩이 전혀 작동하지 않습니다. 이것은 vogella의 튜토리얼 (http://www.vogella.com/tutorials/EclipseRCP/article.html)에 반영되지 않고 그의 책에도 반영되지 않습니다.

나는이 정보를 찾을 수있는 유일한 장소에 유래 질문을했다 : 만약 리눅스와 윈도우 모두 일식 화성 (4.5.0)를 사용하고, 나는 모르는 eclipse rcp keybindings don't work

새로운 verions이 '버그 '해결되었습니다.

Key Binding configuration