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 (IDocument.DEFAULT_CONTENT_TYPE.equals(contentType) ? "//" : null); //$NON-NLS-1$
108 * Method declared on SourceViewerConfiguration
110 public ITextDoubleClickStrategy getDoubleClickStrategy(ISourceViewer sourceViewer, String contentType) {
111 return new PHPDoubleClickSelector();
115 * Method declared on SourceViewerConfiguration
117 public String[] getIndentPrefixes(ISourceViewer sourceViewer, String contentType) {
118 return new String[] { "\t", " " }; //$NON-NLS-1$ //$NON-NLS-2$
122 * Method declared on SourceViewerConfiguration
124 public IPresentationReconciler getPresentationReconciler(ISourceViewer sourceViewer) {
126 PHPColorProvider provider = PHPEditorEnvironment.getPHPColorProvider();
127 PresentationReconciler reconciler = new PresentationReconciler();
129 DefaultDamagerRepairer dr= new DefaultDamagerRepairer(PHPEditorEnvironment.getHTMLCodeScanner());
130 reconciler.setDamager(dr, IDocument.DEFAULT_CONTENT_TYPE);
131 reconciler.setRepairer(dr, IDocument.DEFAULT_CONTENT_TYPE);
133 // dr = new DefaultDamagerRepairer(new SingleTokenScanner(new TextAttribute(provider.getColor(provider.HTML_DEFAULT))));
134 // reconciler.setDamager(dr, IDocument.DEFAULT_CONTENT_TYPE);
135 // reconciler.setRepairer(dr, IDocument.DEFAULT_CONTENT_TYPE);
137 dr = new DefaultDamagerRepairer(PHPEditorEnvironment.getPHPCodeScanner());
138 reconciler.setDamager(dr, PHPPartitionScanner.PHP);
139 reconciler.setRepairer(dr, PHPPartitionScanner.PHP);
141 // dr = new DefaultDamagerRepairer(PHPEditorEnvironment.getHTMLCodeScanner());
142 // reconciler.setDamager(dr, PHPPartitionScanner.HTML);
143 // reconciler.setRepairer(dr, PHPPartitionScanner.HTML);
145 dr = new DefaultDamagerRepairer(new SingleTokenScanner(new TextAttribute(provider.getColor(provider.MULTI_LINE_COMMENT))));
146 reconciler.setDamager(dr, PHPPartitionScanner.HTML_MULTILINE_COMMENT);
147 reconciler.setRepairer(dr, PHPPartitionScanner.HTML_MULTILINE_COMMENT);
153 * Method declared on SourceViewerConfiguration
155 public int getTabWidth(ISourceViewer sourceViewer) {
160 * Method declared on SourceViewerConfiguration
162 public ITextHover getTextHover(ISourceViewer sourceViewer, String contentType) {
163 return new PHPTextHover();