如何在EmbeddedEditor中显示打印边距/垂直线?

huangapple go评论72阅读模式
英文:

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.

huangapple
  • 本文由 发表于 2020年4月9日 21:07:56
  • 转载请务必保留本文链接:https://go.coder-hub.com/61121903.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定