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;
15 import java.util.List;
17 import org.eclipse.swt.graphics.RGB;
18 import org.eclipse.jface.text.DefaultAutoIndentStrategy;
19 import org.eclipse.jface.text.IAutoIndentStrategy;
20 import org.eclipse.jface.text.IDocument;
21 import org.eclipse.jface.text.ITextDoubleClickStrategy;
22 import org.eclipse.jface.text.ITextHover;
23 import org.eclipse.jface.text.TextAttribute;
24 import org.eclipse.jface.text.contentassist.ContentAssistant;
25 import org.eclipse.jface.text.contentassist.IContentAssistant;
26 import org.eclipse.jface.text.presentation.IPresentationReconciler;
27 import org.eclipse.jface.text.presentation.PresentationReconciler;
28 import org.eclipse.jface.text.rules.BufferedRuleBasedScanner;
29 import org.eclipse.jface.text.rules.DefaultDamagerRepairer;
30 import org.eclipse.jface.text.rules.IToken;
31 import org.eclipse.jface.text.rules.RuleBasedDamagerRepairer;
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 net.sourceforge.phpeclipse.phpeditor.php.PHPAutoIndentStrategy;
37 import net.sourceforge.phpeclipse.phpeditor.php.PHPCompletionProcessor;
38 import net.sourceforge.phpeclipse.phpeditor.php.PHPDoubleClickSelector;
39 import net.sourceforge.phpeclipse.phpeditor.php.PHPPartitionScanner;
40 //import net.sourceforge.phpeclipse.phpeditor.html.JavaDocCompletionProcessor;
41 import net.sourceforge.phpeclipse.phpeditor.util.PHPColorProvider;
44 * Configuration for an <code>SourceViewer</code> which shows PHP code.
46 public class PHPSourceViewerConfiguration extends SourceViewerConfiguration {
49 * Single token scanner.
51 static class SingleTokenScanner extends BufferedRuleBasedScanner {
52 public SingleTokenScanner(TextAttribute attribute) {
53 setDefaultReturnToken(new Token(attribute));
58 * Default constructor.
60 public PHPSourceViewerConfiguration() {
64 * Method declared on SourceViewerConfiguration
66 public IAnnotationHover getAnnotationHover(ISourceViewer sourceViewer) {
67 return new PHPAnnotationHover();
71 * Method declared on SourceViewerConfiguration
73 public IAutoIndentStrategy getAutoIndentStrategy(ISourceViewer sourceViewer, String contentType) {
74 return (IDocument.DEFAULT_CONTENT_TYPE.equals(contentType) ? new PHPAutoIndentStrategy() : new DefaultAutoIndentStrategy());
78 * Method declared on SourceViewerConfiguration
80 public String[] getConfiguredContentTypes(ISourceViewer sourceViewer) {
82 IDocument.DEFAULT_CONTENT_TYPE,
83 PHPPartitionScanner.PHP,
84 // PHPPartitionScanner.JAVA_DOC,
85 PHPPartitionScanner.JAVA_MULTILINE_COMMENT };
89 * Method declared on SourceViewerConfiguration
91 public IContentAssistant getContentAssistant(ISourceViewer sourceViewer) {
93 ContentAssistant assistant = new ContentAssistant();
94 assistant.setContentAssistProcessor(new PHPCompletionProcessor(), IDocument.DEFAULT_CONTENT_TYPE);
95 // assistant.setContentAssistProcessor(new JavaDocCompletionProcessor(), PHPPartitionScanner.JAVA_DOC);
97 assistant.enableAutoActivation(true);
98 assistant.setAutoActivationDelay(500);
99 assistant.setProposalPopupOrientation(assistant.PROPOSAL_OVERLAY);
100 assistant.setContextInformationPopupOrientation(assistant.CONTEXT_INFO_ABOVE);
101 assistant.setContextInformationPopupBackground(PHPEditorEnvironment.getJavaColorProvider().getColor(new RGB(150, 150, 0)));
107 * Method declared on SourceViewerConfiguration
109 public String getDefaultPrefix(ISourceViewer sourceViewer, String contentType) {
110 return (IDocument.DEFAULT_CONTENT_TYPE.equals(contentType) ? "//" : null); //$NON-NLS-1$
114 * Method declared on SourceViewerConfiguration
116 public ITextDoubleClickStrategy getDoubleClickStrategy(ISourceViewer sourceViewer, String contentType) {
117 return new PHPDoubleClickSelector();
121 * Method declared on SourceViewerConfiguration
123 public String[] getIndentPrefixes(ISourceViewer sourceViewer, String contentType) {
124 return new String[] { "\t", " " }; //$NON-NLS-1$ //$NON-NLS-2$
128 * Method declared on SourceViewerConfiguration
130 public IPresentationReconciler getPresentationReconciler(ISourceViewer sourceViewer) {
132 PHPColorProvider provider = PHPEditorEnvironment.getJavaColorProvider();
133 PresentationReconciler reconciler = new PresentationReconciler();
135 DefaultDamagerRepairer dr = new DefaultDamagerRepairer(new SingleTokenScanner(new TextAttribute(provider.getColor(provider.HTML_DEFAULT))));
136 reconciler.setDamager(dr, IDocument.DEFAULT_CONTENT_TYPE);
137 reconciler.setRepairer(dr, IDocument.DEFAULT_CONTENT_TYPE);
139 dr = new DefaultDamagerRepairer(PHPEditorEnvironment.getPHPCodeScanner());
140 reconciler.setDamager(dr, PHPPartitionScanner.PHP);
141 reconciler.setRepairer(dr, PHPPartitionScanner.PHP);
143 // dr = new DefaultDamagerRepairer(new SingleTokenScanner(new TextAttribute(provider.getColor(provider.JAVADOC_DEFAULT))));
144 // reconciler.setDamager(dr, PHPPartitionScanner.JAVA_DOC);
145 // reconciler.setRepairer(dr, PHPPartitionScanner.JAVA_DOC);
147 dr = new DefaultDamagerRepairer(new SingleTokenScanner(new TextAttribute(provider.getColor(provider.MULTI_LINE_COMMENT))));
148 reconciler.setDamager(dr, PHPPartitionScanner.JAVA_MULTILINE_COMMENT);
149 reconciler.setRepairer(dr, PHPPartitionScanner.JAVA_MULTILINE_COMMENT);
155 * Method declared on SourceViewerConfiguration
157 public int getTabWidth(ISourceViewer sourceViewer) {
162 * Method declared on SourceViewerConfiguration
164 public ITextHover getTextHover(ISourceViewer sourceViewer, String contentType) {
165 return new PHPTextHover();