eclipse - Eclipse 中自定义编辑器的源代码菜单
问题描述
我正在编写一个 Eclipse 插件来在我自己的自定义编辑器中显示自己的文件类型的内容。
编辑器应该启用源菜单并使其可见(例如 java 编辑器),但我不知道如何启用该源菜单。
有了这个 如何在 Eclipse 中扩展源菜单?(或:它的 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:动作被添加到动作组中,它们在那里工作。
我还没有定义源菜单..我应该定义它还是在其他地方定义它?
谢谢
解决方案
让您的编辑器拥有自己的源菜单的最简单方法可能是覆盖contributeToMenu
编辑器操作栏贡献者中的方法:
@Override
public void contributeToMenu(final IMenuManager manager)
{
final IMenuManager menu = new MenuManager("Menu Title");
manager.prependToGroup(IWorkbenchActionConstants.MB_ADDITIONS, menu);
// Append your actions here
menu.add(sampleAction);
}
推荐阅读
- mysql - 带有 SUM 的 MySQL 内连接显示不正确的值
- python - 如何使用 python 或 bash 为文件中的每个值添加值“1”
- php - 如何在 cakephp 中正确构建这个 mysql 连接查询?
- javascript - 在 JavaScript If..Else 语句中使用逻辑运算符“&&”时得到“未定义”结果
- php - 将数组重组为关联数组
- node.js - 将多个变量传递给 package.json 脚本
- javascript - 如何自动幻灯片放映
- java - JVM 和 C++ 之间的纳秒精度差异
- javascript - 我正在尝试使用 jQuery 操作页面上的特定链接
- c# - 简明的键值对动态列表