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

问题描述 投票:0回答:1

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

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

eclipse eclipse-plugin dsl xtext
1个回答
0
投票

您可以使用编辑器注释模型来查明是否存在任何错误。有关如何检索和过滤注释的示例,请参阅org.eclipse.xtext.ui.editor.XtextEditorErrorTickUpdater.getSeverity(XtextEditor)。如果有错误,该类用于在编辑器图标中显示红色x

© www.soinside.com 2019 - 2024. All rights reserved.