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.phpdt.ui.text;
14 import java.util.Vector;
16 import net.sourceforge.phpdt.core.JavaCore;
17 import net.sourceforge.phpdt.internal.ui.text.AbstractJavaScanner;
18 import net.sourceforge.phpdt.internal.ui.text.ContentAssistPreference;
19 import net.sourceforge.phpdt.internal.ui.text.HTMLTextPresenter;
20 import net.sourceforge.phpdt.internal.ui.text.IPHPPartitions;
21 import net.sourceforge.phpdt.internal.ui.text.JavaAnnotationHover;
22 import net.sourceforge.phpdt.internal.ui.text.JavaCompositeReconcilingStrategy;
23 import net.sourceforge.phpdt.internal.ui.text.JavaElementProvider;
24 import net.sourceforge.phpdt.internal.ui.text.JavaOutlineInformationControl;
25 import net.sourceforge.phpdt.internal.ui.text.JavaPresentationReconciler;
26 import net.sourceforge.phpdt.internal.ui.text.JavaReconciler;
27 import net.sourceforge.phpdt.internal.ui.text.PreferencesAdapter;
28 import net.sourceforge.phpdt.internal.ui.text.java.JavaFormattingStrategy;
29 import net.sourceforge.phpdt.internal.ui.text.java.JavaStringAutoIndentStrategyDQ;
30 import net.sourceforge.phpdt.internal.ui.text.java.JavaStringAutoIndentStrategySQ;
31 import net.sourceforge.phpdt.internal.ui.text.java.hover.JavaEditorTextHoverDescriptor;
32 import net.sourceforge.phpdt.internal.ui.text.java.hover.JavaEditorTextHoverProxy;
33 import net.sourceforge.phpdt.internal.ui.text.java.hover.JavaInformationProvider;
34 import net.sourceforge.phpdt.internal.ui.text.phpdoc.PHPDocCodeScanner;
35 import net.sourceforge.phpdt.internal.ui.text.phpdoc.PHPDocCompletionProcessor;
36 import net.sourceforge.phpdt.ui.PreferenceConstants;
37 import net.sourceforge.phpeclipse.IPreferenceConstants;
38 import net.sourceforge.phpeclipse.PHPeclipsePlugin;
39 import net.sourceforge.phpeclipse.phpeditor.html.HTMLFormattingStrategy;
40 import net.sourceforge.phpeclipse.phpeditor.php.HTMLCompletionProcessor;
41 import net.sourceforge.phpeclipse.phpeditor.php.PHPAutoIndentStrategy;
42 import net.sourceforge.phpeclipse.phpeditor.php.PHPCodeScanner;
43 import net.sourceforge.phpeclipse.phpeditor.php.PHPCompletionProcessor;
44 import net.sourceforge.phpeclipse.phpeditor.php.PHPDocumentPartitioner;
45 import net.sourceforge.phpeclipse.phpeditor.php.PHPDoubleClickSelector;
46 import net.sourceforge.phpeclipse.phpeditor.php.PHPPartitionScanner;
47 import net.sourceforge.phpeclipse.xml.ui.XMLPlugin;
48 import net.sourceforge.phpeclipse.xml.ui.internal.text.XMLConfiguration;
49 import net.sourceforge.phpeclipse.xml.ui.internal.text.XMLPartitionScanner;
50 import net.sourceforge.phpeclipse.xml.ui.text.XMLTextTools;
52 import org.eclipse.core.runtime.NullProgressMonitor;
53 import org.eclipse.jface.preference.IPreferenceStore;
54 import org.eclipse.jface.text.DefaultAutoIndentStrategy;
55 import org.eclipse.jface.text.DefaultInformationControl;
56 import org.eclipse.jface.text.IAutoIndentStrategy;
57 import org.eclipse.jface.text.IDocument;
58 import org.eclipse.jface.text.IInformationControl;
59 import org.eclipse.jface.text.IInformationControlCreator;
60 import org.eclipse.jface.text.ITextDoubleClickStrategy;
61 import org.eclipse.jface.text.ITextHover;
62 import org.eclipse.jface.text.ITextViewerExtension2;
63 import org.eclipse.jface.text.TextAttribute;
64 import org.eclipse.jface.text.contentassist.ContentAssistant;
65 import org.eclipse.jface.text.contentassist.IContentAssistProcessor;
66 import org.eclipse.jface.text.contentassist.IContentAssistant;
67 import org.eclipse.jface.text.formatter.ContentFormatter;
68 import org.eclipse.jface.text.formatter.IContentFormatter;
69 import org.eclipse.jface.text.formatter.IFormattingStrategy;
70 import org.eclipse.jface.text.information.IInformationPresenter;
71 import org.eclipse.jface.text.information.IInformationProvider;
72 import org.eclipse.jface.text.information.InformationPresenter;
73 import org.eclipse.jface.text.presentation.IPresentationDamager;
74 import org.eclipse.jface.text.presentation.IPresentationReconciler;
75 import org.eclipse.jface.text.presentation.IPresentationRepairer;
76 import org.eclipse.jface.text.presentation.PresentationReconciler;
77 import org.eclipse.jface.text.reconciler.IReconciler;
78 import org.eclipse.jface.text.rules.BufferedRuleBasedScanner;
79 import org.eclipse.jface.text.rules.DefaultDamagerRepairer;
80 import org.eclipse.jface.text.rules.DefaultPartitioner;
81 import org.eclipse.jface.text.rules.RuleBasedScanner;
82 import org.eclipse.jface.text.rules.Token;
83 import org.eclipse.jface.text.source.IAnnotationHover;
84 import org.eclipse.jface.text.source.ISourceViewer;
85 import org.eclipse.jface.text.source.SourceViewerConfiguration;
86 import org.eclipse.jface.util.Assert;
87 import org.eclipse.jface.util.PropertyChangeEvent;
88 import org.eclipse.swt.SWT;
89 import org.eclipse.swt.widgets.Shell;
90 import org.eclipse.ui.editors.text.EditorsUI;
91 import org.eclipse.ui.texteditor.ChainedPreferenceStore;
92 import org.eclipse.ui.texteditor.ITextEditor;
95 * Configuration for an <code>SourceViewer</code> which shows PHP code.
97 public class PHPSourceViewerConfiguration extends SourceViewerConfiguration {
99 * Preference key used to look up display tab width.
103 public final static String PREFERENCE_TAB_WIDTH = PreferenceConstants.EDITOR_TAB_WIDTH;
106 * Preference key for inserting spaces rather than tabs.
110 public final static String SPACES_FOR_TABS = PreferenceConstants.EDITOR_SPACES_FOR_TABS;
112 // public static final String HTML_DEFAULT =
113 // IPHPPartitionScannerConstants.HTML;
114 //IDocument.DEFAULT_CONTENT_TYPE;
115 private JavaTextTools fJavaTextTools;
117 private ITextEditor fTextEditor;
120 * The document partitioning.
124 private String fDocumentPartitioning;
126 private ContentFormatter fFormatter;
128 private HTMLFormattingStrategy fFormattingStrategy;
131 * Single token scanner.
133 static class SingleTokenScanner extends BufferedRuleBasedScanner {
134 public SingleTokenScanner(TextAttribute attribute) {
135 setDefaultReturnToken(new Token(attribute));
140 * The document partitioning.
144 // private String fDocumentPartitioning;
146 * The Java source code scanner
150 private AbstractJavaScanner fCodeScanner;
153 * The Java multi-line comment scanner
157 private AbstractJavaScanner fMultilineCommentScanner;
160 * The Java single-line comment scanner
164 private AbstractJavaScanner fSinglelineCommentScanner;
167 * The Java string scanner
171 private AbstractJavaScanner fStringScanner;
174 * The Javadoc scanner
178 private AbstractJavaScanner fJavaDocScanner;
181 * The preference store, can be read-only
185 private IPreferenceStore fPreferenceStore;
192 private IColorManager fColorManager;
194 private XMLTextTools fXMLTextTools;
196 private XMLConfiguration xmlConfiguration;
199 * Creates a new Java source viewer configuration for viewers in the given editor using the given preference store, the color
200 * manager and the specified document partitioning.
202 * Creates a Java source viewer configuration in the new setup without text tools. Clients are allowed to call
203 * {@link JavaSourceViewerConfiguration#handlePropertyChangeEvent(PropertyChangeEvent)}and disallowed to call
204 * {@link JavaSourceViewerConfiguration#getPreferenceStore()}on the resulting Java source viewer configuration.
207 * @param colorManager
209 * @param preferenceStore
210 * the preference store, can be read-only
212 * the editor in which the configured viewer(s) will reside
213 * @param partitioning
214 * the document partitioning for this configuration
217 public PHPSourceViewerConfiguration(IColorManager colorManager, IPreferenceStore preferenceStore, ITextEditor editor,
218 String partitioning) {
219 fColorManager = colorManager;
220 fPreferenceStore = preferenceStore;
221 fTextEditor = editor;
222 fDocumentPartitioning = partitioning;
223 // fJavaTextTools = PHPeclipsePlugin.getDefault().getJavaTextTools();
224 fXMLTextTools = XMLPlugin.getDefault().getXMLTextTools();
225 xmlConfiguration = new XMLConfiguration(fXMLTextTools);
226 fColorManager= colorManager;
227 fPreferenceStore= preferenceStore;
229 fDocumentPartitioning= partitioning;
231 initializeScanners();
235 * Creates a new Java source viewer configuration for viewers in the given editor
236 * using the given Java tools.
238 * @param tools the Java text tools to be used
239 * @param editor the editor in which the configured viewer(s) will reside
241 * @deprecated As of 3.0, replaced by {@link JavaSourceViewerConfiguration#JavaSourceViewerConfiguration(IColorManager, IPreferenceStore, ITextEditor, String)}
243 // public PHPSourceViewerConfiguration(JavaTextTools tools, PHPEditor editor, String partitioning) {
244 // fJavaTextTools = tools;
245 // fColorManager = tools.getColorManager();
246 // fPreferenceStore = createPreferenceStore();
247 // fDocumentPartitioning = partitioning;
248 // fCodeScanner = (AbstractJavaScanner) fJavaTextTools.getCodeScanner();
249 // fMultilineCommentScanner = (AbstractJavaScanner) fJavaTextTools.getMultilineCommentScanner();
250 // fSinglelineCommentScanner = (AbstractJavaScanner) fJavaTextTools.getSinglelineCommentScanner();
251 // fStringScanner = (AbstractJavaScanner) fJavaTextTools.getStringScanner();
252 // fJavaDocScanner = (AbstractJavaScanner) fJavaTextTools.getJavaDocScanner();
253 // fTextEditor = editor;
254 // fXMLTextTools = XMLPlugin.getDefault().getXMLTextTools();
255 // xmlConfiguration = new XMLConfiguration(fXMLTextTools);
259 * Returns the color manager for this configuration.
261 * @return the color manager
263 protected IColorManager getColorManager() {
264 return fColorManager;
268 * Initializes the scanners.
272 private void initializeScanners() {
273 Assert.isTrue(isNewSetup());
274 fCodeScanner = new PHPCodeScanner(getColorManager(), fPreferenceStore);
275 fMultilineCommentScanner = new SingleTokenPHPScanner(getColorManager(), fPreferenceStore,
276 IPreferenceConstants.PHP_MULTILINE_COMMENT);
277 fSinglelineCommentScanner = new SingleTokenPHPScanner(getColorManager(), fPreferenceStore,
278 IPreferenceConstants.PHP_SINGLELINE_COMMENT);
279 fStringScanner = new SingleTokenPHPScanner(getColorManager(), fPreferenceStore, IPreferenceConstants.PHP_STRING);
280 fJavaDocScanner = new PHPDocCodeScanner(getColorManager(), fPreferenceStore);
284 * Determines whether the preference change encoded by the given event changes the behavior of one of its contained components.
287 * the event to be investigated
288 * @return <code>true</code> if event causes a behavioral change
291 public boolean affectsTextPresentation(PropertyChangeEvent event) {
292 return fCodeScanner.affectsBehavior(event) || fMultilineCommentScanner.affectsBehavior(event)
293 || fSinglelineCommentScanner.affectsBehavior(event) || fStringScanner.affectsBehavior(event)
294 || fJavaDocScanner.affectsBehavior(event);
298 * Adapts the behavior of the contained components to the change encoded in the given event.
300 * Clients are not allowed to call this method if the old setup with text tools is in use.
304 * the event to which to adapt
305 * @see JavaSourceViewerConfiguration#JavaSourceViewerConfiguration(IColorManager, IPreferenceStore, ITextEditor, String)
308 public void handlePropertyChangeEvent(PropertyChangeEvent event) {
309 Assert.isTrue(isNewSetup());
310 if (fCodeScanner.affectsBehavior(event))
311 fCodeScanner.adaptToPreferenceChange(event);
312 if (fMultilineCommentScanner.affectsBehavior(event))
313 fMultilineCommentScanner.adaptToPreferenceChange(event);
314 if (fSinglelineCommentScanner.affectsBehavior(event))
315 fSinglelineCommentScanner.adaptToPreferenceChange(event);
316 if (fStringScanner.affectsBehavior(event))
317 fStringScanner.adaptToPreferenceChange(event);
318 if (fJavaDocScanner.affectsBehavior(event))
319 fJavaDocScanner.adaptToPreferenceChange(event);
323 * @see SourceViewerConfiguration#getContentFormatter(ISourceViewer)
325 public IContentFormatter getContentFormatter(ISourceViewer sourceViewer) {
326 // if (fFormatter == null) {
327 // fFormatter = new ContentFormatter();
328 // fFormattingStrategy = new HTMLFormattingStrategy(this,
330 // fFormatter.setFormattingStrategy(fFormattingStrategy, HTML_DEFAULT);
331 // fFormatter.enablePartitionAwareFormatting(false);
332 // fFormatter.setPartitionManagingPositionCategories(getConfiguredContentTypes(null));
334 // return fFormatter;
335 if (fFormatter == null) {
337 fFormatter = new ContentFormatter();
338 IFormattingStrategy strategy = new JavaFormattingStrategy(sourceViewer);
339 fFormatter.setFormattingStrategy(strategy, IDocument.DEFAULT_CONTENT_TYPE);
340 fFormatter.enablePartitionAwareFormatting(false);
341 fFormatter.setPartitionManagingPositionCategories(getPartitionManagingPositionCategories());
347 * Returns the names of the document position categories used by the document partitioners created by this object to manage their
348 * partition information. If the partitioners don't use document position categories, the returned result is <code>null</code>.
350 * @return the partition managing position categories or <code>null</code> if there is none
352 public String[] getPartitionManagingPositionCategories() {
353 return new String[] { DefaultPartitioner.CONTENT_TYPES_CATEGORY };
357 // * Returns the names of the document position categories used by the
359 // * partitioners created by this object to manage their partition
361 // * If the partitioners don't use document position categories, the
363 // * result is <code>null</code>.
365 // * @return the partition managing position categories or
367 // * if there is none
369 // private String[] getPartitionManagingPositionCategories() {
370 // return new String[] { DefaultPartitioner.CONTENT_TYPES_CATEGORY };
372 public ITextEditor getEditor() {
377 * Returns the preference store used by this configuration to initialize the individual bits and pieces.
379 * @return the preference store used to initialize this configuration
383 protected IPreferenceStore getPreferenceStore() {
384 return PHPeclipsePlugin.getDefault().getPreferenceStore();
388 // * Method declared on SourceViewerConfiguration
390 // public IAnnotationHover getAnnotationHover(ISourceViewer sourceViewer) {
391 // return new PHPAnnotationHover();
394 * @see SourceViewerConfiguration#getAnnotationHover(ISourceViewer)
396 public IAnnotationHover getAnnotationHover(ISourceViewer sourceViewer) {
397 return new JavaAnnotationHover(JavaAnnotationHover.VERTICAL_RULER_HOVER);
401 * @see SourceViewerConfiguration#getOverviewRulerAnnotationHover(ISourceViewer)
404 public IAnnotationHover getOverviewRulerAnnotationHover(ISourceViewer sourceViewer) {
405 return new JavaAnnotationHover(JavaAnnotationHover.OVERVIEW_RULER_HOVER);
409 * (non-Javadoc) Method declared on SourceViewerConfiguration
411 public IAutoIndentStrategy getAutoIndentStrategy(ISourceViewer sourceViewer, String contentType) {
412 if (IPHPPartitions.PHP_STRING_DQ.equals(contentType))
413 return new JavaStringAutoIndentStrategyDQ(getConfiguredDocumentPartitioning(sourceViewer));
414 if (IPHPPartitions.PHP_STRING_SQ.equals(contentType))
415 return new JavaStringAutoIndentStrategySQ(getConfiguredDocumentPartitioning(sourceViewer));
417 return (PHPDocumentPartitioner.PHP_TEMPLATE_DATA.equals(contentType)
418 || PHPDocumentPartitioner.PHP_SCRIPT_CODE.equals(contentType) || IDocument.DEFAULT_CONTENT_TYPE.equals(contentType)
419 || IPHPPartitions.PHP_PARTITIONING.equals(contentType) || PHPPartitionScanner.PHP_SCRIPTING_AREA.equals(contentType) ? new PHPAutoIndentStrategy()
420 : new DefaultAutoIndentStrategy());
424 * Returns the PHP source code scanner for this configuration.
426 * @return the PHP source code scanner
428 protected RuleBasedScanner getCodeScanner() {
429 return fCodeScanner; //fJavaTextTools.getCodeScanner();
432 * Returns the Java multi-line comment scanner for this configuration.
434 * @return the Java multi-line comment scanner
437 protected RuleBasedScanner getMultilineCommentScanner() {
438 return fMultilineCommentScanner;
442 * Returns the Java single-line comment scanner for this configuration.
444 * @return the Java single-line comment scanner
447 protected RuleBasedScanner getSinglelineCommentScanner() {
448 return fSinglelineCommentScanner;
452 * Returns the Java string scanner for this configuration.
454 * @return the Java string scanner
457 protected RuleBasedScanner getStringScanner() {
458 return fStringScanner;
461 * Returns the HTML source code scanner for this configuration.
463 * @return the HTML source code scanner
465 // protected RuleBasedScanner getHTMLScanner() {
466 // return fJavaTextTools.getHTMLScanner();
469 * Returns the Smarty source code scanner for this configuration.
471 * @return the Smarty source code scanner
473 // protected RuleBasedScanner getSmartyScanner() {
474 // return fJavaTextTools.getSmartyScanner();
478 * @see SourceViewerConfiguration#getReconciler(ISourceViewer)
481 * @see SourceViewerConfiguration#getReconciler(ISourceViewer)
483 public IReconciler getReconciler(ISourceViewer sourceViewer) {
485 final ITextEditor editor = getEditor();
486 if (editor != null && editor.isEditable()) {
488 JavaCompositeReconcilingStrategy strategy = new JavaCompositeReconcilingStrategy(editor,
489 getConfiguredDocumentPartitioning(sourceViewer));
490 JavaReconciler reconciler = new JavaReconciler(editor, strategy, false);
491 reconciler.setIsIncrementalReconciler(false);
492 reconciler.setProgressMonitor(new NullProgressMonitor());
493 reconciler.setDelay(500);
500 // public IReconciler getReconciler(ISourceViewer sourceViewer) {
501 // if (getEditor() != null && getEditor().isEditable()) {
502 // JavaReconciler reconciler = new JavaReconciler(getEditor(),
503 // new JavaReconcilingStrategy(getEditor()), false);
504 // reconciler.setProgressMonitor(new NullProgressMonitor());
505 // reconciler.setDelay(500);
506 // return reconciler;
511 * @see SourceViewerConfiguration#getConfiguredTextHoverStateMasks(ISourceViewer, String)
514 public int[] getConfiguredTextHoverStateMasks(ISourceViewer sourceViewer, String contentType) {
515 JavaEditorTextHoverDescriptor[] hoverDescs = PHPeclipsePlugin.getDefault().getJavaEditorTextHoverDescriptors();
516 int stateMasks[] = new int[hoverDescs.length];
517 int stateMasksLength = 0;
518 for (int i = 0; i < hoverDescs.length; i++) {
519 if (hoverDescs[i].isEnabled()) {
521 int stateMask = hoverDescs[i].getStateMask();
522 while (j < stateMasksLength) {
523 if (stateMasks[j] == stateMask)
527 if (j == stateMasksLength)
528 stateMasks[stateMasksLength++] = stateMask;
531 if (stateMasksLength == hoverDescs.length)
533 int[] shortenedStateMasks = new int[stateMasksLength];
534 System.arraycopy(stateMasks, 0, shortenedStateMasks, 0, stateMasksLength);
535 return shortenedStateMasks;
539 * @see SourceViewerConfiguration#getTextHover(ISourceViewer, String, int)
542 public ITextHover getTextHover(ISourceViewer sourceViewer, String contentType, int stateMask) {
543 JavaEditorTextHoverDescriptor[] hoverDescs = PHPeclipsePlugin.getDefault().getJavaEditorTextHoverDescriptors();
545 while (i < hoverDescs.length) {
546 if (hoverDescs[i].isEnabled() && hoverDescs[i].getStateMask() == stateMask)
547 return new JavaEditorTextHoverProxy(hoverDescs[i], getEditor());
551 // if (fEditor != null) {
552 // IEditorInput editorInput = fEditor.getEditorInput();
553 // if (editorInput instanceof IFileEditorInput) {
555 // IFile f = ((IFileEditorInput) editorInput).getFile();
556 // return new PHPTextHover(f.getProject());
557 // } catch (NullPointerException e) {
558 // // this exception occurs, if getTextHover is called by
559 // // preference pages !
563 // return new PHPTextHover(null);
567 * @see SourceViewerConfiguration#getTextHover(ISourceViewer, String)
569 public ITextHover getTextHover(ISourceViewer sourceViewer, String contentType) {
570 return getTextHover(sourceViewer, contentType, ITextViewerExtension2.DEFAULT_HOVER_STATE_MASK);
574 * Returns the SmartyDoc source code scanner for this configuration.
576 * @return the SmartyDoc source code scanner
578 // protected RuleBasedScanner getSmartyDocScanner() {
579 // return fJavaTextTools.getSmartyDocScanner();
583 * Returns the PHPDoc source code scanner for this configuration.
585 * @return the PHPDoc source code scanner
587 protected RuleBasedScanner getPHPDocScanner() {
588 return fJavaDocScanner; //fJavaTextTools.getJavaDocScanner();
592 * (non-Javadoc) Method declared on SourceViewerConfiguration
594 public String[] getConfiguredContentTypes(ISourceViewer sourceViewer) {
595 return new String[] { IDocument.DEFAULT_CONTENT_TYPE, PHPPartitionScanner.PHP_SCRIPTING_AREA,
597 IPHPPartitions.HTML, IPHPPartitions.HTML_MULTILINE_COMMENT, IPHPPartitions.PHP_PARTITIONING,
598 IPHPPartitions.PHP_SINGLELINE_COMMENT, IPHPPartitions.PHP_MULTILINE_COMMENT, IPHPPartitions.PHP_PHPDOC_COMMENT,
599 IPHPPartitions.PHP_STRING_DQ, IPHPPartitions.PHP_STRING_SQ, IPHPPartitions.CSS, IPHPPartitions.CSS_MULTILINE_COMMENT,
600 IPHPPartitions.JAVASCRIPT, IPHPPartitions.JS_MULTILINE_COMMENT, IPHPPartitions.SMARTY,
601 IPHPPartitions.SMARTY_MULTILINE_COMMENT,
603 XMLPartitionScanner.XML_PI, XMLPartitionScanner.XML_COMMENT, XMLPartitionScanner.XML_DECL, XMLPartitionScanner.XML_TAG,
604 XMLPartitionScanner.XML_ATTRIBUTE, XMLPartitionScanner.XML_CDATA,
606 XMLPartitionScanner.DTD_INTERNAL, XMLPartitionScanner.DTD_INTERNAL_PI, XMLPartitionScanner.DTD_INTERNAL_COMMENT,
607 XMLPartitionScanner.DTD_INTERNAL_DECL,
609 PHPDocumentPartitioner.PHP_TEMPLATE_DATA, PHPDocumentPartitioner.PHP_SCRIPT_CODE };
612 public String[] getConfiguredHTMLContentTypes() {
613 return new String[] { XMLPartitionScanner.XML_PI, XMLPartitionScanner.XML_COMMENT, XMLPartitionScanner.XML_DECL,
614 XMLPartitionScanner.XML_TAG, XMLPartitionScanner.XML_ATTRIBUTE, XMLPartitionScanner.XML_CDATA,
616 XMLPartitionScanner.DTD_INTERNAL, XMLPartitionScanner.DTD_INTERNAL_PI, XMLPartitionScanner.DTD_INTERNAL_COMMENT,
617 XMLPartitionScanner.DTD_INTERNAL_DECL, };
620 public String[] getConfiguredPHPContentTypes() {
621 return new String[] { IDocument.DEFAULT_CONTENT_TYPE, IPHPPartitions.PHP_PARTITIONING, IPHPPartitions.PHP_SINGLELINE_COMMENT,
622 IPHPPartitions.PHP_MULTILINE_COMMENT, IPHPPartitions.PHP_PHPDOC_COMMENT, IPHPPartitions.PHP_STRING_DQ,
623 IPHPPartitions.PHP_STRING_SQ, IPHPPartitions.CSS, IPHPPartitions.CSS_MULTILINE_COMMENT, IPHPPartitions.JAVASCRIPT,
624 IPHPPartitions.JS_MULTILINE_COMMENT, IPHPPartitions.SMARTY, IPHPPartitions.SMARTY_MULTILINE_COMMENT, };
628 * @see org.eclipse.jface.text.source.SourceViewerConfiguration#getConfiguredDocumentPartitioning(org.eclipse.jface.text.source.ISourceViewer)
631 public String getConfiguredDocumentPartitioning(ISourceViewer sourceViewer) {
632 if (fDocumentPartitioning != null)
633 return fDocumentPartitioning;
634 return super.getConfiguredDocumentPartitioning(sourceViewer);
638 * (non-Javadoc) Method declared on SourceViewerConfiguration
640 public IContentAssistant getContentAssistant(ISourceViewer sourceViewer) {
641 ContentAssistant assistant = new ContentAssistant();
642 IContentAssistProcessor processor = new HTMLCompletionProcessor(getEditor());
643 assistant.setDocumentPartitioning(getConfiguredDocumentPartitioning(sourceViewer));
644 assistant.setContentAssistProcessor(processor, IPHPPartitions.HTML);
645 assistant.setContentAssistProcessor(processor, IPHPPartitions.HTML_MULTILINE_COMMENT);
647 assistant.setContentAssistProcessor(processor, IPHPPartitions.CSS);
648 assistant.setContentAssistProcessor(processor, IPHPPartitions.CSS_MULTILINE_COMMENT);
649 assistant.setContentAssistProcessor(processor, IPHPPartitions.JAVASCRIPT);
650 assistant.setContentAssistProcessor(processor, IPHPPartitions.JS_MULTILINE_COMMENT);
651 // TODO define special smarty partition content assist
652 assistant.setContentAssistProcessor(processor, IPHPPartitions.SMARTY);
653 assistant.setContentAssistProcessor(processor, IPHPPartitions.SMARTY_MULTILINE_COMMENT);
655 assistant.setContentAssistProcessor(processor, PHPDocumentPartitioner.PHP_TEMPLATE_DATA);
656 String[] htmlTypes = getConfiguredHTMLContentTypes();
657 for (int i = 0; i < htmlTypes.length; i++) {
658 assistant.setContentAssistProcessor(processor, htmlTypes[i]);
660 processor = new PHPCompletionProcessor(getEditor());
662 assistant.setContentAssistProcessor(processor, PHPDocumentPartitioner.PHP_SCRIPT_CODE);
663 assistant.setContentAssistProcessor(processor, IPHPPartitions.PHP_PARTITIONING);
664 assistant.setContentAssistProcessor(processor, IPHPPartitions.PHP_STRING_DQ);
665 assistant.setContentAssistProcessor(processor, IPHPPartitions.PHP_STRING_SQ);
667 assistant.setContentAssistProcessor(new PHPDocCompletionProcessor(getEditor()), IPHPPartitions.PHP_PHPDOC_COMMENT);
668 // assistant.enableAutoActivation(true);
669 // assistant.setAutoActivationDelay(500);
670 // assistant.setProposalPopupOrientation(ContentAssistant.PROPOSAL_OVERLAY);
671 // ContentAssistPreference.configure(assistant, getPreferenceStore());
672 // assistant.setContextInformationPopupOrientation(
673 // ContentAssistant.CONTEXT_INFO_ABOVE);
674 // assistant.setContextInformationPopupBackground(
675 // PHPEditorEnvironment.getPHPColorProvider().getColor(
676 // new RGB(150, 150, 0)));
677 ContentAssistPreference.configure(assistant, getPreferenceStore());
678 assistant.setContextInformationPopupOrientation(ContentAssistant.CONTEXT_INFO_ABOVE);
679 assistant.setInformationControlCreator(getInformationControlCreator(sourceViewer));
684 * (non-Javadoc) Method declared on SourceViewerConfiguration
686 // public String getDefaultPrefix(ISourceViewer sourceViewer, String
688 // return (PHPPartitionScanner.PHP.equals(contentType) ? "//" : null);
690 // // return (IDocument.DEFAULT_CONTENT_TYPE.equals(contentType) ? "//" :
691 // null); //$NON-NLS-1$
694 * @see SourceViewerConfiguration#getDefaultPrefix(ISourceViewer, String)
697 public String[] getDefaultPrefixes(ISourceViewer sourceViewer, String contentType) {
698 return new String[] { "//", "" }; //$NON-NLS-1$ //$NON-NLS-2$
702 * (non-Javadoc) Method declared on SourceViewerConfiguration
704 public ITextDoubleClickStrategy getDoubleClickStrategy(ISourceViewer sourceViewer, String contentType) {
705 return new PHPDoubleClickSelector();
709 * @see SourceViewerConfiguration#getIndentPrefixes(ISourceViewer, String)
711 public String[] getIndentPrefixes(ISourceViewer sourceViewer, String contentType) {
712 Vector vector = new Vector();
713 // prefix[0] is either '\t' or ' ' x tabWidth, depending on useSpaces
714 final IPreferenceStore preferences = PHPeclipsePlugin.getDefault().getPreferenceStore();
715 int tabWidth = preferences.getInt(JavaCore.FORMATTER_TAB_SIZE);
716 boolean useSpaces = getPreferenceStore().getBoolean(SPACES_FOR_TABS);
717 for (int i = 0; i <= tabWidth; i++) {
718 StringBuffer prefix = new StringBuffer();
720 for (int j = 0; j + i < tabWidth; j++)
725 for (int j = 0; j < i; j++)
730 vector.add(prefix.toString());
732 vector.add(""); //$NON-NLS-1$
733 return (String[]) vector.toArray(new String[vector.size()]);
737 * @return <code>true</code> iff the new setup without text tools is in use.
741 private boolean isNewSetup() {
742 return fJavaTextTools == null;
746 * Creates and returns a preference store which combines the preference stores from the text tools and which is read-only.
748 * @return the read-only preference store
751 private IPreferenceStore createPreferenceStore() {
752 Assert.isTrue(!isNewSetup());
753 IPreferenceStore generalTextStore = EditorsUI.getPreferenceStore();
754 if (fJavaTextTools.getCorePreferenceStore() == null)
755 return new ChainedPreferenceStore(new IPreferenceStore[] { fJavaTextTools.getPreferenceStore(), generalTextStore });
757 return new ChainedPreferenceStore(new IPreferenceStore[] { fJavaTextTools.getPreferenceStore(),
758 new PreferencesAdapter(fJavaTextTools.getCorePreferenceStore()), generalTextStore });
762 * (non-Javadoc) Method declared on SourceViewerConfiguration
764 public IPresentationReconciler getPresentationReconciler(ISourceViewer sourceViewer) {
765 // PHPColorProvider provider =
766 // PHPEditorEnvironment.getPHPColorProvider();
767 // JavaColorManager provider =
768 // PHPEditorEnvironment.getPHPColorProvider();
769 PresentationReconciler phpReconciler = new JavaPresentationReconciler();
770 phpReconciler.setDocumentPartitioning(getConfiguredDocumentPartitioning(sourceViewer));
772 // DefaultDamagerRepairer dr = new DefaultDamagerRepairer(getHTMLScanner());
773 // reconciler.setDamager(dr, IDocument.DEFAULT_CONTENT_TYPE);
774 // reconciler.setRepairer(dr, IDocument.DEFAULT_CONTENT_TYPE);
775 // dr = new DefaultDamagerRepairer(getHTMLScanner());
776 // reconciler.setDamager(dr, IPHPPartitions.HTML);
777 // reconciler.setRepairer(dr, IPHPPartitions.HTML);
778 // dr = new DefaultDamagerRepairer(getHTMLScanner());
779 // reconciler.setDamager(dr, IPHPPartitions.CSS);
780 // reconciler.setRepairer(dr, IPHPPartitions.CSS);
781 // dr = new DefaultDamagerRepairer(getHTMLScanner());
782 // reconciler.setDamager(dr, IPHPPartitions.CSS_MULTILINE_COMMENT);
783 // reconciler.setRepairer(dr, IPHPPartitions.CSS_MULTILINE_COMMENT);
784 // dr = new DefaultDamagerRepairer(getHTMLScanner());
785 // reconciler.setDamager(dr, IPHPPartitions.JAVASCRIPT);
786 // reconciler.setRepairer(dr, IPHPPartitions.JAVASCRIPT);
787 // dr = new DefaultDamagerRepairer(getHTMLScanner());
788 // reconciler.setDamager(dr, IPHPPartitions.JS_MULTILINE_COMMENT);
789 // reconciler.setRepairer(dr, IPHPPartitions.JS_MULTILINE_COMMENT);
790 // DefaultDamagerRepairer phpDR = new DefaultDamagerRepairer(getSmartyScanner());
791 // phpReconciler.setDamager(phpDR, IPHPPartitions.SMARTY);
792 // phpReconciler.setRepairer(phpDR, IPHPPartitions.SMARTY);
793 // phpDR = new DefaultDamagerRepairer(getSmartyDocScanner());
794 // phpReconciler.setDamager(phpDR, IPHPPartitions.SMARTY_MULTILINE_COMMENT);
795 // phpReconciler.setRepairer(phpDR, IPHPPartitions.SMARTY_MULTILINE_COMMENT);
796 // dr = new DefaultDamagerRepairer(new SingleTokenScanner(new TextAttribute(fJavaTextTools.getColorManager().getColor(
797 // PHPColorProvider.MULTI_LINE_COMMENT))));
798 // reconciler.setDamager(dr, IPHPPartitions.HTML_MULTILINE_COMMENT);
799 // reconciler.setRepairer(dr, IPHPPartitions.HTML_MULTILINE_COMMENT);
801 DefaultDamagerRepairer phpDR = new DefaultDamagerRepairer(getCodeScanner());
802 phpReconciler.setDamager(phpDR, IDocument.DEFAULT_CONTENT_TYPE);
803 phpReconciler.setRepairer(phpDR, IDocument.DEFAULT_CONTENT_TYPE);
805 phpDR = new DefaultDamagerRepairer(getCodeScanner());
806 phpReconciler.setDamager(phpDR, IPHPPartitions.PHP_PARTITIONING);
807 phpReconciler.setRepairer(phpDR, IPHPPartitions.PHP_PARTITIONING);
809 phpDR = new DefaultDamagerRepairer(getPHPDocScanner());
810 phpReconciler.setDamager(phpDR, IPHPPartitions.PHP_PHPDOC_COMMENT);
811 phpReconciler.setRepairer(phpDR, IPHPPartitions.PHP_PHPDOC_COMMENT);
813 phpDR = new DefaultDamagerRepairer(getStringScanner());
814 phpReconciler.setDamager(phpDR, IPHPPartitions.PHP_STRING_DQ);
815 phpReconciler.setRepairer(phpDR, IPHPPartitions.PHP_STRING_DQ);
816 phpDR = new DefaultDamagerRepairer(getStringScanner());
817 phpReconciler.setDamager(phpDR, IPHPPartitions.PHP_STRING_SQ);
818 phpReconciler.setRepairer(phpDR, IPHPPartitions.PHP_STRING_SQ);
819 phpDR = new DefaultDamagerRepairer(getSinglelineCommentScanner());
820 phpReconciler.setDamager(phpDR, IPHPPartitions.PHP_SINGLELINE_COMMENT);
821 phpReconciler.setRepairer(phpDR, IPHPPartitions.PHP_SINGLELINE_COMMENT);
822 phpDR = new DefaultDamagerRepairer(getMultilineCommentScanner());
823 phpReconciler.setDamager(phpDR, IPHPPartitions.PHP_MULTILINE_COMMENT);
824 phpReconciler.setRepairer(phpDR, IPHPPartitions.PHP_MULTILINE_COMMENT);
826 PresentationReconciler reconciler = new PresentationReconciler();
827 reconciler.setDocumentPartitioning(getConfiguredDocumentPartitioning(sourceViewer));
829 JavaTextTools jspTextTools = PHPeclipsePlugin.getDefault().getJavaTextTools();
830 DefaultDamagerRepairer dr = new DefaultDamagerRepairer(getPHPDocScanner());//jspTextTools.getJSPTextScanner());
831 reconciler.setDamager(dr, IDocument.DEFAULT_CONTENT_TYPE);
832 reconciler.setRepairer(dr, IDocument.DEFAULT_CONTENT_TYPE);
834 // dr = new DefaultDamagerRepairer(new SingleTokenScanner(new TextAttribute(fJavaTextTools.getColorManager().getColor(
835 // PHPColorProvider.PHPDOC_TAG))));//jspTextTools.getJSPBracketScanner());
836 // reconciler.setDamager(dr, JSPScriptScanner.JSP_BRACKET);
837 // reconciler.setRepairer(dr, JSPScriptScanner.JSP_BRACKET);
840 configureEmbeddedPresentationReconciler(reconciler, xmlConfiguration.getPresentationReconciler(sourceViewer), xmlConfiguration
841 .getConfiguredContentTypes(sourceViewer), PHPDocumentPartitioner.PHP_TEMPLATE_DATA);
844 configureEmbeddedPresentationReconciler(reconciler, phpReconciler, getConfiguredPHPContentTypes(),
845 PHPDocumentPartitioner.PHP_SCRIPT_CODE);
850 private void configureEmbeddedPresentationReconciler(PresentationReconciler reconciler, IPresentationReconciler embedded,
851 String[] types, String defaultType) {
852 for (int i = 0; i < types.length; i++) {
853 String type = types[i];
855 IPresentationDamager damager = embedded.getDamager(type);
856 IPresentationRepairer repairer = embedded.getRepairer(type);
858 if (type == IDocument.DEFAULT_CONTENT_TYPE) {
862 reconciler.setDamager(damager, type);
863 reconciler.setRepairer(repairer, type);
868 * (non-Javadoc) Method declared on SourceViewerConfiguration
870 public int getTabWidth(ISourceViewer sourceViewer) {
871 return getPreferenceStore().getInt(PREFERENCE_TAB_WIDTH);
875 * (non-Javadoc) Method declared on SourceViewerConfiguration
877 // public ITextHover getTextHover(ISourceViewer sourceViewer, String
879 // if (fEditor != null) {
880 // IEditorInput editorInput = fEditor.getEditorInput();
881 // if (editorInput instanceof IFileEditorInput) {
883 // IFile f = ((IFileEditorInput) editorInput).getFile();
884 // return new PHPTextHover(f.getProject());
885 // } catch (NullPointerException e) {
886 // // this exception occurs, if getTextHover is called by preference pages
891 // return new PHPTextHover(null);
894 * @see SourceViewerConfiguration#getInformationControlCreator(ISourceViewer)
897 public IInformationControlCreator getInformationControlCreator(ISourceViewer sourceViewer) {
898 return new IInformationControlCreator() {
899 public IInformationControl createInformationControl(Shell parent) {
900 return new DefaultInformationControl(parent, SWT.NONE, new HTMLTextPresenter(true));
901 // return new HoverBrowserControl(parent);
907 * @see SourceViewerConfiguration#getInformationPresenter(ISourceViewer)
910 public IInformationPresenter getInformationPresenter(ISourceViewer sourceViewer) {
911 InformationPresenter presenter = new InformationPresenter(getInformationPresenterControlCreator(sourceViewer));
912 presenter.setDocumentPartitioning(getConfiguredDocumentPartitioning(sourceViewer));
913 IInformationProvider provider = new JavaInformationProvider(getEditor());
914 presenter.setInformationProvider(provider, IDocument.DEFAULT_CONTENT_TYPE);
915 presenter.setInformationProvider(provider, IPHPPartitions.PHP_PHPDOC_COMMENT);
916 // presenter.setInformationProvider(provider, IPHPPartitions.JAVA_CHARACTER);
917 presenter.setSizeConstraints(60, 10, true, true);
922 * @see SourceViewerConfiguration#getInformationPresenter(ISourceViewer)
925 // public IInformationPresenter getInformationPresenter(ISourceViewer
927 // InformationPresenter presenter= new
928 // InformationPresenter(getInformationPresenterControlCreator(sourceViewer));
929 // IInformationProvider provider= new JavaInformationProvider(getEditor());
930 // presenter.setInformationProvider(provider,
931 // IDocument.DEFAULT_CONTENT_TYPE);
932 // presenter.setInformationProvider(provider, IJavaPartitions.JAVA_DOC);
933 // presenter.setSizeConstraints(60, 10, true, true);
937 * Returns the information presenter control creator. The creator is a factory creating the presenter controls for the given
938 * source viewer. This implementation always returns a creator for <code>DefaultInformationControl</code> instances.
940 * @param sourceViewer
941 * the source viewer to be configured by this configuration
942 * @return an information control creator
945 private IInformationControlCreator getInformationPresenterControlCreator(ISourceViewer sourceViewer) {
946 return new IInformationControlCreator() {
947 public IInformationControl createInformationControl(Shell parent) {
948 int shellStyle = SWT.RESIZE;
949 int style = SWT.V_SCROLL | SWT.H_SCROLL;
950 return new DefaultInformationControl(parent, shellStyle, style, new HTMLTextPresenter(false));
951 // return new HoverBrowserControl(parent);
957 * Returns the outline presenter control creator. The creator is a factory creating outline presenter controls for the given
958 * source viewer. This implementation always returns a creator for <code>JavaOutlineInformationControl</code> instances.
960 * @param sourceViewer
961 * the source viewer to be configured by this configuration
962 * @return an information control creator
965 private IInformationControlCreator getOutlinePresenterControlCreator(ISourceViewer sourceViewer) {
966 return new IInformationControlCreator() {
967 public IInformationControl createInformationControl(Shell parent) {
968 int shellStyle = SWT.RESIZE;
969 int treeStyle = SWT.V_SCROLL | SWT.H_SCROLL;
970 return new JavaOutlineInformationControl(parent, shellStyle, treeStyle);
976 * Returns the outline presenter which will determine and shown information requested for the current cursor position.
978 * @param sourceViewer
979 * the source viewer to be configured by this configuration
980 * @param doCodeResolve
981 * a boolean which specifies whether code resolve should be used to compute the Java element
982 * @return an information presenter
985 public IInformationPresenter getOutlinePresenter(ISourceViewer sourceViewer, boolean doCodeResolve) {
986 InformationPresenter presenter = new InformationPresenter(getOutlinePresenterControlCreator(sourceViewer));
987 presenter.setAnchor(InformationPresenter.ANCHOR_GLOBAL);
988 IInformationProvider provider = new JavaElementProvider(getEditor(), doCodeResolve);
989 presenter.setInformationProvider(provider, IDocument.DEFAULT_CONTENT_TYPE);
990 presenter.setInformationProvider(provider, IPHPPartitions.PHP_PARTITIONING);
991 presenter.setInformationProvider(provider, IPHPPartitions.PHP_PHPDOC_COMMENT);
992 presenter.setInformationProvider(provider, IPHPPartitions.SMARTY_MULTILINE_COMMENT);
993 presenter.setInformationProvider(provider, IPHPPartitions.HTML);
994 presenter.setInformationProvider(provider, IPHPPartitions.HTML_MULTILINE_COMMENT);
995 presenter.setSizeConstraints(40, 20, true, false);