如何在标尺上添加标记? [英] How to add a marker on the ruler?

查看:187
本文介绍了如何在标尺上添加标记?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am trying to add a marker/icon on the vertical ruler in Eclipse. I used the following code for it

     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();
      }

其中offset是我想要标记的行号。
这段代码是标记,但不在标尺上,而是在控制台和错误日志旁边的问题视图中。任何想法如何解决它?另外,如果有任何其他方式在标尺上添加一个切换/图标/标记,请咨询。

Where offset is the line number where I want the marker. This piece of code the a marker but not on the ruler, but on the Problems view next to Console and Error log. Any idea how I can fix it? Also if there is any other way of adding a toggle/icon/marker on the ruler, please advice.

推荐答案

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

You should use markerAnnotationSpecification extension point. This is used to define a mapping between markers and editor annotations automatically, with specified formatting.

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

See my blog post for more details about it: http://cubussapiens.hu/2011/05/custom-markers-and-annotations-the-bright-side-of-eclipse/

这篇关于如何在标尺上添加标记?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆