【问题标题】:How to add a marker on the ruler?如何在标尺上添加标记?
【发布时间】:2011-12-01 04:58:18
【问题描述】:

我正在尝试在 Eclipse 的垂直标尺上添加一个标记/图标。我使用了以下代码

     IEditorPart editor = PlatformUI.getWorkbench()
        .getActiveWorkbenchWindow().getActivePage().getActiveEditor();
     IFileEditorInput input = (IFileEditorInput)editor.getEditorInput() ;
     IFile file = input.getFile();
     IProject activeProject = file.getProject();
     IResource res = (IResource) activeProject;

     IMarker m;
     try {
            m = res.createMarker("com.examples.problem");
            m.setAttribute(IMarker.LOCATION, offset);
            m.setAttribute(IMarker.MESSAGE, "Hello");
            m.setAttribute(IMarker.LINE_NUMBER, offset);
      } catch (CoreException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
      }

其中偏移量是我想要标记的行号。 这段代码是一个标记,但不在标尺上,而是在控制台和错误日志旁边的问题视图上。知道如何解决吗?另外,如果有任何其他方法可以在标尺上添加切换/图标/标记,请提出建议。

【问题讨论】:

    标签: java eclipse eclipse-plugin


    【解决方案1】:

    您应该使用 markerAnnotationSpecification 扩展点。这用于自动定义标记和编辑器注释之间的映射,具有指定的格式。

    有关它的更多详细信息,请参阅我的博客文章:http://cubussapiens.hu/2011/05/custom-markers-and-annotations-the-bright-side-of-eclipse/

    【讨论】:

      【解决方案2】:

      您应该在编辑器中打开的文件上创建标记,而不是在项目上。

      【讨论】:

      • 非常感谢...这对您有帮助。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-08-20
      • 1970-01-01
      相关资源
      最近更新 更多