Added context help menu for php function names. The description of the fundtion opens...
[phpeclipse.git] / net.sourceforge.phpeclipse / src / net / sourceforge / phpeclipse / phpeditor / PHPSourceViewerConfiguration.java
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
7
8 Contributors:
9     IBM Corporation - Initial implementation
10     Klaus Hartlage - www.eclipseproject.de
11 **********************************************************************/
12 package net.sourceforge.phpeclipse.phpeditor;
13
14
15 import java.util.List;
16
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;
42
43 /**
44  * Configuration for an <code>SourceViewer</code> which shows PHP code.
45  */
46 public class PHPSourceViewerConfiguration extends SourceViewerConfiguration {
47
48         /**
49          * Single token scanner.
50          */
51         static class SingleTokenScanner extends BufferedRuleBasedScanner {
52                 public SingleTokenScanner(TextAttribute attribute) {
53                         setDefaultReturnToken(new Token(attribute));
54                 }
55         };
56
57         /**
58          * Default constructor.
59          */
60         public PHPSourceViewerConfiguration() {
61         }
62
63         /* (non-Javadoc)
64          * Method declared on SourceViewerConfiguration
65          */
66         public IAnnotationHover getAnnotationHover(ISourceViewer sourceViewer) {
67                 return new PHPAnnotationHover();
68         }
69
70         /* (non-Javadoc)
71          * Method declared on SourceViewerConfiguration
72          */
73         public IAutoIndentStrategy getAutoIndentStrategy(ISourceViewer sourceViewer, String contentType) {
74                 return (IDocument.DEFAULT_CONTENT_TYPE.equals(contentType) ? new PHPAutoIndentStrategy() : new DefaultAutoIndentStrategy());
75         }
76
77         /* (non-Javadoc)
78          * Method declared on SourceViewerConfiguration
79          */
80         public String[] getConfiguredContentTypes(ISourceViewer sourceViewer) {
81                 return new String[] {
82                         IDocument.DEFAULT_CONTENT_TYPE,
83       PHPPartitionScanner.PHP,
84                 //      PHPPartitionScanner.JAVA_DOC,
85                         PHPPartitionScanner.JAVA_MULTILINE_COMMENT };
86         }
87
88         /* (non-Javadoc)
89          * Method declared on SourceViewerConfiguration
90          */
91         public IContentAssistant getContentAssistant(ISourceViewer sourceViewer) {
92
93                 ContentAssistant assistant = new ContentAssistant();
94                 assistant.setContentAssistProcessor(new PHPCompletionProcessor(), IDocument.DEFAULT_CONTENT_TYPE);
95         //      assistant.setContentAssistProcessor(new JavaDocCompletionProcessor(), PHPPartitionScanner.JAVA_DOC);
96
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)));
102
103                 return assistant;
104         }
105
106         /* (non-Javadoc)
107          * Method declared on SourceViewerConfiguration
108          */
109         public String getDefaultPrefix(ISourceViewer sourceViewer, String contentType) {
110                 return (IDocument.DEFAULT_CONTENT_TYPE.equals(contentType) ? "//" : null); //$NON-NLS-1$
111         }
112
113         /* (non-Javadoc)
114          * Method declared on SourceViewerConfiguration
115          */
116         public ITextDoubleClickStrategy getDoubleClickStrategy(ISourceViewer sourceViewer, String contentType) {
117                 return new PHPDoubleClickSelector();
118         }
119
120         /* (non-Javadoc)
121          * Method declared on SourceViewerConfiguration
122          */
123         public String[] getIndentPrefixes(ISourceViewer sourceViewer, String contentType) {
124                 return new String[] { "\t", "    " }; //$NON-NLS-1$ //$NON-NLS-2$
125         }
126
127         /* (non-Javadoc)
128          * Method declared on SourceViewerConfiguration
129          */
130         public IPresentationReconciler getPresentationReconciler(ISourceViewer sourceViewer) {
131
132                 PHPColorProvider provider = PHPEditorEnvironment.getJavaColorProvider();
133                 PresentationReconciler reconciler = new PresentationReconciler();
134
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);
138     
139     dr = new DefaultDamagerRepairer(PHPEditorEnvironment.getPHPCodeScanner());
140     reconciler.setDamager(dr, PHPPartitionScanner.PHP);
141     reconciler.setRepairer(dr, PHPPartitionScanner.PHP);
142     
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);
146
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);
150
151                 return reconciler;
152         }
153
154         /* (non-Javadoc)
155          * Method declared on SourceViewerConfiguration
156          */
157         public int getTabWidth(ISourceViewer sourceViewer) {
158                 return 4;
159         }
160
161         /* (non-Javadoc)
162          * Method declared on SourceViewerConfiguration
163          */
164         public ITextHover getTextHover(ISourceViewer sourceViewer, String contentType) {
165                 return new PHPTextHover();
166         }
167 }