Programing

JDT의 "리팩터링"컨텍스트 메뉴와 유사한 퀵메뉴에 대한 키 바인딩을 어떻게 추가 할 수 있습니까?

crosscheck 2020. 11. 6. 07:51
반응형

JDT의 "리팩터링"컨텍스트 메뉴와 유사한 퀵메뉴에 대한 키 바인딩을 어떻게 추가 할 수 있습니까?


기존 바인딩으로 빠른 메뉴를 표시하기 위해 이클립스 플러그인에 바로 가기를 추가하고 싶습니다. JDT의 "리팩터링"퀵 메뉴처럼 작동합니다.

JDT의 빠른 메뉴 바로 가기 : "리팩터링"퀵 메뉴 바로 가기

JDT 빠른 메뉴 :

JDT 퀵메뉴

이미 바인딩과 명령을 추가했지만 뭔가 빠진 것 같습니다. 삭제 뭔가 항목이 또한 상황에 맞는 메뉴를 위해 노력하고, 빠른 메뉴로 바로 가기가 없습니다. 아무도 이것을하는 방법이 있습니까?

<extension point="org.eclipse.ui.bindings">
  <key
        commandId="myplugin.refactoring.actions.DeleteSomething"
        schemeId="org.eclipse.ui.defaultAcceleratorConfiguration"
        sequence="M1+5">
  </key>
  <key
        commandId="myplugin.refactoring.quickMenu"
        schemeId="org.eclipse.ui.defaultAcceleratorConfiguration"
        sequence="M1+9">
  </key>

<extension point="org.eclipse.ui.commands">
  <command
        categoryId="myplugin.category.refactor"
        description="Delete Something"
        id="myplugin.refactoring.actions.DeleteSomething"
        name="Extract Method">
  </command>
  <command
        categoryId="myplugin.category.refactor"
        id="myplugin.refactoring.quickMenu"
        name="Show Refactor Quick Menu">
  </command>
  <category
        id="myplugin.category.refactor"
        name="Refactor">
  </category>


다음과 같이 할 수도 있습니다.

빠른 메뉴에 대한 명령을 추가하고 기본 처리기를 설정합니다.

      <command
        defaultHandler="myplugin.refactoring.QuickmenuHandler"
        id="myplugin.refactoring.quickMenu"
        name="Show Refactor Quick Menu">
      </command>

핸들러는 메뉴를 생성 할 수 있어야합니다. 이 같은:

@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
    ...
    Menu menu = new Menu(some parent);
    new MenuItem(menu, SWT.PUSH).setText("...");
    menu.setVisible(true);
    return null;
}

명령에 바로 가기를 추가합니다 (예 :

 <key
    commandId="myplugin.refactoring.quickMenu"
    schemeId="org.eclipse.ui.defaultAcceleratorConfiguration"
    sequence="M1+9">
 </key>

마지막으로 메뉴 확장 점에서이 모든 것을 함께 묶습니다.

   <extension
     point="org.eclipse.ui.menus">
  <menuContribution
        allPopups="false"
        locationURI="popup:ch.arenae.dnp.frame.popup?after=additions">
     <menu
           commandId="myplugin.refactoring.quickMenu"
           label="Refactor">
        <command
              commandId="<first refactoring command>"
              style="push">
        </command>
     </menu>
     ...
  </menuContribution>

The important point is the commandId attribute in the menu element. It is used to display the keyboard shortcut in the menu.


You can have a look at how JDT implements the same. For instance, when looking at the Eclipse 3.8.2 source code, you'll see interesting method:

org.eclipse.jdt.ui.actions.RefactorActionGroup.installQuickAccessAction()

which is called when Java editor is opened. This is were programmatic handler association with current editor takes place.

To summarize how it's done in JDT:

  1. First, they have a command declaration in plugin.xml:

    <command name="%ActionDefinition.refactorQuickMenu.name" description="%ActionDefinition.refactorQuickMenu.description" categoryId="org.eclipse.jdt.ui.category.refactoring" id="org.eclipse.jdt.ui.edit.text.java.refactor.quickMenu">

  2. They declare a key binding:

    <key sequence = "M2 + M3 + T"commandId = "org.eclipse.jdt.ui.edit.text.java.refactor.quickMenu"schemeId = "org.eclipse.ui.defaultAcceleratorConfiguration"/>

  3. 편집기가 생성되면이 명령을 핸들러와 연결합니다. 핸들러 자체 ( org.eclipse.jdt.internal.ui.actions.JDTQuickMenuCreator)는 빠른 메뉴를 항목으로 채우는 작업을 처리합니다.

프로그래밍 방식으로 명령을 핸들러와 연관시킬 필요가 없습니다. 다른 옵션은 org.eclipse.ui.handlers 확장 점을 사용하는 것입니다.

참고 URL : https://stackoverflow.com/questions/7672536/how-can-i-add-a-key-binding-for-a-quickmenu-similar-to-the-refactor-context-me

반응형