【问题标题】:Toggle breakpoints on custom editor in Eclipse RCP?在 Eclipse RCP 中的自定义编辑器上切换断点?
【发布时间】:2013-04-07 02:40:49
【问题描述】:
我想在我创建的新编辑器上切换断点。我有一个新的编辑器和一个新的 LineBreakpoint 实现并运行。我已经可以使用 Ctrl + Shift + B 或 Main Menu -> Run -> Toggle Line Breakpoint 来切换这些断点。我希望能够在我的自定义 Eclipse 应用程序的垂直标尺栏中添加 Java 编辑器中完全相同的切换行为。也就是说,双击在给定的行位置创建/切换断点。右键单击会弹出切换断点菜单上下文(在垂直标尺栏上)。完成线切换图像标签。
我假设有一种简单的方法可以做到这一点,而不是实现每个菜单和操作。如果没有,如何将这些双击和上下文菜单添加到自定义编辑器的垂直标尺?
【问题讨论】:
标签:
eclipse
eclipse-rcp
eclipse-plugin
【解决方案1】:
我正在考虑做同样的事情。到目前为止,我发现扩展 AbstractDecoratedTextEditor 将为您提供执行此操作的平台。我会在它工作时更新。
【解决方案2】:
这是一个老问题,但我遇到了这个问题并这样做了:
我有一个编辑器 (org.eclipse.ui.texteditor.AbstractDecoratedTextEditor)。在这个编辑器类上我实现了这个方法:
@Override
protected IVerticalRulerColumn createAnnotationRulerColumn(CompositeRuler ruler) {
AnnotationRulerColumn column = new MyAnnotationRulerColumn(VERTICAL_RULER_WIDTH, getAnnotationAccess(), this);
return column;
}
MyAnnotationRulerColumn 类有些人是这样认为的:
import org.eclipse.debug.ui.actions.ToggleBreakpointAction;
import org.eclipse.jface.text.source.AnnotationRulerColumn;
import org.eclipse.jface.text.source.IAnnotationAccess;
import org.eclipse.jface.text.source.IVerticalRulerInfo;
public class MyAnnotationRulerColumn extends AnnotationRulerColumn {
private MyEditor editor;
public MyAnnotationRulerColumn(int width, IAnnotationAccess annotationAccess, MyEditor part) {
super(width, annotationAccess);
this.editor = part;
}
@Override
protected void mouseDoubleClicked(int rulerLine) {
if (editor != null) {
IVerticalRulerInfo rulerInfo= (IVerticalRulerInfo) editor.getAdapter(IVerticalRulerInfo.class);
ToggleBreakpointAction action = new ToggleBreakpointAction(editor, null, rulerInfo);
action.update();
action.run();
}
}
}