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
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.JavaDocAutoIndentStrategy;
35 import net.sourceforge.phpdt.internal.ui.text.phpdoc.PHPDocCodeScanner;
36 import net.sourceforge.phpdt.internal.ui.text.phpdoc.PHPDocCompletionProcessor;
37 import net.sourceforge.phpdt.ui.PreferenceConstants;
38 import net.sourceforge.phpeclipse.IPreferenceConstants;
39 import net.sourceforge.phpeclipse.PHPeclipsePlugin;
40 import net.sourceforge.phpeclipse.phpeditor.html.HTMLFormattingStrategy;
41 import net.sourceforge.phpeclipse.phpeditor.php.HTMLCompletionProcessor;
42 import net.sourceforge.phpeclipse.phpeditor.php.PHPAutoIndentStrategy;
43 import net.sourceforge.phpeclipse.phpeditor.php.PHPCodeScanner;
44 import net.sourceforge.phpeclipse.phpeditor.php.PHPCompletionProcessor;
45 import net.sourceforge.phpeclipse.phpeditor.php.PHPDocumentPartitioner;
46 import net.sourceforge.phpeclipse.phpeditor.php.PHPDoubleClickSelector;
47 import net.sourceforge.phpeclipse.phpeditor.php.PHPPartitionScanner;
48 import net.sourceforge.phpeclipse.xml.ui.XMLPlugin;
49 import net.sourceforge.phpeclipse.xml.ui.internal.text.XMLConfiguration;
50 import net.sourceforge.phpeclipse.xml.ui.internal.text.XMLPartitionScanner;
51 import net.sourceforge.phpeclipse.xml.ui.text.XMLTextTools;
53 import org.eclipse.core.runtime.NullProgressMonitor;
54 import org.eclipse.jface.preference.IPreferenceStore;
55 import org.eclipse.jface.text.DefaultAutoIndentStrategy;
56 import org.eclipse.jface.text.DefaultInformationControl;
57 import org.eclipse.jface.text.IAutoIndentStrategy;
58 import org.eclipse.jface.text.IDocument;
59 import org.eclipse.jface.text.IInformationControl;
60 import org.eclipse.jface.text.IInformationControlCreator;
61 import org.eclipse.jface.text.ITextDoubleClickStrategy;
62 import org.eclipse.jface.text.ITextHover;
63 import org.eclipse.jface.text.ITextViewerExtension2;
64 import org.eclipse.jface.text.TextAttribute;
65 import org.eclipse.jface.text.contentassist.ContentAssistant;
66 import org.eclipse.jface.text.contentassist.IContentAssistProcessor;
67 import org.eclipse.jface.text.contentassist.IContentAssistant;
68 import org.eclipse.jface.text.formatter.ContentFormatter;
69 import org.eclipse.jface.text.formatter.IContentFormatter;
70 import org.eclipse.jface.text.formatter.IFormattingStrategy;
71 import org.eclipse.jface.text.information.IInformationPresenter;
72 import org.eclipse.jface.text.information.IInformationProvider;
73 import org.eclipse.jface.text.information.InformationPresenter;
74 import org.eclipse.jface.text.presentation.IPresentationDamager;
75 import org.eclipse.jface.text.presentation.IPresentationReconciler;
76 import org.eclipse.jface.text.presentation.IPresentationRepairer;
77 import org.eclipse.jface.text.presentation.PresentationReconciler;
78 import org.eclipse.jface.text.reconciler.IReconciler;
79 import org.eclipse.jface.text.rules.BufferedRuleBasedScanner;
80 import org.eclipse.jface.text.rules.DefaultDamagerRepairer;
81 import org.eclipse.jface.text.rules.DefaultPartitioner;
82 import org.eclipse.jface.text.rules.RuleBasedScanner;
83 import org.eclipse.jface.text.rules.Token;
84 import org.eclipse.jface.text.source.IAnnotationHover;
85 import org.eclipse.jface.text.source.ISourceViewer;
86 import org.eclipse.jface.text.source.SourceViewerConfiguration;
87 import org.eclipse.jface.util.Assert;
88 import org.eclipse.jface.util.PropertyChangeEvent;
89 import org.eclipse.swt.SWT;
90 import org.eclipse.swt.widgets.Shell;
91 import org.eclipse.ui.editors.text.EditorsUI;
92 import org.eclipse.ui.texteditor.ChainedPreferenceStore;
93 import org.eclipse.ui.texteditor.ITextEditor;
96 * Configuration for an <code>SourceViewer</code> which shows PHP code.
98 public class PHPSourceViewerConfiguration extends SourceViewerConfiguration {
100 * Preference key used to look up display tab width.
104 public final static String PREFERENCE_TAB_WIDTH = PreferenceConstants.EDITOR_TAB_WIDTH;
107 * Preference key for inserting spaces rather than tabs.
111 public final static String SPACES_FOR_TABS = PreferenceConstants.EDITOR_SPACES_FOR_TABS;
113 // public static final String HTML_DEFAULT =
114 // IPHPPartitionScannerConstants.HTML;
115 //IDocument.DEFAULT_CONTENT_TYPE;
116 private JavaTextTools fJavaTextTools;
118 private ITextEditor fTextEditor;
121 * The document partitioning.
125 private String fDocumentPartitioning;
127 private ContentFormatter fFormatter;
129 private HTMLFormattingStrategy fFormattingStrategy;
132 * Single token scanner.
134 static class SingleTokenScanner extends BufferedRuleBasedScanner {
135 public SingleTokenScanner(TextAttribute attribute) {
136 setDefaultReturnToken(new Token(attribute));
141 * The document partitioning.
145 // private String fDocumentPartitioning;
147 * The Java source code scanner
151 private AbstractJavaScanner fCodeScanner;
154 * The Java multi-line comment scanner
158 private AbstractJavaScanner fMultilineCommentScanner;
161 * The Java single-line comment scanner
165 private AbstractJavaScanner fSinglelineCommentScanner;
168 * The PHP double quoted string scanner
170 private AbstractJavaScanner fStringDQScanner;
172 * The PHP single quoted string scanner
174 private AbstractJavaScanner fStringSQScanner;
177 * The Javadoc scanner
181 private AbstractJavaScanner fJavaDocScanner;
184 * The preference store, can be read-only
188 private IPreferenceStore fPreferenceStore;
195 private IColorManager fColorManager;
197 private XMLTextTools fXMLTextTools;
199 private XMLConfiguration xmlConfiguration;
202 * Creates a new Java source viewer configuration for viewers in the given editor using the given preference store, the color
203 * manager and the specified document partitioning.
205 * Creates a Java source viewer configuration in the new setup without text tools. Clients are allowed to call
206 * {@link JavaSourceViewerConfiguration#handlePropertyChangeEvent(PropertyChangeEvent)}and disallowed to call
207 * {@link JavaSourceViewerConfiguration#getPreferenceStore()}on the resulting Java source viewer configuration.
210 * @param colorManager
212 * @param preferenceStore
213 * the preference store, can be read-only
215 * the editor in which the configured viewer(s) will reside
216 * @param partitioning
217 * the document partitioning for this configuration
220 public PHPSourceViewerConfiguration(IColorManager colorManager, IPreferenceStore preferenceStore, ITextEditor editor,
221 String partitioning) {
222 fColorManager = colorManager;
223 fPreferenceStore = preferenceStore;
224 fTextEditor = editor;
225 fDocumentPartitioning = partitioning;
226 // fJavaTextTools = PHPeclipsePlugin.getDefault().getJavaTextTools();
227 fXMLTextTools = XMLPlugin.getDefault().getXMLTextTools();
228 xmlConfiguration = new XMLConfiguration(fXMLTextTools);
229 fColorManager = colorManager;
230 fPreferenceStore = preferenceStore;
231 fTextEditor = editor;
232 fDocumentPartitioning = partitioning;
234 initializeScanners();
238 * Creates a new Java source viewer configuration for viewers in the given editor using the given Java tools.
241 * the Java text tools to be used
243 * the editor in which the configured viewer(s) will reside
245 * @deprecated As of 3.0, replaced by
246 * {@link JavaSourceViewerConfiguration#JavaSourceViewerConfiguration(IColorManager, IPreferenceStore, ITextEditor, String)}
248 // public PHPSourceViewerConfiguration(JavaTextTools tools, PHPEditor editor, String partitioning) {
249 // fJavaTextTools = tools;
250 // fColorManager = tools.getColorManager();
251 // fPreferenceStore = createPreferenceStore();
252 // fDocumentPartitioning = partitioning;
253 // fCodeScanner = (AbstractJavaScanner) fJavaTextTools.getCodeScanner();
254 // fMultilineCommentScanner = (AbstractJavaScanner) fJavaTextTools.getMultilineCommentScanner();
255 // fSinglelineCommentScanner = (AbstractJavaScanner) fJavaTextTools.getSinglelineCommentScanner();
256 // fStringDQScanner = (AbstractJavaScanner) fJavaTextTools.getStringScanner();
257 // fJavaDocScanner = (AbstractJavaScanner) fJavaTextTools.getJavaDocScanner();
258 // fTextEditor = editor;
259 // fXMLTextTools = XMLPlugin.getDefault().getXMLTextTools();
260 // xmlConfiguration = new XMLConfiguration(fXMLTextTools);
263 * Returns the color manager for this configuration.
265 * @return the color manager
267 protected IColorManager getColorManager() {
268 return fColorManager;
272 * Initializes the scanners.
276 private void initializeScanners() {
277 Assert.isTrue(isNewSetup());
278 fCodeScanner = new PHPCodeScanner(getColorManager(), fPreferenceStore);
279 fMultilineCommentScanner = new SingleTokenPHPScanner(getColorManager(), fPreferenceStore,
280 IPreferenceConstants.PHP_MULTILINE_COMMENT);
281 fSinglelineCommentScanner = new SingleTokenPHPScanner(getColorManager(), fPreferenceStore,
282 IPreferenceConstants.PHP_SINGLELINE_COMMENT);
283 // fStringDQScanner = new SingleTokenPHPScanner(getColorManager(), fPreferenceStore, IPreferenceConstants.PHP_STRING_DQ);
284 fStringDQScanner = new PHPStringDQCodeScanner(getColorManager(), fPreferenceStore);
285 fStringSQScanner = new SingleTokenPHPScanner(getColorManager(), fPreferenceStore, IPreferenceConstants.PHP_STRING_SQ);
286 fJavaDocScanner = new PHPDocCodeScanner(getColorManager(), fPreferenceStore);
290 * Determines whether the preference change encoded by the given event changes the behavior of one of its contained components.
293 * the event to be investigated
294 * @return <code>true</code> if event causes a behavioral change
297 public boolean affectsTextPresentation(PropertyChangeEvent event) {
298 return fCodeScanner.affectsBehavior(event) || fMultilineCommentScanner.affectsBehavior(event)
299 || fSinglelineCommentScanner.affectsBehavior(event) || fStringDQScanner.affectsBehavior(event)|| fStringSQScanner.affectsBehavior(event)
300 || fJavaDocScanner.affectsBehavior(event);
304 * Adapts the behavior of the contained components to the change encoded in the given event.
306 * Clients are not allowed to call this method if the old setup with text tools is in use.
310 * the event to which to adapt
311 * @see JavaSourceViewerConfiguration#JavaSourceViewerConfiguration(IColorManager, IPreferenceStore, ITextEditor, String)
314 public void handlePropertyChangeEvent(PropertyChangeEvent event) {
315 Assert.isTrue(isNewSetup());
316 if (fCodeScanner.affectsBehavior(event))
317 fCodeScanner.adaptToPreferenceChange(event);
318 if (fMultilineCommentScanner.affectsBehavior(event))
319 fMultilineCommentScanner.adaptToPreferenceChange(event);
320 if (fSinglelineCommentScanner.affectsBehavior(event))
321 fSinglelineCommentScanner.adaptToPreferenceChange(event);
322 if (fStringDQScanner.affectsBehavior(event))
323 fStringDQScanner.adaptToPreferenceChange(event);
324 if (fStringSQScanner.affectsBehavior(event))
325 fStringSQScanner.adaptToPreferenceChange(event);
326 if (fJavaDocScanner.affectsBehavior(event))
327 fJavaDocScanner.adaptToPreferenceChange(event);
331 * @see SourceViewerConfiguration#getContentFormatter(ISourceViewer)
333 public IContentFormatter getContentFormatter(ISourceViewer sourceViewer) {
334 // if (fFormatter == null) {
335 // fFormatter = new ContentFormatter();
336 // fFormattingStrategy = new HTMLFormattingStrategy(this,
338 // fFormatter.setFormattingStrategy(fFormattingStrategy, HTML_DEFAULT);
339 // fFormatter.enablePartitionAwareFormatting(false);
340 // fFormatter.setPartitionManagingPositionCategories(getConfiguredContentTypes(null));
342 // return fFormatter;
343 if (fFormatter == null) {
345 fFormatter = new ContentFormatter();
346 IFormattingStrategy strategy = new JavaFormattingStrategy(sourceViewer);
347 fFormatter.setFormattingStrategy(strategy, IDocument.DEFAULT_CONTENT_TYPE);
348 fFormatter.enablePartitionAwareFormatting(false);
349 fFormatter.setPartitionManagingPositionCategories(getPartitionManagingPositionCategories());
355 * Returns the names of the document position categories used by the document partitioners created by this object to manage their
356 * partition information. If the partitioners don't use document position categories, the returned result is <code>null</code>.
358 * @return the partition managing position categories or <code>null</code> if there is none
360 public String[] getPartitionManagingPositionCategories() {
361 return new String[] { DefaultPartitioner.CONTENT_TYPES_CATEGORY };
365 // * Returns the names of the document position categories used by the
367 // * partitioners created by this object to manage their partition
369 // * If the partitioners don't use document position categories, the
371 // * result is <code>null</code>.
373 // * @return the partition managing position categories or
375 // * if there is none
377 // private String[] getPartitionManagingPositionCategories() {
378 // return new String[] { DefaultPartitioner.CONTENT_TYPES_CATEGORY };
380 public ITextEditor getEditor() {
385 * Returns the preference store used by this configuration to initialize the individual bits and pieces.
387 * @return the preference store used to initialize this configuration
391 protected IPreferenceStore getPreferenceStore() {
392 return PHPeclipsePlugin.getDefault().getPreferenceStore();
396 // * Method declared on SourceViewerConfiguration
398 // public IAnnotationHover getAnnotationHover(ISourceViewer sourceViewer) {
399 // return new PHPAnnotationHover();
402 * @see SourceViewerConfiguration#getAnnotationHover(ISourceViewer)
404 public IAnnotationHover getAnnotationHover(ISourceViewer sourceViewer) {
405 return new JavaAnnotationHover(JavaAnnotationHover.VERTICAL_RULER_HOVER);
409 * @see SourceViewerConfiguration#getOverviewRulerAnnotationHover(ISourceViewer)
412 public IAnnotationHover getOverviewRulerAnnotationHover(ISourceViewer sourceViewer) {
413 return new JavaAnnotationHover(JavaAnnotationHover.OVERVIEW_RULER_HOVER);
417 * (non-Javadoc) Method declared on SourceViewerConfiguration
419 public IAutoIndentStrategy getAutoIndentStrategy(ISourceViewer sourceViewer, String contentType) {
420 if (IPHPPartitions.PHP_PHPDOC_COMMENT.equals(contentType)
421 || IPHPPartitions.PHP_MULTILINE_COMMENT.equals(contentType))
422 return new JavaDocAutoIndentStrategy(getConfiguredDocumentPartitioning(sourceViewer));
423 if (IPHPPartitions.PHP_STRING_DQ.equals(contentType))
424 return new JavaStringAutoIndentStrategyDQ(getConfiguredDocumentPartitioning(sourceViewer));
425 if (IPHPPartitions.PHP_STRING_SQ.equals(contentType))
426 return new JavaStringAutoIndentStrategySQ(getConfiguredDocumentPartitioning(sourceViewer));
428 return (PHPDocumentPartitioner.PHP_TEMPLATE_DATA.equals(contentType)
429 || PHPDocumentPartitioner.PHP_SCRIPT_CODE.equals(contentType) || IDocument.DEFAULT_CONTENT_TYPE.equals(contentType)
430 || IPHPPartitions.PHP_PARTITIONING.equals(contentType) || PHPPartitionScanner.PHP_SCRIPTING_AREA.equals(contentType) ? new PHPAutoIndentStrategy()
431 : new DefaultAutoIndentStrategy());
435 * Returns the PHP source code scanner for this configuration.
437 * @return the PHP source code scanner
439 protected RuleBasedScanner getCodeScanner() {
440 return fCodeScanner; //fJavaTextTools.getCodeScanner();
444 * Returns the Java multi-line comment scanner for this configuration.
446 * @return the Java multi-line comment scanner
449 protected RuleBasedScanner getMultilineCommentScanner() {
450 return fMultilineCommentScanner;
454 * Returns the Java single-line comment scanner for this configuration.
456 * @return the Java single-line comment scanner
459 protected RuleBasedScanner getSinglelineCommentScanner() {
460 return fSinglelineCommentScanner;
464 * Returns the PHP double quoted string scanner for this configuration.
466 * @return the PHP double quoted string scanner
468 protected RuleBasedScanner getStringDQScanner() {
469 return fStringDQScanner;
473 * Returns the PHP single quoted string scanner for this configuration.
475 * @return the PHP single quoted string scanner
477 protected RuleBasedScanner getStringSQScanner() {
478 return fStringSQScanner;
481 * Returns the HTML source code scanner for this configuration.
483 * @return the HTML source code scanner
485 // protected RuleBasedScanner getHTMLScanner() {
486 // return fJavaTextTools.getHTMLScanner();
489 * Returns the Smarty source code scanner for this configuration.
491 * @return the Smarty source code scanner
493 // protected RuleBasedScanner getSmartyScanner() {
494 // return fJavaTextTools.getSmartyScanner();
497 * @see SourceViewerConfiguration#getReconciler(ISourceViewer)
500 * @see SourceViewerConfiguration#getReconciler(ISourceViewer)
502 public IReconciler getReconciler(ISourceViewer sourceViewer) {
504 final ITextEditor editor = getEditor();
505 if (editor != null && editor.isEditable()) {
507 JavaCompositeReconcilingStrategy strategy = new JavaCompositeReconcilingStrategy(editor,
508 getConfiguredDocumentPartitioning(sourceViewer));
509 JavaReconciler reconciler = new JavaReconciler(editor, strategy, false);
510 reconciler.setIsIncrementalReconciler(false);
511 reconciler.setProgressMonitor(new NullProgressMonitor());
512 reconciler.setDelay(500);
520 * @see SourceViewerConfiguration#getConfiguredTextHoverStateMasks(ISourceViewer, String)
523 public int[] getConfiguredTextHoverStateMasks(ISourceViewer sourceViewer, String contentType) {
524 JavaEditorTextHoverDescriptor[] hoverDescs = PHPeclipsePlugin.getDefault().getJavaEditorTextHoverDescriptors();
525 int stateMasks[] = new int[hoverDescs.length];
526 int stateMasksLength = 0;
527 for (int i = 0; i < hoverDescs.length; i++) {
528 if (hoverDescs[i].isEnabled()) {
530 int stateMask = hoverDescs[i].getStateMask();
531 while (j < stateMasksLength) {
532 if (stateMasks[j] == stateMask)
536 if (j == stateMasksLength)
537 stateMasks[stateMasksLength++] = stateMask;
540 if (stateMasksLength == hoverDescs.length)
542 int[] shortenedStateMasks = new int[stateMasksLength];
543 System.arraycopy(stateMasks, 0, shortenedStateMasks, 0, stateMasksLength);
544 return shortenedStateMasks;
548 * @see SourceViewerConfiguration#getTextHover(ISourceViewer, String, int)
551 public ITextHover getTextHover(ISourceViewer sourceViewer, String contentType, int stateMask) {
552 JavaEditorTextHoverDescriptor[] hoverDescs = PHPeclipsePlugin.getDefault().getJavaEditorTextHoverDescriptors();
554 while (i < hoverDescs.length) {
555 if (hoverDescs[i].isEnabled() && hoverDescs[i].getStateMask() == stateMask)
556 return new JavaEditorTextHoverProxy(hoverDescs[i], getEditor());
560 // if (fEditor != null) {
561 // IEditorInput editorInput = fEditor.getEditorInput();
562 // if (editorInput instanceof IFileEditorInput) {
564 // IFile f = ((IFileEditorInput) editorInput).getFile();
565 // return new PHPTextHover(f.getProject());
566 // } catch (NullPointerException e) {
567 // // this exception occurs, if getTextHover is called by
568 // // preference pages !
572 // return new PHPTextHover(null);
576 * @see SourceViewerConfiguration#getTextHover(ISourceViewer, String)
578 public ITextHover getTextHover(ISourceViewer sourceViewer, String contentType) {
579 return getTextHover(sourceViewer, contentType, ITextViewerExtension2.DEFAULT_HOVER_STATE_MASK);
583 * Returns the SmartyDoc source code scanner for this configuration.
585 * @return the SmartyDoc source code scanner
587 // protected RuleBasedScanner getSmartyDocScanner() {
588 // return fJavaTextTools.getSmartyDocScanner();
591 * Returns the PHPDoc source code scanner for this configuration.
593 * @return the PHPDoc source code scanner
595 protected RuleBasedScanner getPHPDocScanner() {
596 return fJavaDocScanner; //fJavaTextTools.getJavaDocScanner();
600 * (non-Javadoc) Method declared on SourceViewerConfiguration
602 public String[] getConfiguredContentTypes(ISourceViewer sourceViewer) {
603 return new String[] { IDocument.DEFAULT_CONTENT_TYPE, PHPPartitionScanner.PHP_SCRIPTING_AREA,
605 IPHPPartitions.HTML, IPHPPartitions.HTML_MULTILINE_COMMENT, IPHPPartitions.PHP_PARTITIONING,
606 IPHPPartitions.PHP_SINGLELINE_COMMENT, IPHPPartitions.PHP_MULTILINE_COMMENT, IPHPPartitions.PHP_PHPDOC_COMMENT,
607 IPHPPartitions.PHP_STRING_DQ, IPHPPartitions.PHP_STRING_SQ, IPHPPartitions.CSS, IPHPPartitions.CSS_MULTILINE_COMMENT,
608 IPHPPartitions.JAVASCRIPT, IPHPPartitions.JS_MULTILINE_COMMENT, IPHPPartitions.SMARTY,
609 IPHPPartitions.SMARTY_MULTILINE_COMMENT,
611 XMLPartitionScanner.XML_PI, XMLPartitionScanner.XML_COMMENT, XMLPartitionScanner.XML_DECL, XMLPartitionScanner.XML_TAG,
612 XMLPartitionScanner.XML_ATTRIBUTE, XMLPartitionScanner.XML_CDATA,
614 XMLPartitionScanner.DTD_INTERNAL, XMLPartitionScanner.DTD_INTERNAL_PI, XMLPartitionScanner.DTD_INTERNAL_COMMENT,
615 XMLPartitionScanner.DTD_INTERNAL_DECL,
617 PHPDocumentPartitioner.PHP_TEMPLATE_DATA, PHPDocumentPartitioner.PHP_SCRIPT_CODE };
620 public String[] getConfiguredHTMLContentTypes() {
621 return new String[] { XMLPartitionScanner.XML_PI, XMLPartitionScanner.XML_COMMENT, XMLPartitionScanner.XML_DECL,
622 XMLPartitionScanner.XML_TAG, XMLPartitionScanner.XML_ATTRIBUTE, XMLPartitionScanner.XML_CDATA,
624 XMLPartitionScanner.DTD_INTERNAL, XMLPartitionScanner.DTD_INTERNAL_PI, XMLPartitionScanner.DTD_INTERNAL_COMMENT,
625 XMLPartitionScanner.DTD_INTERNAL_DECL, };
628 public String[] getConfiguredPHPContentTypes() {
629 return new String[] { IDocument.DEFAULT_CONTENT_TYPE, IPHPPartitions.PHP_PARTITIONING, IPHPPartitions.PHP_SINGLELINE_COMMENT,
630 IPHPPartitions.PHP_MULTILINE_COMMENT, IPHPPartitions.PHP_PHPDOC_COMMENT, IPHPPartitions.PHP_STRING_DQ,
631 IPHPPartitions.PHP_STRING_SQ, IPHPPartitions.CSS, IPHPPartitions.CSS_MULTILINE_COMMENT, IPHPPartitions.JAVASCRIPT,
632 IPHPPartitions.JS_MULTILINE_COMMENT, IPHPPartitions.SMARTY, IPHPPartitions.SMARTY_MULTILINE_COMMENT, };
636 * @see org.eclipse.jface.text.source.SourceViewerConfiguration#getConfiguredDocumentPartitioning(org.eclipse.jface.text.source.ISourceViewer)
639 public String getConfiguredDocumentPartitioning(ISourceViewer sourceViewer) {
640 if (fDocumentPartitioning != null)
641 return fDocumentPartitioning;
642 return super.getConfiguredDocumentPartitioning(sourceViewer);
646 * (non-Javadoc) Method declared on SourceViewerConfiguration
648 public IContentAssistant getContentAssistant(ISourceViewer sourceViewer) {
649 ContentAssistant assistant = new ContentAssistant();
650 IContentAssistProcessor processor = new HTMLCompletionProcessor(getEditor());
651 assistant.setDocumentPartitioning(getConfiguredDocumentPartitioning(sourceViewer));
652 assistant.setContentAssistProcessor(processor, IPHPPartitions.HTML);
653 assistant.setContentAssistProcessor(processor, IPHPPartitions.HTML_MULTILINE_COMMENT);
655 assistant.setContentAssistProcessor(processor, IPHPPartitions.CSS);
656 assistant.setContentAssistProcessor(processor, IPHPPartitions.CSS_MULTILINE_COMMENT);
657 assistant.setContentAssistProcessor(processor, IPHPPartitions.JAVASCRIPT);
658 assistant.setContentAssistProcessor(processor, IPHPPartitions.JS_MULTILINE_COMMENT);
659 // TODO define special smarty partition content assist
660 assistant.setContentAssistProcessor(processor, IPHPPartitions.SMARTY);
661 assistant.setContentAssistProcessor(processor, IPHPPartitions.SMARTY_MULTILINE_COMMENT);
663 assistant.setContentAssistProcessor(processor, PHPDocumentPartitioner.PHP_TEMPLATE_DATA);
664 String[] htmlTypes = getConfiguredHTMLContentTypes();
665 for (int i = 0; i < htmlTypes.length; i++) {
666 assistant.setContentAssistProcessor(processor, htmlTypes[i]);
668 processor = new PHPCompletionProcessor(getEditor());
670 assistant.setContentAssistProcessor(processor, PHPDocumentPartitioner.PHP_SCRIPT_CODE);
671 assistant.setContentAssistProcessor(processor, IPHPPartitions.PHP_PARTITIONING);
672 assistant.setContentAssistProcessor(processor, IPHPPartitions.PHP_STRING_DQ);
673 assistant.setContentAssistProcessor(processor, IPHPPartitions.PHP_STRING_SQ);
675 assistant.setContentAssistProcessor(new PHPDocCompletionProcessor(getEditor()), IPHPPartitions.PHP_PHPDOC_COMMENT);
676 // assistant.enableAutoActivation(true);
677 // assistant.setAutoActivationDelay(500);
678 // assistant.setProposalPopupOrientation(ContentAssistant.PROPOSAL_OVERLAY);
679 // ContentAssistPreference.configure(assistant, getPreferenceStore());
680 // assistant.setContextInformationPopupOrientation(
681 // ContentAssistant.CONTEXT_INFO_ABOVE);
682 // assistant.setContextInformationPopupBackground(
683 // PHPEditorEnvironment.getPHPColorProvider().getColor(
684 // new RGB(150, 150, 0)));
685 ContentAssistPreference.configure(assistant, getPreferenceStore());
686 assistant.setContextInformationPopupOrientation(ContentAssistant.CONTEXT_INFO_ABOVE);
687 assistant.setInformationControlCreator(getInformationControlCreator(sourceViewer));
692 * (non-Javadoc) Method declared on SourceViewerConfiguration
694 // public String getDefaultPrefix(ISourceViewer sourceViewer, String
696 // return (PHPPartitionScanner.PHP.equals(contentType) ? "//" : null);
698 // // return (IDocument.DEFAULT_CONTENT_TYPE.equals(contentType) ? "//" :
699 // null); //$NON-NLS-1$
702 * @see SourceViewerConfiguration#getDefaultPrefix(ISourceViewer, String)
705 public String[] getDefaultPrefixes(ISourceViewer sourceViewer, String contentType) {
706 return new String[] { "//", "" }; //$NON-NLS-1$ //$NON-NLS-2$
710 * (non-Javadoc) Method declared on SourceViewerConfiguration
712 public ITextDoubleClickStrategy getDoubleClickStrategy(ISourceViewer sourceViewer, String contentType) {
713 return new PHPDoubleClickSelector();
717 * @see SourceViewerConfiguration#getIndentPrefixes(ISourceViewer, String)
719 public String[] getIndentPrefixes(ISourceViewer sourceViewer, String contentType) {
720 Vector vector = new Vector();
721 // prefix[0] is either '\t' or ' ' x tabWidth, depending on useSpaces
722 final IPreferenceStore preferences = PHPeclipsePlugin.getDefault().getPreferenceStore();
723 int tabWidth = preferences.getInt(JavaCore.FORMATTER_TAB_SIZE);
724 boolean useSpaces = getPreferenceStore().getBoolean(SPACES_FOR_TABS);
725 for (int i = 0; i <= tabWidth; i++) {
726 StringBuffer prefix = new StringBuffer();
728 for (int j = 0; j + i < tabWidth; j++)
733 for (int j = 0; j < i; j++)
738 vector.add(prefix.toString());
740 vector.add(""); //$NON-NLS-1$
741 return (String[]) vector.toArray(new String[vector.size()]);
745 * @return <code>true</code> iff the new setup without text tools is in use.
749 private boolean isNewSetup() {
750 return fJavaTextTools == null;
754 * Creates and returns a preference store which combines the preference stores from the text tools and which is read-only.
756 * @return the read-only preference store
759 private IPreferenceStore createPreferenceStore() {
760 Assert.isTrue(!isNewSetup());
761 IPreferenceStore generalTextStore = EditorsUI.getPreferenceStore();
762 if (fJavaTextTools.getCorePreferenceStore() == null)
763 return new ChainedPreferenceStore(new IPreferenceStore[] { fJavaTextTools.getPreferenceStore(), generalTextStore });
765 return new ChainedPreferenceStore(new IPreferenceStore[] { fJavaTextTools.getPreferenceStore(),
766 new PreferencesAdapter(fJavaTextTools.getCorePreferenceStore()), generalTextStore });
770 * (non-Javadoc) Method declared on SourceViewerConfiguration
772 public IPresentationReconciler getPresentationReconciler(ISourceViewer sourceViewer) {
773 // PHPColorProvider provider =
774 // PHPEditorEnvironment.getPHPColorProvider();
775 // JavaColorManager provider =
776 // PHPEditorEnvironment.getPHPColorProvider();
777 PresentationReconciler phpReconciler = new JavaPresentationReconciler();
778 phpReconciler.setDocumentPartitioning(getConfiguredDocumentPartitioning(sourceViewer));
780 // DefaultDamagerRepairer dr = new DefaultDamagerRepairer(getHTMLScanner());
781 // reconciler.setDamager(dr, IDocument.DEFAULT_CONTENT_TYPE);
782 // reconciler.setRepairer(dr, IDocument.DEFAULT_CONTENT_TYPE);
783 // dr = new DefaultDamagerRepairer(getHTMLScanner());
784 // reconciler.setDamager(dr, IPHPPartitions.HTML);
785 // reconciler.setRepairer(dr, IPHPPartitions.HTML);
786 // dr = new DefaultDamagerRepairer(getHTMLScanner());
787 // reconciler.setDamager(dr, IPHPPartitions.CSS);
788 // reconciler.setRepairer(dr, IPHPPartitions.CSS);
789 // dr = new DefaultDamagerRepairer(getHTMLScanner());
790 // reconciler.setDamager(dr, IPHPPartitions.CSS_MULTILINE_COMMENT);
791 // reconciler.setRepairer(dr, IPHPPartitions.CSS_MULTILINE_COMMENT);
792 // dr = new DefaultDamagerRepairer(getHTMLScanner());
793 // reconciler.setDamager(dr, IPHPPartitions.JAVASCRIPT);
794 // reconciler.setRepairer(dr, IPHPPartitions.JAVASCRIPT);
795 // dr = new DefaultDamagerRepairer(getHTMLScanner());
796 // reconciler.setDamager(dr, IPHPPartitions.JS_MULTILINE_COMMENT);
797 // reconciler.setRepairer(dr, IPHPPartitions.JS_MULTILINE_COMMENT);
798 // DefaultDamagerRepairer phpDR = new DefaultDamagerRepairer(getSmartyScanner());
799 // phpReconciler.setDamager(phpDR, IPHPPartitions.SMARTY);
800 // phpReconciler.setRepairer(phpDR, IPHPPartitions.SMARTY);
801 // phpDR = new DefaultDamagerRepairer(getSmartyDocScanner());
802 // phpReconciler.setDamager(phpDR, IPHPPartitions.SMARTY_MULTILINE_COMMENT);
803 // phpReconciler.setRepairer(phpDR, IPHPPartitions.SMARTY_MULTILINE_COMMENT);
804 // dr = new DefaultDamagerRepairer(new SingleTokenScanner(new TextAttribute(fJavaTextTools.getColorManager().getColor(
805 // PHPColorProvider.MULTI_LINE_COMMENT))));
806 // reconciler.setDamager(dr, IPHPPartitions.HTML_MULTILINE_COMMENT);
807 // reconciler.setRepairer(dr, IPHPPartitions.HTML_MULTILINE_COMMENT);
809 DefaultDamagerRepairer phpDR = new DefaultDamagerRepairer(getCodeScanner());
810 phpReconciler.setDamager(phpDR, IDocument.DEFAULT_CONTENT_TYPE);
811 phpReconciler.setRepairer(phpDR, IDocument.DEFAULT_CONTENT_TYPE);
813 phpDR = new DefaultDamagerRepairer(getCodeScanner());
814 phpReconciler.setDamager(phpDR, IPHPPartitions.PHP_PARTITIONING);
815 phpReconciler.setRepairer(phpDR, IPHPPartitions.PHP_PARTITIONING);
817 phpDR = new DefaultDamagerRepairer(getPHPDocScanner());
818 phpReconciler.setDamager(phpDR, IPHPPartitions.PHP_PHPDOC_COMMENT);
819 phpReconciler.setRepairer(phpDR, IPHPPartitions.PHP_PHPDOC_COMMENT);
821 phpDR = new DefaultDamagerRepairer(getStringDQScanner());
822 phpReconciler.setDamager(phpDR, IPHPPartitions.PHP_STRING_DQ);
823 phpReconciler.setRepairer(phpDR, IPHPPartitions.PHP_STRING_DQ);
824 phpDR = new DefaultDamagerRepairer(getStringSQScanner());
825 phpReconciler.setDamager(phpDR, IPHPPartitions.PHP_STRING_SQ);
826 phpReconciler.setRepairer(phpDR, IPHPPartitions.PHP_STRING_SQ);
827 phpDR = new DefaultDamagerRepairer(getSinglelineCommentScanner());
828 phpReconciler.setDamager(phpDR, IPHPPartitions.PHP_SINGLELINE_COMMENT);
829 phpReconciler.setRepairer(phpDR, IPHPPartitions.PHP_SINGLELINE_COMMENT);
830 phpDR = new DefaultDamagerRepairer(getMultilineCommentScanner());
831 phpReconciler.setDamager(phpDR, IPHPPartitions.PHP_MULTILINE_COMMENT);
832 phpReconciler.setRepairer(phpDR, IPHPPartitions.PHP_MULTILINE_COMMENT);
834 PresentationReconciler reconciler = new PresentationReconciler();
835 reconciler.setDocumentPartitioning(getConfiguredDocumentPartitioning(sourceViewer));
837 JavaTextTools jspTextTools = PHPeclipsePlugin.getDefault().getJavaTextTools();
838 DefaultDamagerRepairer dr = new DefaultDamagerRepairer(getPHPDocScanner());//jspTextTools.getJSPTextScanner());
839 reconciler.setDamager(dr, IDocument.DEFAULT_CONTENT_TYPE);
840 reconciler.setRepairer(dr, IDocument.DEFAULT_CONTENT_TYPE);
842 // dr = new DefaultDamagerRepairer(new SingleTokenScanner(new TextAttribute(fJavaTextTools.getColorManager().getColor(
843 // PHPColorProvider.PHPDOC_TAG))));//jspTextTools.getJSPBracketScanner());
844 // reconciler.setDamager(dr, JSPScriptScanner.JSP_BRACKET);
845 // reconciler.setRepairer(dr, JSPScriptScanner.JSP_BRACKET);
848 configureEmbeddedPresentationReconciler(reconciler, xmlConfiguration.getPresentationReconciler(sourceViewer), xmlConfiguration
849 .getConfiguredContentTypes(sourceViewer), PHPDocumentPartitioner.PHP_TEMPLATE_DATA);
852 configureEmbeddedPresentationReconciler(reconciler, phpReconciler, getConfiguredPHPContentTypes(),
853 PHPDocumentPartitioner.PHP_SCRIPT_CODE);
858 private void configureEmbeddedPresentationReconciler(PresentationReconciler reconciler, IPresentationReconciler embedded,
859 String[] types, String defaultType) {
860 for (int i = 0; i < types.length; i++) {
861 String type = types[i];
863 IPresentationDamager damager = embedded.getDamager(type);
864 IPresentationRepairer repairer = embedded.getRepairer(type);
866 if (type == IDocument.DEFAULT_CONTENT_TYPE) {
870 reconciler.setDamager(damager, type);
871 reconciler.setRepairer(repairer, type);
876 * (non-Javadoc) Method declared on SourceViewerConfiguration
878 public int getTabWidth(ISourceViewer sourceViewer) {
879 return getPreferenceStore().getInt(PREFERENCE_TAB_WIDTH);
883 * (non-Javadoc) Method declared on SourceViewerConfiguration
885 // public ITextHover getTextHover(ISourceViewer sourceViewer, String
887 // if (fEditor != null) {
888 // IEditorInput editorInput = fEditor.getEditorInput();
889 // if (editorInput instanceof IFileEditorInput) {
891 // IFile f = ((IFileEditorInput) editorInput).getFile();
892 // return new PHPTextHover(f.getProject());
893 // } catch (NullPointerException e) {
894 // // this exception occurs, if getTextHover is called by preference pages
899 // return new PHPTextHover(null);
902 * @see SourceViewerConfiguration#getInformationControlCreator(ISourceViewer)
905 public IInformationControlCreator getInformationControlCreator(ISourceViewer sourceViewer) {
906 return new IInformationControlCreator() {
907 public IInformationControl createInformationControl(Shell parent) {
908 return new DefaultInformationControl(parent, SWT.NONE, new HTMLTextPresenter(true));
909 // return new HoverBrowserControl(parent);
915 * @see SourceViewerConfiguration#getInformationPresenter(ISourceViewer)
918 public IInformationPresenter getInformationPresenter(ISourceViewer sourceViewer) {
919 InformationPresenter presenter = new InformationPresenter(getInformationPresenterControlCreator(sourceViewer));
920 presenter.setDocumentPartitioning(getConfiguredDocumentPartitioning(sourceViewer));
921 IInformationProvider provider = new JavaInformationProvider(getEditor());
922 presenter.setInformationProvider(provider, IDocument.DEFAULT_CONTENT_TYPE);
923 presenter.setInformationProvider(provider, IPHPPartitions.PHP_PHPDOC_COMMENT);
924 // presenter.setInformationProvider(provider, IPHPPartitions.JAVA_CHARACTER);
925 presenter.setSizeConstraints(60, 10, true, true);
930 * @see SourceViewerConfiguration#getInformationPresenter(ISourceViewer)
933 // public IInformationPresenter getInformationPresenter(ISourceViewer
935 // InformationPresenter presenter= new
936 // InformationPresenter(getInformationPresenterControlCreator(sourceViewer));
937 // IInformationProvider provider= new JavaInformationProvider(getEditor());
938 // presenter.setInformationProvider(provider,
939 // IDocument.DEFAULT_CONTENT_TYPE);
940 // presenter.setInformationProvider(provider, IJavaPartitions.JAVA_DOC);
941 // presenter.setSizeConstraints(60, 10, true, true);
945 * Returns the information presenter control creator. The creator is a factory creating the presenter controls for the given
946 * source viewer. This implementation always returns a creator for <code>DefaultInformationControl</code> instances.
948 * @param sourceViewer
949 * the source viewer to be configured by this configuration
950 * @return an information control creator
953 private IInformationControlCreator getInformationPresenterControlCreator(ISourceViewer sourceViewer) {
954 return new IInformationControlCreator() {
955 public IInformationControl createInformationControl(Shell parent) {
956 int shellStyle = SWT.RESIZE;
957 int style = SWT.V_SCROLL | SWT.H_SCROLL;
958 return new DefaultInformationControl(parent, shellStyle, style, new HTMLTextPresenter(false));
959 // return new HoverBrowserControl(parent);
965 * Returns the outline presenter control creator. The creator is a factory creating outline presenter controls for the given
966 * source viewer. This implementation always returns a creator for <code>JavaOutlineInformationControl</code> instances.
968 * @param sourceViewer
969 * the source viewer to be configured by this configuration
970 * @return an information control creator
973 private IInformationControlCreator getOutlinePresenterControlCreator(ISourceViewer sourceViewer) {
974 return new IInformationControlCreator() {
975 public IInformationControl createInformationControl(Shell parent) {
976 int shellStyle = SWT.RESIZE;
977 int treeStyle = SWT.V_SCROLL | SWT.H_SCROLL;
978 return new JavaOutlineInformationControl(parent, shellStyle, treeStyle);
984 * Returns the outline presenter which will determine and shown information requested for the current cursor position.
986 * @param sourceViewer
987 * the source viewer to be configured by this configuration
988 * @param doCodeResolve
989 * a boolean which specifies whether code resolve should be used to compute the Java element
990 * @return an information presenter
993 public IInformationPresenter getOutlinePresenter(ISourceViewer sourceViewer, boolean doCodeResolve) {
994 InformationPresenter presenter = new InformationPresenter(getOutlinePresenterControlCreator(sourceViewer));
995 presenter.setAnchor(InformationPresenter.ANCHOR_GLOBAL);
996 IInformationProvider provider = new JavaElementProvider(getEditor(), doCodeResolve);
997 presenter.setInformationProvider(provider, IDocument.DEFAULT_CONTENT_TYPE);
998 presenter.setInformationProvider(provider, PHPDocumentPartitioner.PHP_SCRIPT_CODE);
999 presenter.setInformationProvider(provider, IPHPPartitions.PHP_PARTITIONING);
1000 presenter.setInformationProvider(provider, IPHPPartitions.PHP_PHPDOC_COMMENT);
1001 presenter.setInformationProvider(provider, IPHPPartitions.SMARTY_MULTILINE_COMMENT);
1002 presenter.setInformationProvider(provider, IPHPPartitions.HTML);
1003 presenter.setInformationProvider(provider, IPHPPartitions.HTML_MULTILINE_COMMENT);
1004 presenter.setSizeConstraints(40, 20, true, false);