mysourceviewerconfig.java

来自「这是用SWT写的一个自定义编辑器的一个小离子」· Java 代码 · 共 59 行

JAVA
59
字号
package edit4.Myedit;import org.eclipse.jface.text.IDocument;import org.eclipse.jface.text.TextAttribute;import org.eclipse.jface.text.contentassist.ContentAssistant;import org.eclipse.jface.text.contentassist.IContentAssistant;import org.eclipse.jface.text.presentation.IPresentationReconciler;import org.eclipse.jface.text.presentation.PresentationReconciler;import org.eclipse.jface.text.rules.DefaultDamagerRepairer;import org.eclipse.jface.text.rules.Token;import org.eclipse.jface.text.source.ISourceViewer;import org.eclipse.jface.text.source.SourceViewerConfiguration;import org.eclipse.swt.graphics.Color;import org.eclipse.swt.graphics.RGB;import org.eclipse.swt.widgets.Display;public class MySourceViewerConfig extends SourceViewerConfiguration {	private MyRuleScanner scanner;	private static Color DEFAULT_TAG_COLOR =		new Color(Display.getCurrent(), new RGB(0, 0, 255));	public MySourceViewerConfig() {	}	protected MyRuleScanner getTagScanner() {		if (scanner == null) {			scanner = new MyRuleScanner();			scanner.setDefaultReturnToken(				new Token(new TextAttribute(DEFAULT_TAG_COLOR)));		}		return scanner;	}	/**	 * Define reconciler for MyEditor	 */	public IPresentationReconciler getPresentationReconciler(ISourceViewer sourceViewer) {		PresentationReconciler reconciler = new PresentationReconciler();		DefaultDamagerRepairer dr = new DefaultDamagerRepairer(getTagScanner());		reconciler.setDamager(dr, IDocument.DEFAULT_CONTENT_TYPE);		reconciler.setRepairer(dr, IDocument.DEFAULT_CONTENT_TYPE);		return reconciler;	}		public IContentAssistant getContentAssistant(ISourceViewer sourceViewer) {		ContentAssistant assistant = new ContentAssistant();		assistant.setContentAssistProcessor(			new MyCompletionProcessor(),			IDocument.DEFAULT_CONTENT_TYPE);		assistant.enableAutoActivation(true);		assistant.setAutoActivationDelay(500);		assistant.setProposalPopupOrientation(			IContentAssistant.PROPOSAL_OVERLAY);		return assistant;	}}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?