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 fStringSQScanner = new SingleTokenPHPScanner(getColorManager(), fPreferenceStore, IPreferenceConstants.PHP_STRING_SQ);
285 fJavaDocScanner = new PHPDocCodeScanner(getColorManager(), fPreferenceStore);
289 * Determines whether the preference change encoded by the given event changes the behavior of one of its contained components.
292 * the event to be investigated
293 * @return <code>true</code> if event causes a behavioral change
296 public boolean affectsTextPresentation(PropertyChangeEvent event) {
297 return fCodeScanner.affectsBehavior(event) || fMultilineCommentScanner.affectsBehavior(event)
298 || fSinglelineCommentScanner.affectsBehavior(event) || fStringDQScanner.affectsBehavior(event)|| fStringSQScanner.affectsBehavior(event)
299 || fJavaDocScanner.affectsBehavior(event);
303 * Adapts the behavior of the contained components to the change encoded in the given event.
305 * Clients are not allowed to call this method if the old setup with text tools is in use.
309 * the event to which to adapt
310 * @see JavaSourceViewerConfiguration#JavaSourceViewerConfiguration(IColorManager, IPreferenceStore, ITextEditor, String)
313 public void handlePropertyChangeEvent(PropertyChangeEvent event) {
314 Assert.isTrue(isNewSetup());
315 if (fCodeScanner.affectsBehavior(event))
316 fCodeScanner.adaptToPreferenceChange(event);
317 if (fMultilineCommentScanner.affectsBehavior(event))
318 fMultilineCommentScanner.adaptToPreferenceChange(event);
319 if (fSinglelineCommentScanner.affectsBehavior(event))
320 fSinglelineCommentScanner.adaptToPreferenceChange(event);
321 if (fStringDQScanner.affectsBehavior(event))
322 fStringDQScanner.adaptToPreferenceChange(event);
323 if (fStringSQScanner.affectsBehavior(event))
324 fStringSQScanner.adaptToPreferenceChange(event);
325 if (fJavaDocScanner.affectsBehavior(event))
326 fJavaDocScanner.adaptToPreferenceChange(event);
330 * @see SourceViewerConfiguration#getContentFormatter(ISourceViewer)
332 public IContentFormatter getContentFormatter(ISourceViewer sourceViewer) {
333 // if (fFormatter == null) {
334 // fFormatter = new ContentFormatter();
335 // fFormattingStrategy = new HTMLFormattingStrategy(this,
337 // fFormatter.setFormattingStrategy(fFormattingStrategy, HTML_DEFAULT);
338 // fFormatter.enablePartitionAwareFormatting(false);
339 // fFormatter.setPartitionManagingPositionCategories(getConfiguredContentTypes(null));
341 // return fFormatter;
342 if (fFormatter == null) {
344 fFormatter = new ContentFormatter();
345 IFormattingStrategy strategy = new JavaFormattingStrategy(sourceViewer);
346 fFormatter.setFormattingStrategy(strategy, IDocument.DEFAULT_CONTENT_TYPE);
347 fFormatter.enablePartitionAwareFormatting(false);
348 fFormatter.setPartitionManagingPositionCategories(getPartitionManagingPositionCategories());
354 * Returns the names of the document position categories used by the document partitioners created by this object to manage their
355 * partition information. If the partitioners don't use document position categories, the returned result is <code>null</code>.
357 * @return the partition managing position categories or <code>null</code> if there is none
359 public String[] getPartitionManagingPositionCategories() {
360 return new String[] { DefaultPartitioner.CONTENT_TYPES_CATEGORY };
364 // * Returns the names of the document position categories used by the
366 // * partitioners created by this object to manage their partition
368 // * If the partitioners don't use document position categories, the
370 // * result is <code>null</code>.
372 // * @return the partition managing position categories or
374 // * if there is none
376 // private String[] getPartitionManagingPositionCategories() {
377 // return new String[] { DefaultPartitioner.CONTENT_TYPES_CATEGORY };
379 public ITextEditor getEditor() {
384 * Returns the preference store used by this configuration to initialize the individual bits and pieces.
386 * @return the preference store used to initialize this configuration
390 protected IPreferenceStore getPreferenceStore() {
391 return PHPeclipsePlugin.getDefault().getPreferenceStore();
395 // * Method declared on SourceViewerConfiguration
397 // public IAnnotationHover getAnnotationHover(ISourceViewer sourceViewer) {
398 // return new PHPAnnotationHover();
401 * @see SourceViewerConfiguration#getAnnotationHover(ISourceViewer)
403 public IAnnotationHover getAnnotationHover(ISourceViewer sourceViewer) {
404 return new JavaAnnotationHover(JavaAnnotationHover.VERTICAL_RULER_HOVER);
408 * @see SourceViewerConfiguration#getOverviewRulerAnnotationHover(ISourceViewer)
411 public IAnnotationHover getOverviewRulerAnnotationHover(ISourceViewer sourceViewer) {
412 return new JavaAnnotationHover(JavaAnnotationHover.OVERVIEW_RULER_HOVER);
416 * (non-Javadoc) Method declared on SourceViewerConfiguration
418 public IAutoIndentStrategy getAutoIndentStrategy(ISourceViewer sourceViewer, String contentType) {
419 if (IPHPPartitions.PHP_PHPDOC_COMMENT.equals(contentType)
420 || IPHPPartitions.PHP_MULTILINE_COMMENT.equals(contentType))
421 return new JavaDocAutoIndentStrategy(getConfiguredDocumentPartitioning(sourceViewer));
422 if (IPHPPartitions.PHP_STRING_DQ.equals(contentType))
423 return new JavaStringAutoIndentStrategyDQ(getConfiguredDocumentPartitioning(sourceViewer));
424 if (IPHPPartitions.PHP_STRING_SQ.equals(contentType))
425 return new JavaStringAutoIndentStrategySQ(getConfiguredDocumentPartitioning(sourceViewer));
427 return (PHPDocumentPartitioner.PHP_TEMPLATE_DATA.equals(contentType)
428 || PHPDocumentPartitioner.PHP_SCRIPT_CODE.equals(contentType) || IDocument.DEFAULT_CONTENT_TYPE.equals(contentType)
429 || IPHPPartitions.PHP_PARTITIONING.equals(contentType) || PHPPartitionScanner.PHP_SCRIPTING_AREA.equals(contentType) ? new PHPAutoIndentStrategy()
430 : new DefaultAutoIndentStrategy());
434 * Returns the PHP source code scanner for this configuration.
436 * @return the PHP source code scanner
438 protected RuleBasedScanner getCodeScanner() {
439 return fCodeScanner; //fJavaTextTools.getCodeScanner();
443 * Returns the Java multi-line comment scanner for this configuration.
445 * @return the Java multi-line comment scanner
448 protected RuleBasedScanner getMultilineCommentScanner() {
449 return fMultilineCommentScanner;
453 * Returns the Java single-line comment scanner for this configuration.
455 * @return the Java single-line comment scanner
458 protected RuleBasedScanner getSinglelineCommentScanner() {
459 return fSinglelineCommentScanner;
463 * Returns the PHP double quoted string scanner for this configuration.
465 * @return the PHP double quoted string scanner
467 protected RuleBasedScanner getStringDQScanner() {
468 return fStringDQScanner;
472 * Returns the PHP single quoted string scanner for this configuration.
474 * @return the PHP single quoted string scanner
476 protected RuleBasedScanner getStringSQScanner() {
477 return fStringSQScanner;
480 * Returns the HTML source code scanner for this configuration.
482 * @return the HTML source code scanner
484 // protected RuleBasedScanner getHTMLScanner() {
485 // return fJavaTextTools.getHTMLScanner();
488 * Returns the Smarty source code scanner for this configuration.
490 * @return the Smarty source code scanner
492 // protected RuleBasedScanner getSmartyScanner() {
493 // return fJavaTextTools.getSmartyScanner();
496 * @see SourceViewerConfiguration#getReconciler(ISourceViewer)
499 * @see SourceViewerConfiguration#getReconciler(ISourceViewer)
501 public IReconciler getReconciler(ISourceViewer sourceViewer) {
503 final ITextEditor editor = getEditor();
504 if (editor != null && editor.isEditable()) {
506 JavaCompositeReconcilingStrategy strategy = new JavaCompositeReconcilingStrategy(editor,
507 getConfiguredDocumentPartitioning(sourceViewer));
508 JavaReconciler reconciler = new JavaReconciler(editor, strategy, false);
509 reconciler.setIsIncrementalReconciler(false);
510 reconciler.setProgressMonitor(new NullProgressMonitor());
511 reconciler.setDelay(500);
519 * @see SourceViewerConfiguration#getConfiguredTextHoverStateMasks(ISourceViewer, String)
522 public int[] getConfiguredTextHoverStateMasks(ISourceViewer sourceViewer, String contentType) {
523 JavaEditorTextHoverDescriptor[] hoverDescs = PHPeclipsePlugin.getDefault().getJavaEditorTextHoverDescriptors();
524 int stateMasks[] = new int[hoverDescs.length];
525 int stateMasksLength = 0;
526 for (int i = 0; i < hoverDescs.length; i++) {
527 if (hoverDescs[i].isEnabled()) {
529 int stateMask = hoverDescs[i].getStateMask();
530 while (j < stateMasksLength) {
531 if (stateMasks[j] == stateMask)
535 if (j == stateMasksLength)
536 stateMasks[stateMasksLength++] = stateMask;
539 if (stateMasksLength == hoverDescs.length)
541 int[] shortenedStateMasks = new int[stateMasksLength];
542 System.arraycopy(stateMasks, 0, shortenedStateMasks, 0, stateMasksLength);
543 return shortenedStateMasks;
547 * @see SourceViewerConfiguration#getTextHover(ISourceViewer, String, int)
550 public ITextHover getTextHover(ISourceViewer sourceViewer, String contentType, int stateMask) {
551 JavaEditorTextHoverDescriptor[] hoverDescs = PHPeclipsePlugin.getDefault().getJavaEditorTextHoverDescriptors();
553 while (i < hoverDescs.length) {
554 if (hoverDescs[i].isEnabled() && hoverDescs[i].getStateMask() == stateMask)
555 return new JavaEditorTextHoverProxy(hoverDescs[i], getEditor());
559 // if (fEditor != null) {
560 // IEditorInput editorInput = fEditor.getEditorInput();
561 // if (editorInput instanceof IFileEditorInput) {
563 // IFile f = ((IFileEditorInput) editorInput).getFile();
564 // return new PHPTextHover(f.getProject());
565 // } catch (NullPointerException e) {
566 // // this exception occurs, if getTextHover is called by
567 // // preference pages !
571 // return new PHPTextHover(null);
575 * @see SourceViewerConfiguration#getTextHover(ISourceViewer, String)
577 public ITextHover getTextHover(ISourceViewer sourceViewer, String contentType) {
578 return getTextHover(sourceViewer, contentType, ITextViewerExtension2.DEFAULT_HOVER_STATE_MASK);
582 * Returns the SmartyDoc source code scanner for this configuration.
584 * @return the SmartyDoc source code scanner
586 // protected RuleBasedScanner getSmartyDocScanner() {
587 // return fJavaTextTools.getSmartyDocScanner();
590 * Returns the PHPDoc source code scanner for this configuration.
592 * @return the PHPDoc source code scanner
594 protected RuleBasedScanner getPHPDocScanner() {
595 return fJavaDocScanner; //fJavaTextTools.getJavaDocScanner();
599 * (non-Javadoc) Method declared on SourceViewerConfiguration
601 public String[] getConfiguredContentTypes(ISourceViewer sourceViewer) {
602 return new String[] { IDocument.DEFAULT_CONTENT_TYPE, PHPPartitionScanner.PHP_SCRIPTING_AREA,
604 IPHPPartitions.HTML, IPHPPartitions.HTML_MULTILINE_COMMENT, IPHPPartitions.PHP_PARTITIONING,
605 IPHPPartitions.PHP_SINGLELINE_COMMENT, IPHPPartitions.PHP_MULTILINE_COMMENT, IPHPPartitions.PHP_PHPDOC_COMMENT,
606 IPHPPartitions.PHP_STRING_DQ, IPHPPartitions.PHP_STRING_SQ, IPHPPartitions.CSS, IPHPPartitions.CSS_MULTILINE_COMMENT,
607 IPHPPartitions.JAVASCRIPT, IPHPPartitions.JS_MULTILINE_COMMENT, IPHPPartitions.SMARTY,
608 IPHPPartitions.SMARTY_MULTILINE_COMMENT,
610 XMLPartitionScanner.XML_PI, XMLPartitionScanner.XML_COMMENT, XMLPartitionScanner.XML_DECL, XMLPartitionScanner.XML_TAG,
611 XMLPartitionScanner.XML_ATTRIBUTE, XMLPartitionScanner.XML_CDATA,
613 XMLPartitionScanner.DTD_INTERNAL, XMLPartitionScanner.DTD_INTERNAL_PI, XMLPartitionScanner.DTD_INTERNAL_COMMENT,
614 XMLPartitionScanner.DTD_INTERNAL_DECL,
616 PHPDocumentPartitioner.PHP_TEMPLATE_DATA, PHPDocumentPartitioner.PHP_SCRIPT_CODE };
619 public String[] getConfiguredHTMLContentTypes() {
620 return new String[] { XMLPartitionScanner.XML_PI, XMLPartitionScanner.XML_COMMENT, XMLPartitionScanner.XML_DECL,
621 XMLPartitionScanner.XML_TAG, XMLPartitionScanner.XML_ATTRIBUTE, XMLPartitionScanner.XML_CDATA,
623 XMLPartitionScanner.DTD_INTERNAL, XMLPartitionScanner.DTD_INTERNAL_PI, XMLPartitionScanner.DTD_INTERNAL_COMMENT,
624 XMLPartitionScanner.DTD_INTERNAL_DECL, };
627 public String[] getConfiguredPHPContentTypes() {
628 return new String[] { IDocument.DEFAULT_CONTENT_TYPE, IPHPPartitions.PHP_PARTITIONING, IPHPPartitions.PHP_SINGLELINE_COMMENT,
629 IPHPPartitions.PHP_MULTILINE_COMMENT, IPHPPartitions.PHP_PHPDOC_COMMENT, IPHPPartitions.PHP_STRING_DQ,
630 IPHPPartitions.PHP_STRING_SQ, IPHPPartitions.CSS, IPHPPartitions.CSS_MULTILINE_COMMENT, IPHPPartitions.JAVASCRIPT,
631 IPHPPartitions.JS_MULTILINE_COMMENT, IPHPPartitions.SMARTY, IPHPPartitions.SMARTY_MULTILINE_COMMENT, };
635 * @see org.eclipse.jface.text.source.SourceViewerConfiguration#getConfiguredDocumentPartitioning(org.eclipse.jface.text.source.ISourceViewer)
638 public String getConfiguredDocumentPartitioning(ISourceViewer sourceViewer) {
639 if (fDocumentPartitioning != null)
640 return fDocumentPartitioning;
641 return super.getConfiguredDocumentPartitioning(sourceViewer);
645 * (non-Javadoc) Method declared on SourceViewerConfiguration
647 public IContentAssistant getContentAssistant(ISourceViewer sourceViewer) {
648 ContentAssistant assistant = new ContentAssistant();
649 IContentAssistProcessor processor = new HTMLCompletionProcessor(getEditor());
650 assistant.setDocumentPartitioning(getConfiguredDocumentPartitioning(sourceViewer));
651 assistant.setContentAssistProcessor(processor, IPHPPartitions.HTML);
652 assistant.setContentAssistProcessor(processor, IPHPPartitions.HTML_MULTILINE_COMMENT);
654 assistant.setContentAssistProcessor(processor, IPHPPartitions.CSS);
655 assistant.setContentAssistProcessor(processor, IPHPPartitions.CSS_MULTILINE_COMMENT);
656 assistant.setContentAssistProcessor(processor, IPHPPartitions.JAVASCRIPT);
657 assistant.setContentAssistProcessor(processor, IPHPPartitions.JS_MULTILINE_COMMENT);
658 // TODO define special smarty partition content assist
659 assistant.setContentAssistProcessor(processor, IPHPPartitions.SMARTY);
660 assistant.setContentAssistProcessor(processor, IPHPPartitions.SMARTY_MULTILINE_COMMENT);
662 assistant.setContentAssistProcessor(processor, PHPDocumentPartitioner.PHP_TEMPLATE_DATA);
663 String[] htmlTypes = getConfiguredHTMLContentTypes();
664 for (int i = 0; i < htmlTypes.length; i++) {
665 assistant.setContentAssistProcessor(processor, htmlTypes[i]);
667 processor = new PHPCompletionProcessor(getEditor());
669 assistant.setContentAssistProcessor(processor, PHPDocumentPartitioner.PHP_SCRIPT_CODE);
670 assistant.setContentAssistProcessor(processor, IPHPPartitions.PHP_PARTITIONING);
671 assistant.setContentAssistProcessor(processor, IPHPPartitions.PHP_STRING_DQ);
672 assistant.setContentAssistProcessor(processor, IPHPPartitions.PHP_STRING_SQ);
674 assistant.setContentAssistProcessor(new PHPDocCompletionProcessor(getEditor()), IPHPPartitions.PHP_PHPDOC_COMMENT);
675 // assistant.enableAutoActivation(true);
676 // assistant.setAutoActivationDelay(500);
677 // assistant.setProposalPopupOrientation(ContentAssistant.PROPOSAL_OVERLAY);
678 // ContentAssistPreference.configure(assistant, getPreferenceStore());
679 // assistant.setContextInformationPopupOrientation(
680 // ContentAssistant.CONTEXT_INFO_ABOVE);
681 // assistant.setContextInformationPopupBackground(
682 // PHPEditorEnvironment.getPHPColorProvider().getColor(
683 // new RGB(150, 150, 0)));
684 ContentAssistPreference.configure(assistant, getPreferenceStore());
685 assistant.setContextInformationPopupOrientation(ContentAssistant.CONTEXT_INFO_ABOVE);
686 assistant.setInformationControlCreator(getInformationControlCreator(sourceViewer));
691 * (non-Javadoc) Method declared on SourceViewerConfiguration
693 // public String getDefaultPrefix(ISourceViewer sourceViewer, String
695 // return (PHPPartitionScanner.PHP.equals(contentType) ? "//" : null);
697 // // return (IDocument.DEFAULT_CONTENT_TYPE.equals(contentType) ? "//" :
698 // null); //$NON-NLS-1$
701 * @see SourceViewerConfiguration#getDefaultPrefix(ISourceViewer, String)
704 public String[] getDefaultPrefixes(ISourceViewer sourceViewer, String contentType) {
705 return new String[] { "//", "" }; //$NON-NLS-1$ //$NON-NLS-2$
709 * (non-Javadoc) Method declared on SourceViewerConfiguration
711 public ITextDoubleClickStrategy getDoubleClickStrategy(ISourceViewer sourceViewer, String contentType) {
712 return new PHPDoubleClickSelector();
716 * @see SourceViewerConfiguration#getIndentPrefixes(ISourceViewer, String)
718 public String[] getIndentPrefixes(ISourceViewer sourceViewer, String contentType) {
719 Vector vector = new Vector();
720 // prefix[0] is either '\t' or ' ' x tabWidth, depending on useSpaces
721 final IPreferenceStore preferences = PHPeclipsePlugin.getDefault().getPreferenceStore();
722 int tabWidth = preferences.getInt(JavaCore.FORMATTER_TAB_SIZE);
723 boolean useSpaces = getPreferenceStore().getBoolean(SPACES_FOR_TABS);
724 for (int i = 0; i <= tabWidth; i++) {
725 StringBuffer prefix = new StringBuffer();
727 for (int j = 0; j + i < tabWidth; j++)
732 for (int j = 0; j < i; j++)
737 vector.add(prefix.toString());
739 vector.add(""); //$NON-NLS-1$
740 return (String[]) vector.toArray(new String[vector.size()]);
744 * @return <code>true</code> iff the new setup without text tools is in use.
748 private boolean isNewSetup() {
749 return fJavaTextTools == null;
753 * Creates and returns a preference store which combines the preference stores from the text tools and which is read-only.
755 * @return the read-only preference store
758 private IPreferenceStore createPreferenceStore() {
759 Assert.isTrue(!isNewSetup());
760 IPreferenceStore generalTextStore = EditorsUI.getPreferenceStore();
761 if (fJavaTextTools.getCorePreferenceStore() == null)
762 return new ChainedPreferenceStore(new IPreferenceStore[] { fJavaTextTools.getPreferenceStore(), generalTextStore });
764 return new ChainedPreferenceStore(new IPreferenceStore[] { fJavaTextTools.getPreferenceStore(),
765 new PreferencesAdapter(fJavaTextTools.getCorePreferenceStore()), generalTextStore });
769 * (non-Javadoc) Method declared on SourceViewerConfiguration
771 public IPresentationReconciler getPresentationReconciler(ISourceViewer sourceViewer) {
772 // PHPColorProvider provider =
773 // PHPEditorEnvironment.getPHPColorProvider();
774 // JavaColorManager provider =
775 // PHPEditorEnvironment.getPHPColorProvider();
776 PresentationReconciler phpReconciler = new JavaPresentationReconciler();
777 phpReconciler.setDocumentPartitioning(getConfiguredDocumentPartitioning(sourceViewer));
779 // DefaultDamagerRepairer dr = new DefaultDamagerRepairer(getHTMLScanner());
780 // reconciler.setDamager(dr, IDocument.DEFAULT_CONTENT_TYPE);
781 // reconciler.setRepairer(dr, IDocument.DEFAULT_CONTENT_TYPE);
782 // dr = new DefaultDamagerRepairer(getHTMLScanner());
783 // reconciler.setDamager(dr, IPHPPartitions.HTML);
784 // reconciler.setRepairer(dr, IPHPPartitions.HTML);
785 // dr = new DefaultDamagerRepairer(getHTMLScanner());
786 // reconciler.setDamager(dr, IPHPPartitions.CSS);
787 // reconciler.setRepairer(dr, IPHPPartitions.CSS);
788 // dr = new DefaultDamagerRepairer(getHTMLScanner());
789 // reconciler.setDamager(dr, IPHPPartitions.CSS_MULTILINE_COMMENT);
790 // reconciler.setRepairer(dr, IPHPPartitions.CSS_MULTILINE_COMMENT);
791 // dr = new DefaultDamagerRepairer(getHTMLScanner());
792 // reconciler.setDamager(dr, IPHPPartitions.JAVASCRIPT);
793 // reconciler.setRepairer(dr, IPHPPartitions.JAVASCRIPT);
794 // dr = new DefaultDamagerRepairer(getHTMLScanner());
795 // reconciler.setDamager(dr, IPHPPartitions.JS_MULTILINE_COMMENT);
796 // reconciler.setRepairer(dr, IPHPPartitions.JS_MULTILINE_COMMENT);
797 // DefaultDamagerRepairer phpDR = new DefaultDamagerRepairer(getSmartyScanner());
798 // phpReconciler.setDamager(phpDR, IPHPPartitions.SMARTY);
799 // phpReconciler.setRepairer(phpDR, IPHPPartitions.SMARTY);
800 // phpDR = new DefaultDamagerRepairer(getSmartyDocScanner());
801 // phpReconciler.setDamager(phpDR, IPHPPartitions.SMARTY_MULTILINE_COMMENT);
802 // phpReconciler.setRepairer(phpDR, IPHPPartitions.SMARTY_MULTILINE_COMMENT);
803 // dr = new DefaultDamagerRepairer(new SingleTokenScanner(new TextAttribute(fJavaTextTools.getColorManager().getColor(
804 // PHPColorProvider.MULTI_LINE_COMMENT))));
805 // reconciler.setDamager(dr, IPHPPartitions.HTML_MULTILINE_COMMENT);
806 // reconciler.setRepairer(dr, IPHPPartitions.HTML_MULTILINE_COMMENT);
808 DefaultDamagerRepairer phpDR = new DefaultDamagerRepairer(getCodeScanner());
809 phpReconciler.setDamager(phpDR, IDocument.DEFAULT_CONTENT_TYPE);
810 phpReconciler.setRepairer(phpDR, IDocument.DEFAULT_CONTENT_TYPE);
812 phpDR = new DefaultDamagerRepairer(getCodeScanner());
813 phpReconciler.setDamager(phpDR, IPHPPartitions.PHP_PARTITIONING);
814 phpReconciler.setRepairer(phpDR, IPHPPartitions.PHP_PARTITIONING);
816 phpDR = new DefaultDamagerRepairer(getPHPDocScanner());
817 phpReconciler.setDamager(phpDR, IPHPPartitions.PHP_PHPDOC_COMMENT);
818 phpReconciler.setRepairer(phpDR, IPHPPartitions.PHP_PHPDOC_COMMENT);
820 phpDR = new DefaultDamagerRepairer(getStringDQScanner());
821 phpReconciler.setDamager(phpDR, IPHPPartitions.PHP_STRING_DQ);
822 phpReconciler.setRepairer(phpDR, IPHPPartitions.PHP_STRING_DQ);
823 phpDR = new DefaultDamagerRepairer(getStringSQScanner());
824 phpReconciler.setDamager(phpDR, IPHPPartitions.PHP_STRING_SQ);
825 phpReconciler.setRepairer(phpDR, IPHPPartitions.PHP_STRING_SQ);
826 phpDR = new DefaultDamagerRepairer(getSinglelineCommentScanner());
827 phpReconciler.setDamager(phpDR, IPHPPartitions.PHP_SINGLELINE_COMMENT);
828 phpReconciler.setRepairer(phpDR, IPHPPartitions.PHP_SINGLELINE_COMMENT);
829 phpDR = new DefaultDamagerRepairer(getMultilineCommentScanner());
830 phpReconciler.setDamager(phpDR, IPHPPartitions.PHP_MULTILINE_COMMENT);
831 phpReconciler.setRepairer(phpDR, IPHPPartitions.PHP_MULTILINE_COMMENT);
833 PresentationReconciler reconciler = new PresentationReconciler();
834 reconciler.setDocumentPartitioning(getConfiguredDocumentPartitioning(sourceViewer));
836 JavaTextTools jspTextTools = PHPeclipsePlugin.getDefault().getJavaTextTools();
837 DefaultDamagerRepairer dr = new DefaultDamagerRepairer(getPHPDocScanner());//jspTextTools.getJSPTextScanner());
838 reconciler.setDamager(dr, IDocument.DEFAULT_CONTENT_TYPE);
839 reconciler.setRepairer(dr, IDocument.DEFAULT_CONTENT_TYPE);
841 // dr = new DefaultDamagerRepairer(new SingleTokenScanner(new TextAttribute(fJavaTextTools.getColorManager().getColor(
842 // PHPColorProvider.PHPDOC_TAG))));//jspTextTools.getJSPBracketScanner());
843 // reconciler.setDamager(dr, JSPScriptScanner.JSP_BRACKET);
844 // reconciler.setRepairer(dr, JSPScriptScanner.JSP_BRACKET);
847 configureEmbeddedPresentationReconciler(reconciler, xmlConfiguration.getPresentationReconciler(sourceViewer), xmlConfiguration
848 .getConfiguredContentTypes(sourceViewer), PHPDocumentPartitioner.PHP_TEMPLATE_DATA);
851 configureEmbeddedPresentationReconciler(reconciler, phpReconciler, getConfiguredPHPContentTypes(),
852 PHPDocumentPartitioner.PHP_SCRIPT_CODE);
857 private void configureEmbeddedPresentationReconciler(PresentationReconciler reconciler, IPresentationReconciler embedded,
858 String[] types, String defaultType) {
859 for (int i = 0; i < types.length; i++) {
860 String type = types[i];
862 IPresentationDamager damager = embedded.getDamager(type);
863 IPresentationRepairer repairer = embedded.getRepairer(type);
865 if (type == IDocument.DEFAULT_CONTENT_TYPE) {
869 reconciler.setDamager(damager, type);
870 reconciler.setRepairer(repairer, type);
875 * (non-Javadoc) Method declared on SourceViewerConfiguration
877 public int getTabWidth(ISourceViewer sourceViewer) {
878 return getPreferenceStore().getInt(PREFERENCE_TAB_WIDTH);
882 * (non-Javadoc) Method declared on SourceViewerConfiguration
884 // public ITextHover getTextHover(ISourceViewer sourceViewer, String
886 // if (fEditor != null) {
887 // IEditorInput editorInput = fEditor.getEditorInput();
888 // if (editorInput instanceof IFileEditorInput) {
890 // IFile f = ((IFileEditorInput) editorInput).getFile();
891 // return new PHPTextHover(f.getProject());
892 // } catch (NullPointerException e) {
893 // // this exception occurs, if getTextHover is called by preference pages
898 // return new PHPTextHover(null);
901 * @see SourceViewerConfiguration#getInformationControlCreator(ISourceViewer)
904 public IInformationControlCreator getInformationControlCreator(ISourceViewer sourceViewer) {
905 return new IInformationControlCreator() {
906 public IInformationControl createInformationControl(Shell parent) {
907 return new DefaultInformationControl(parent, SWT.NONE, new HTMLTextPresenter(true));
908 // return new HoverBrowserControl(parent);
914 * @see SourceViewerConfiguration#getInformationPresenter(ISourceViewer)
917 public IInformationPresenter getInformationPresenter(ISourceViewer sourceViewer) {
918 InformationPresenter presenter = new InformationPresenter(getInformationPresenterControlCreator(sourceViewer));
919 presenter.setDocumentPartitioning(getConfiguredDocumentPartitioning(sourceViewer));
920 IInformationProvider provider = new JavaInformationProvider(getEditor());
921 presenter.setInformationProvider(provider, IDocument.DEFAULT_CONTENT_TYPE);
922 presenter.setInformationProvider(provider, IPHPPartitions.PHP_PHPDOC_COMMENT);
923 // presenter.setInformationProvider(provider, IPHPPartitions.JAVA_CHARACTER);
924 presenter.setSizeConstraints(60, 10, true, true);
929 * @see SourceViewerConfiguration#getInformationPresenter(ISourceViewer)
932 // public IInformationPresenter getInformationPresenter(ISourceViewer
934 // InformationPresenter presenter= new
935 // InformationPresenter(getInformationPresenterControlCreator(sourceViewer));
936 // IInformationProvider provider= new JavaInformationProvider(getEditor());
937 // presenter.setInformationProvider(provider,
938 // IDocument.DEFAULT_CONTENT_TYPE);
939 // presenter.setInformationProvider(provider, IJavaPartitions.JAVA_DOC);
940 // presenter.setSizeConstraints(60, 10, true, true);
944 * Returns the information presenter control creator. The creator is a factory creating the presenter controls for the given
945 * source viewer. This implementation always returns a creator for <code>DefaultInformationControl</code> instances.
947 * @param sourceViewer
948 * the source viewer to be configured by this configuration
949 * @return an information control creator
952 private IInformationControlCreator getInformationPresenterControlCreator(ISourceViewer sourceViewer) {
953 return new IInformationControlCreator() {
954 public IInformationControl createInformationControl(Shell parent) {
955 int shellStyle = SWT.RESIZE;
956 int style = SWT.V_SCROLL | SWT.H_SCROLL;
957 return new DefaultInformationControl(parent, shellStyle, style, new HTMLTextPresenter(false));
958 // return new HoverBrowserControl(parent);
964 * Returns the outline presenter control creator. The creator is a factory creating outline presenter controls for the given
965 * source viewer. This implementation always returns a creator for <code>JavaOutlineInformationControl</code> instances.
967 * @param sourceViewer
968 * the source viewer to be configured by this configuration
969 * @return an information control creator
972 private IInformationControlCreator getOutlinePresenterControlCreator(ISourceViewer sourceViewer) {
973 return new IInformationControlCreator() {
974 public IInformationControl createInformationControl(Shell parent) {
975 int shellStyle = SWT.RESIZE;
976 int treeStyle = SWT.V_SCROLL | SWT.H_SCROLL;
977 return new JavaOutlineInformationControl(parent, shellStyle, treeStyle);
983 * Returns the outline presenter which will determine and shown information requested for the current cursor position.
985 * @param sourceViewer
986 * the source viewer to be configured by this configuration
987 * @param doCodeResolve
988 * a boolean which specifies whether code resolve should be used to compute the Java element
989 * @return an information presenter
992 public IInformationPresenter getOutlinePresenter(ISourceViewer sourceViewer, boolean doCodeResolve) {
993 InformationPresenter presenter = new InformationPresenter(getOutlinePresenterControlCreator(sourceViewer));
994 presenter.setAnchor(InformationPresenter.ANCHOR_GLOBAL);
995 IInformationProvider provider = new JavaElementProvider(getEditor(), doCodeResolve);
996 presenter.setInformationProvider(provider, IDocument.DEFAULT_CONTENT_TYPE);
997 presenter.setInformationProvider(provider, PHPDocumentPartitioner.PHP_SCRIPT_CODE);
998 presenter.setInformationProvider(provider, IPHPPartitions.PHP_PARTITIONING);
999 presenter.setInformationProvider(provider, IPHPPartitions.PHP_PHPDOC_COMMENT);
1000 presenter.setInformationProvider(provider, IPHPPartitions.SMARTY_MULTILINE_COMMENT);
1001 presenter.setInformationProvider(provider, IPHPPartitions.HTML);
1002 presenter.setInformationProvider(provider, IPHPPartitions.HTML_MULTILINE_COMMENT);
1003 presenter.setSizeConstraints(40, 20, true, false);