是否可以找出在 Eclipse 编辑器中编写的代码是否有效并相应地禁用/启用上下文菜单按钮?



我正在使用Xtext为我的DSL创建Eclipse插件,并且需要为我的编辑器添加上下文菜单项(我已经做了),但需要找出编辑器中的代码是否有效,如果是->应该启用此菜单项,否则禁用。是否可以检查整个代码是否有效并相应地更新此上下文菜单项的状态? 我通过将这个片段添加到 Xtext 中 .ui 项目中的插件.xml文件中来添加此上下文菜单项。

<extension point="org.eclipse.ui.menus">
<menuContribution locationURI="popup:#TextEditorContext?after=additions">
<command commandId="org.first.langu.ui.handler.InterpreterCommand" style="push">
<enabledWhen checkEnabled="true">
<reference definitionId="org.first.langu.Program.XtextEditor.opened"/>
</enabledWhen>
</command>
</menuContribution>
</extension>
<extension point="org.eclipse.ui.commands">
<command id="org.first.langu.ui.handler.InterpreterCommand" name="Interpret Code"/>
</extension>
<extension point="org.eclipse.ui.handlers">
<handler
class="org.first.langu.ui.ProgramExecutableExtensionFactory:org.first.langu.ui.handler.InterpretCodeHandler"
commandId="org.first.langu.ui.handler.InterpreterCommand"/>
</extension>

基本上我需要检查编辑器中的代码是否有效,而不是编辑器是否刚刚打开。

您可以使用编辑器注释模型来找出是否有任何错误。 见org.eclipse.xtext.ui.editor.XtextEditorErrorTickUpdater.getSeverity(XtextEditor)有关如何检索和筛选批注的示例。该类用于在出现错误时在编辑器图标中显示红色x

相关内容

最新更新