【问题标题】:How do I get an IResource from an IEditorActionDelegate如何从 EditorAction 委托中获取资源
【发布时间】:2010-02-17 01:59:00
【问题描述】:

我编写了一个 IEditorActionDelegate 来从 CompilationUnitEditor 的上下文菜单中触发。从那里我想在所选文本的起始行创建一个标记。我有一个 ITextSelection 和一个 IEditorPart 对象。如何从这些中获取 IResource 以便我可以调用 resource.createMarker()?

谢谢

【问题讨论】:

    标签: delegates selection markers eclipse-plugin compilationunit


    【解决方案1】:

    也许你可以看看 Eclipse 如何在其org.eclipse.jdt.internal.ui.javaeditor.EditorUtility 类中做类似的事情。

    你可以看到(line 222 and following)它:

    final IEditorInput  input= editor.getEditorInput();
    marker= ((IFileEditorInput)input).getFile().createMarker(IMarker.TEXT);
    marker.setAttribute(IMarker.CHAR_START, offset);
    marker.setAttribute(IMarker.CHAR_END, offset + length);
    

    有了offsetlength,你应该可以从TextSelection 推断出一些东西。

    【讨论】:

      猜你喜欢
      • 2021-03-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-08-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多