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 java.util.List;
 
  16 import org.eclipse.swt.graphics.RGB;
 
  17 import org.eclipse.jface.text.DefaultAutoIndentStrategy;
 
  18 import org.eclipse.jface.text.IAutoIndentStrategy;
 
  19 import org.eclipse.jface.text.IDocument;
 
  20 import org.eclipse.jface.text.ITextDoubleClickStrategy;
 
  21 import org.eclipse.jface.text.ITextHover;
 
  22 import org.eclipse.jface.text.TextAttribute;
 
  23 import org.eclipse.jface.text.contentassist.ContentAssistant;
 
  24 import org.eclipse.jface.text.contentassist.IContentAssistant;
 
  25 import org.eclipse.jface.text.presentation.IPresentationReconciler;
 
  26 import org.eclipse.jface.text.presentation.PresentationReconciler;
 
  27 import org.eclipse.jface.text.rules.BufferedRuleBasedScanner;
 
  28 import org.eclipse.jface.text.rules.DefaultDamagerRepairer;
 
  29 import org.eclipse.jface.text.rules.IToken;
 
  30 import org.eclipse.jface.text.rules.RuleBasedDamagerRepairer;
 
  31 import org.eclipse.jface.text.rules.Token;
 
  32 import org.eclipse.jface.text.source.IAnnotationHover;
 
  33 import org.eclipse.jface.text.source.ISourceViewer;
 
  34 import org.eclipse.jface.text.source.SourceViewerConfiguration;
 
  35 import net.sourceforge.phpeclipse.phpeditor.php.PHPAutoIndentStrategy;
 
  36 import net.sourceforge.phpeclipse.phpeditor.php.PHPCompletionProcessor;
 
  37 import net.sourceforge.phpeclipse.phpeditor.php.PHPDoubleClickSelector;
 
  38 import net.sourceforge.phpeclipse.phpeditor.php.PHPPartitionScanner;
 
  39 //import net.sourceforge.phpeclipse.phpeditor.html.JavaDocCompletionProcessor;
 
  40 import net.sourceforge.phpeclipse.phpeditor.util.PHPColorProvider;
 
  43  * Configuration for an <code>SourceViewer</code> which shows PHP code.
 
  45 public class PHPSourceViewerConfiguration extends SourceViewerConfiguration {
 
  48    * Single token scanner.
 
  50   static class SingleTokenScanner extends BufferedRuleBasedScanner {
 
  51     public SingleTokenScanner(TextAttribute attribute) {
 
  52       setDefaultReturnToken(new Token(attribute));
 
  57    * Default constructor.
 
  59   public PHPSourceViewerConfiguration() {
 
  63    * Method declared on SourceViewerConfiguration
 
  65   public IAnnotationHover getAnnotationHover(ISourceViewer sourceViewer) {
 
  66     return new PHPAnnotationHover();
 
  70    * Method declared on SourceViewerConfiguration
 
  72   public IAutoIndentStrategy getAutoIndentStrategy(ISourceViewer sourceViewer, String contentType) {
 
  73     return (IDocument.DEFAULT_CONTENT_TYPE.equals(contentType) ? new PHPAutoIndentStrategy() : new DefaultAutoIndentStrategy());
 
  77    * Method declared on SourceViewerConfiguration
 
  79   public String[] getConfiguredContentTypes(ISourceViewer sourceViewer) {
 
  80     return new String[] { IDocument.DEFAULT_CONTENT_TYPE, PHPPartitionScanner.PHP,
 
  81       //        PHPPartitionScanner.JAVA_DOC,
 
  82       PHPPartitionScanner.HTML_MULTILINE_COMMENT };
 
  86    * Method declared on SourceViewerConfiguration
 
  88   public IContentAssistant getContentAssistant(ISourceViewer sourceViewer) {
 
  90     ContentAssistant assistant = new ContentAssistant();
 
  91     // assistant.setContentAssistProcessor(new PHPCompletionProcessor(), IDocument.DEFAULT_CONTENT_TYPE);
 
  92     assistant.setContentAssistProcessor(new PHPCompletionProcessor(), PHPPartitionScanner.PHP);
 
  94     assistant.enableAutoActivation(true);
 
  95     assistant.setAutoActivationDelay(500);
 
  96     assistant.setProposalPopupOrientation(assistant.PROPOSAL_OVERLAY);
 
  97     assistant.setContextInformationPopupOrientation(assistant.CONTEXT_INFO_ABOVE);
 
  98     assistant.setContextInformationPopupBackground(PHPEditorEnvironment.getJavaColorProvider().getColor(new RGB(150, 150, 0)));
 
 104    * Method declared on SourceViewerConfiguration
 
 106   public String getDefaultPrefix(ISourceViewer sourceViewer, String contentType) {
 
 107     return (IDocument.DEFAULT_CONTENT_TYPE.equals(contentType) ? "//" : null); //$NON-NLS-1$
 
 111    * Method declared on SourceViewerConfiguration
 
 113   public ITextDoubleClickStrategy getDoubleClickStrategy(ISourceViewer sourceViewer, String contentType) {
 
 114     return new PHPDoubleClickSelector();
 
 118    * Method declared on SourceViewerConfiguration
 
 120   public String[] getIndentPrefixes(ISourceViewer sourceViewer, String contentType) {
 
 121     return new String[] { "\t", "    " }; //$NON-NLS-1$ //$NON-NLS-2$
 
 125    * Method declared on SourceViewerConfiguration
 
 127   public IPresentationReconciler getPresentationReconciler(ISourceViewer sourceViewer) {
 
 129     PHPColorProvider provider = PHPEditorEnvironment.getJavaColorProvider();
 
 130     PresentationReconciler reconciler = new PresentationReconciler();
 
 132     DefaultDamagerRepairer dr= new DefaultDamagerRepairer(PHPEditorEnvironment.getHTMLCodeScanner());
 
 133     reconciler.setDamager(dr, IDocument.DEFAULT_CONTENT_TYPE);
 
 134     reconciler.setRepairer(dr, IDocument.DEFAULT_CONTENT_TYPE);
 
 136 //    dr = new DefaultDamagerRepairer(new SingleTokenScanner(new TextAttribute(provider.getColor(provider.HTML_DEFAULT))));
 
 137 //    reconciler.setDamager(dr, IDocument.DEFAULT_CONTENT_TYPE);
 
 138 //    reconciler.setRepairer(dr, IDocument.DEFAULT_CONTENT_TYPE);
 
 140     dr = new DefaultDamagerRepairer(PHPEditorEnvironment.getPHPCodeScanner());
 
 141     reconciler.setDamager(dr, PHPPartitionScanner.PHP);
 
 142     reconciler.setRepairer(dr, PHPPartitionScanner.PHP);
 
 144 //    dr = new DefaultDamagerRepairer(PHPEditorEnvironment.getHTMLCodeScanner());
 
 145 //    reconciler.setDamager(dr, PHPPartitionScanner.HTML);
 
 146 //    reconciler.setRepairer(dr, PHPPartitionScanner.HTML);
 
 148     dr = new DefaultDamagerRepairer(new SingleTokenScanner(new TextAttribute(provider.getColor(provider.MULTI_LINE_COMMENT))));
 
 149     reconciler.setDamager(dr, PHPPartitionScanner.HTML_MULTILINE_COMMENT);
 
 150     reconciler.setRepairer(dr, PHPPartitionScanner.HTML_MULTILINE_COMMENT);
 
 156    * Method declared on SourceViewerConfiguration
 
 158   public int getTabWidth(ISourceViewer sourceViewer) {
 
 163    * Method declared on SourceViewerConfiguration
 
 165   public ITextHover getTextHover(ISourceViewer sourceViewer, String contentType) {
 
 166     return new PHPTextHover();