【发布时间】:2021-12-27 09:23:31
【问题描述】:
我正在编写一个 Eclipse 插件来在我自己的自定义编辑器中显示自己的文件类型的内容。
编辑器应该启用源菜单并使其可见(例如 java 编辑器),但我不知道如何启用该源菜单。
有了这个 How to extend the source menu in Eclipse? (or: What is its locationURI?) 我可以将动作添加到源菜单,现在可见(总是..),但这些动作被禁用了......
这就是我在 plugin.xml 中定义动作的方式:
<extension
point="org.eclipse.ui.actionSets">
<actionSet
id="com.marchesini.mas.rcp.ui.actionset.mps.source"
label="MPS Source Format">
<action
definitionId="com.marchesini.mas.rcp.ui.edit.text.mps.format"
label="%FormatAction.label"
retarget="true"
id="com.marchesini.mas.rcp.ui.actions.Format">
</action>
<action
definitionId="com.marchesini.mas.rcp.ui.edit.text.mps.indent"
label="%IndentAction.label"
retarget="true"
id="com.marchesini.mas.rcp.ui.actions.Indent">
</action>
<action
definitionId="com.marchesini.mas.rcp.ui.edit.text.mps.sort_op_def"
label="%SortOpDefinitionAction.label"
retarget="true" id="com.marchesini.mas.rcp.ui.actions.SortOpDefinition">
</action>
</actionSet>
</extension>
这些是命令:
<extension
point="org.eclipse.ui.commands">
<category
id="com.marchesini.mas.rcp.ui.category.source"
name="MPS Source">
</category>
<command
categoryId="com.marchesini.mas.rcp.ui.category.source"
id="com.marchesini.mas.rcp.ui.edit.text.mps.format"
name="Format MPS">
</command>
<command
categoryId="com.marchesini.mas.rcp.ui.category.source"
id="com.marchesini.mas.rcp.ui.edit.text.mps.indent"
name="Indent MPS">
</command>
<command
categoryId="com.marchesini.mas.rcp.ui.category.source"
id="com.marchesini.mas.rcp.ui.edit.text.mps.sort_op_def"
name="Sort Op Definition MPS">
</command>
</extension>
这是我编辑器的createAction() 方法:
@Override
protected void createActions() {
super.createActions();
final ResourceBundle bundle = EditorPlugin.getResourceBundle();
IAction action = new TextOperationAction(bundle, "Format.", this, ISourceViewer.FORMAT); //$NON-NLS-1$
action.setActionDefinitionId(IMPSTextEditorActionDefinitionIds.FORMAT);
setAction("Format", action); //$NON-NLS-1$
markAsStateDependentAction("Format", true); //$NON-NLS-1$
action = new MPSIndentAction(bundle, "Indent.", this, false); //$NON-NLS-1$
action.setActionDefinitionId(IMPSTextEditorActionDefinitionIds.INDENT);
setAction("Indent", action); //$NON-NLS-1$
markAsStateDependentAction("Indent", true); //$NON-NLS-1$
markAsSelectionDependentAction("Indent", true); //$NON-NLS-1$
action = new MPSSortOpDefinitionAction(bundle, "SortOpDef.", this); //$NON-NLS-1$
action.setActionDefinitionId(IMPSTextEditorActionDefinitionIds.SORT_OP_DEF);
setAction("SortOpDef", action); //$NON-NLS-1$
markAsStateDependentAction("SortOpDef", true); //$NON-NLS-1$
m_generateActionGroup = new GenerateActionGroup(this, ITextEditorActionConstants.GROUP_EDIT);
}
我应该类似于CDT中的Java编辑器和C++编辑器。
我还在编辑器上下文菜单中注册了一个 ActionGroup:动作被添加到动作组并在那里工作。
我还没有定义源菜单。我应该定义它还是在其他地方定义它?
谢谢
【问题讨论】:
-
向我们展示您是如何定义菜单和您的操作的
-
我有问题的动作定义
-
你用
retarget="true"定义了那些,你做了什么来处理retargetable action? -
这是一个错误..我确实需要一个可重新定位的行动..我会从问题中删除它。
-
您正在指定
definitionId- 您是否为这些 id 设置了 org.eclipse.ui.commands?命令有处理程序吗?处理程序是否处于活动状态?
标签: eclipse eclipse-plugin eclipse-rcp