1 /**********************************************************************
2 Copyright (c) 2000, 2002 IBM Corp. and others.
3 All rights reserved. This program and the accompanying materials
4 are made available under the terms of the Common Public License v1.0
5 which accompanies this distribution, and is available at
6 http://www.eclipse.org/legal/cpl-v10.html
9 IBM Corporation - Initial implementation
10 Klaus Hartlage - www.eclipseproject.de
11 **********************************************************************/
12 package net.sourceforge.phpeclipse.phpeditor;
14 import net.sourceforge.phpeclipse.phpeditor.php.HTMLCompletionProcessor;
15 import net.sourceforge.phpeclipse.phpeditor.php.PHPAutoIndentStrategy;
16 import net.sourceforge.phpeclipse.phpeditor.php.PHPCompletionProcessor;
17 import net.sourceforge.phpeclipse.phpeditor.php.PHPDoubleClickSelector;
18 import net.sourceforge.phpeclipse.phpeditor.php.PHPPartitionScanner;
19 import net.sourceforge.phpeclipse.phpeditor.util.PHPColorProvider;
20 import org.eclipse.jface.text.DefaultAutoIndentStrategy;
21 import org.eclipse.jface.text.IAutoIndentStrategy;
22 import org.eclipse.jface.text.IDocument;
23 import org.eclipse.jface.text.ITextDoubleClickStrategy;
24 import org.eclipse.jface.text.ITextHover;
25 import org.eclipse.jface.text.TextAttribute;
26 import org.eclipse.jface.text.contentassist.ContentAssistant;
27 import org.eclipse.jface.text.contentassist.IContentAssistant;
28 import org.eclipse.jface.text.presentation.IPresentationReconciler;
29 import org.eclipse.jface.text.presentation.PresentationReconciler;
30 import org.eclipse.jface.text.rules.BufferedRuleBasedScanner;
31 import org.eclipse.jface.text.rules.DefaultDamagerRepairer;
32 import org.eclipse.jface.text.rules.Token;
33 import org.eclipse.jface.text.source.IAnnotationHover;
34 import org.eclipse.jface.text.source.ISourceViewer;
35 import org.eclipse.jface.text.source.SourceViewerConfiguration;
36 import org.eclipse.swt.graphics.RGB;
39 * Configuration for an <code>SourceViewer</code> which shows PHP code.
41 public class PHPSourceViewerConfiguration extends SourceViewerConfiguration {
44 * Single token scanner.
46 static class SingleTokenScanner extends BufferedRuleBasedScanner {
47 public SingleTokenScanner(TextAttribute attribute) {
48 setDefaultReturnToken(new Token(attribute));
53 * Default constructor.
55 public PHPSourceViewerConfiguration() {
59 * Method declared on SourceViewerConfiguration
61 public IAnnotationHover getAnnotationHover(ISourceViewer sourceViewer) {
62 return new PHPAnnotationHover();
66 * Method declared on SourceViewerConfiguration
68 public IAutoIndentStrategy getAutoIndentStrategy(ISourceViewer sourceViewer, String contentType) {
69 return (IDocument.DEFAULT_CONTENT_TYPE.equals(contentType) ? new PHPAutoIndentStrategy() : new DefaultAutoIndentStrategy());
73 * Method declared on SourceViewerConfiguration
75 public String[] getConfiguredContentTypes(ISourceViewer sourceViewer) {
76 return new String[] { IDocument.DEFAULT_CONTENT_TYPE, PHPPartitionScanner.PHP,
77 // PHPPartitionScanner.JAVA_DOC,
78 PHPPartitionScanner.HTML_MULTILINE_COMMENT };
82 * Method declared on SourceViewerConfiguration
84 public IContentAssistant getContentAssistant(ISourceViewer sourceViewer) {
86 ContentAssistant assistant = new ContentAssistant();
87 assistant.setContentAssistProcessor(new HTMLCompletionProcessor(), IDocument.DEFAULT_CONTENT_TYPE);
88 assistant.setContentAssistProcessor(new PHPCompletionProcessor(), PHPPartitionScanner.PHP);
89 //assistant.setContentAssistProcessor(new PHPCompletionProcessor(), PHPPartitionScanner.HTML);
91 assistant.enableAutoActivation(true);
92 assistant.setAutoActivationDelay(500);
93 assistant.setProposalPopupOrientation(assistant.PROPOSAL_OVERLAY);
94 assistant.setContextInformationPopupOrientation(assistant.CONTEXT_INFO_ABOVE);
95 assistant.setContextInformationPopupBackground(PHPEditorEnvironment.getPHPColorProvider().getColor(new RGB(150, 150, 0)));
101 * Method declared on SourceViewerConfiguration
103 public String getDefaultPrefix(ISourceViewer sourceViewer, String contentType) {
104 return (PHPPartitionScanner.PHP.equals(contentType) ? "//" : null); //$NON-NLS-1$
105 // return (IDocument.DEFAULT_CONTENT_TYPE.equals(contentType) ? "//" : null); //$NON-NLS-1$
109 * Method declared on SourceViewerConfiguration
111 public ITextDoubleClickStrategy getDoubleClickStrategy(ISourceViewer sourceViewer, String contentType) {
112 return new PHPDoubleClickSelector();
116 * Method declared on SourceViewerConfiguration
118 public String[] getIndentPrefixes(ISourceViewer sourceViewer, String contentType) {
119 return new String[] { "\t", " " }; //$NON-NLS-1$ //$NON-NLS-2$
123 * Method declared on SourceViewerConfiguration
125 public IPresentationReconciler getPresentationReconciler(ISourceViewer sourceViewer) {
127 PHPColorProvider provider = PHPEditorEnvironment.getPHPColorProvider();
128 PresentationReconciler reconciler = new PresentationReconciler();
130 DefaultDamagerRepairer dr= new DefaultDamagerRepairer(PHPEditorEnvironment.getHTMLCodeScanner());
131 reconciler.setDamager(dr, IDocument.DEFAULT_CONTENT_TYPE);
132 reconciler.setRepairer(dr, IDocument.DEFAULT_CONTENT_TYPE);
134 // dr = new DefaultDamagerRepairer(new SingleTokenScanner(new TextAttribute(provider.getColor(provider.HTML_DEFAULT))));
135 // reconciler.setDamager(dr, IDocument.DEFAULT_CONTENT_TYPE);
136 // reconciler.setRepairer(dr, IDocument.DEFAULT_CONTENT_TYPE);
138 dr = new DefaultDamagerRepairer(PHPEditorEnvironment.getPHPCodeScanner());
139 reconciler.setDamager(dr, PHPPartitionScanner.PHP);
140 reconciler.setRepairer(dr, PHPPartitionScanner.PHP);
142 // dr = new DefaultDamagerRepairer(PHPEditorEnvironment.getHTMLCodeScanner());
143 // reconciler.setDamager(dr, PHPPartitionScanner.HTML);
144 // reconciler.setRepairer(dr, PHPPartitionScanner.HTML);
146 dr = new DefaultDamagerRepairer(new SingleTokenScanner(new TextAttribute(provider.getColor(provider.MULTI_LINE_COMMENT))));
147 reconciler.setDamager(dr, PHPPartitionScanner.HTML_MULTILINE_COMMENT);
148 reconciler.setRepairer(dr, PHPPartitionScanner.HTML_MULTILINE_COMMENT);
154 * Method declared on SourceViewerConfiguration
156 public int getTabWidth(ISourceViewer sourceViewer) {
161 * Method declared on SourceViewerConfiguration
163 public ITextHover getTextHover(ISourceViewer sourceViewer, String contentType) {
164 return new PHPTextHover();