readme 도구 조치 세트에서는 새로 대상 지정 가능한 조치도 정의합니다. readme 조치 세트가 나타나면 조치도 나타나지만 조치를 구현하는 보기나 편집기가 활성화된 경우에만 조치를 사용할 수 있습니다. 조치 세트를 사용하여 새로 대상 지정 가능한 조치를 정의할 때 조치는 코드가 아니라 조치 세트 마크업에서 작성됩니다. 다음은 readme 도구 조치 세트 정의의 일부입니다.
<extension point = "org.eclipse.ui.actionSets"> <actionSet id="org_eclipse_ui_examples_readmetool_actionSet" label="%ActionSet.name" visible="true"> ... <action id="org_eclipse_ui_examples_readmetool_readmeRetargetAction" menubarPath="window/org_eclipse_ui_examples_readmetool/slot1" toolbarPath="readme" label="%ReadmeRetargetAction.label" tooltip="%ReadmeRetargetAction.tooltip" helpContextId="org.eclipse.ui.examples.readmetool.open_browser_action_context" icon="icons/ctool16/openbrwsr.png" retarget="true"> </action> <action id="org_eclipse_ui_examples_readmetool_readmeRelabelRetargetAction" menubarPath="window/org_eclipse_ui_examples_readmetool/slot1" toolbarPath="readme" label="%ReadmeRelabelRetargetAction.label" tooltip="%ReadmeRelabelRetargetAction.tooltip" helpContextId="org.eclipse.ui.examples.readmetool.open_browser_action_context" icon="icons/ctool16/openbrwsr.png" retarget="true" allowLabelUpdate="true"> </action> ...
새로 대상 지정된 조치는 retarget="true" 속성을 사용하여 지정됩니다. 이 속성을 지정하면 조치 세트에서 RetargetAction이 작성됩니다. 각 조치를 구현하는 핸들러를 설정하는 것은 플러그인의 각 보기 또는 편집기이기 때문에 새로 대상 지정 가능한 조치는 구현하는 클래스를 지정하지 않습니다. allowLabelUpdate가 true이면 LabelRetargetAction이 대신 작성됩니다.
readme 조치 설정이 나타날 때 새로 대상 지정된 조치가 창 메뉴에 나타납니다. 그러나 readme 도구의 편집기나 아웃라인 보기가 활성화되지 않은 경우 이 조치는 사용 가능하지 않습니다.
편집기와 보기의 기능은 무엇입니까? 클라이언트측의 기능은 Workbench나 편집기의 새로 대상 지정 가능한 조치에 대한 핸들러를 등록하는 것과 비슷합니다. 글로벌 조치 핸들러를 등록할 때 마크업에 지정된 조치 ID를 사용해야 합니다.
ReadmeEditorActionBarContributor에서는 편집기에 대해 이 기능을 처리합니다. 먼저 조치에 대한 핸들러를 정의합니다.
public ReadmeEditorActionBarContributor() { ... handler4 = new EditorAction(MessageUtil.getString("Editor_Action4")); handler5 = new EditorAction(MessageUtil.getString("Editor_Action5")); handler5.setToolTipText(MessageUtil.getString("Readme_Editor_Action5")); ... }
편집기의 새로 대상 지정 가능한 조치에 대한 핸들러가 등록됨과 동시에 핸들러도 등록됩니다.
public void init(IActionBars bars, IWorkbenchPage page) { ... bars.setGlobalActionHandler(IReadmeConstants.ACTION_SET_RETARGET4, handler4); bars.setGlobalActionHandler(IReadmeConstants.ACTION_SET_LABELRETARGET5, handler5); ... }
한 편집기의 다른 인스턴스에서 조치 표시줄 지시자를 공유해야 합니다. 따라서 ReadmeEditorActionBarContributor에 대한 활성 편집기가 변경되면 핸들러에게 알려야 합니다.
public void setActiveEditor(IEditorPart editor) { ... handler4.setActiveEditor(editor); handler5.setActiveEditor(editor); ... }
편집기에 대해서는 이 조치가 전부입니다. 편집기가 활성화될 때 이 조치가 사용 가능한지 확인해야 합니다.
조치 세트 XML 마크업이 allowLabelUpdate를 설정하지 않았으므로 첫 번째 새로 대상 지정 가능한 조치의 레이블("Editor Action 4")이 사용되지 않습니다.
ReadmeContentOutlinePage에서는 편집기의 새로 대상 지정 가능한 조치에 대한 핸들러를 정의한 위치에서 핸들러를 정의합니다.
public void createControl(Composite parent) { ... action = new OutlineAction(MessageUtil.getString("Outline_Action4")); getSite().getActionBars().setGlobalActionHandler( IReadmeConstants.ACTION_SET_RETARGET4, action); action = new OutlineAction(MessageUtil.getString("Outline_Action5")); action.setToolTipText(MessageUtil.getString("Readme_Outline_Action5")); getSite().getActionBars().setGlobalActionHandler( IReadmeConstants.ACTION_SET_LABELRETARGET5, action); }
컨텐츠 아웃라이너가 활성화될 때 다시 레이블이 지정된 조치를 볼 수 있어야 합니다.