【问题标题】:Command Handler not responding for EditorSelectionDialog命令处理程序没有响应 EditorSelectionDialog
【发布时间】:2018-09-03 13:42:50
【问题描述】:

我正在构建我的自定义编辑器。但是当我右键单击我想要的文件并尝试通过“打开方式”选项使用自定义编辑器打开它时,我的命令处理程序不起作用。我必须在 plugin.xml 中使用 menuContribution 标签下的 locationURIcommandId 吗?如果是那怎么办?请查看我当前的 plugin.xml 以获得更好的理解。

插件.xml

<extension point="org.eclipse.ui.editors">
  <editor
        class="launcher.ChartEditor"
        default="false"
        id="launcher.ChartEditor"
        name="ChartEditor">
  </editor>
</extension>
<extension
     point="org.eclipse.ui.commands">
  <command
        id="launcher.openChartEditor"
        name="OpenChartEditor">
  </command>
</extension>
<extension
     point="org.eclipse.ui.handlers">
  <handler
        class="launcher.ChartEditorHandler"
        commandId="launcher.openChartEditor"> 
  </handler>
</extension>

【问题讨论】:

    标签: eclipse eclipse-plugin eclipse-rcp


    【解决方案1】:

    “打开方式...”菜单直接打开编辑器。它不使用任何命令或处理程序。没有其他方法可以为“打开方式”菜单做出贡献。 EditorSelectionDialog 是一样的。

    要使用您的命令和处理程序,您确实需要使用 menuContribution(或工具栏贡献),但这必须在 Open With 以外的其他地方。

    标准的“打开方式”操作打开选定的编辑器,将IEditorInput 传递给当前选择。这通常是一个IFileEditorInput,您可以从中获取文件。

    【讨论】:

    • 好的。但是我怎样才能打开基于所选文件的编辑器。我的编辑器根据所选文件内容显示图表。这就是我使用命令处理程序的原因
    • Well Open With 在当前选择上打开选定的编辑器。为什么那行不通?在答案中添加了一些相关信息。
    • 您更新的答案有一个有效点。但是在我的 EditorPart 类的 init 方法中,当我使用“IFileEditorInput tui = (IFileEditorInput) input”时,我得到了 NoClassDefFoundError 异常。这里有什么问题?
    • 可能您没有在 MANIFEST.MF 中添加对包含 org.eclipse.ui.ide 插件的依赖项,该插件包含 IFileEditorInput,但没有信息很难说。
    • 我发现当我检查“if(input instanceof IFileEditorInput)”时,如果代码块不执行但如果我在 if 块之外的输入上使用 toString 方法,那么它会打印“org.eclipse .ui.part.FileEditorInput(-----)。这里有什么问题?
    猜你喜欢
    • 1970-01-01
    • 2012-05-05
    • 2013-06-16
    • 2014-04-22
    • 2021-07-23
    • 2021-06-06
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多