英文:
How to show print margin/vertical line in EmbeddedEditor?
问题
我想在我的org.eclipse.xtext.ui.editor.embedded.EmbeddedEditor
中的每 120 个字符后显示一条垂直线(在 Eclipse 的术语中称为打印边距)。是否支持这样做,或者是否有某个基础编辑器可用,我可以在其中创建这样的线?
英文:
I want to show a vertical line (print margin in eclipse wording) after 120 characters in my org.eclipse.xtext.ui.editor.embedded.EmbeddedEditor
. Is this supported somehow or is there some underlying editor available where I could create such a line?
答案1
得分: 0
从 greg-449s 的评论中得到的回答:
final EmbeddedEditor editor = ...;
editor.createPartialEditor();
MarginPainter marginPainter = new MarginPainter(editor.getViewer());
marginPainter.setMarginRulerColumn(120);
marginPainter.setMarginRulerColor(Display.getDefault().getSystemColor(SWT.COLOR_GRAY));
editor.getViewer().addPainter(marginPainter);
必须设置颜色,否则下一次对 `paint()` 的调用会抛出异常。
英文:
Answer from greg-449s comment:
final EmbeddedEditor editor = ...;
editor.createPartialEditor();
MarginPainter marginPainter = new MarginPainter(editor.getViewer());
marginPainter.setMarginRulerColumn(120);
marginPainter.setMarginRulerColor(Display.getDefault().getSystemColor(SWT.COLOR_GRAY));
editor.getViewer().addPainter(marginPainter);
You have to set the color, otherwise the next call to paint()
will throw.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论