aec204a46365d1785bd4a9c2f2f65871073d66b5
[phpeclipse.git] / net.sourceforge.phpeclipse.smarty.ui / src / net / sourceforge / phpdt / smarty / ui / internal / text / HTMLConfiguration.java
1 /*
2  * Created on 25.08.2004
3  *
4  * TODO To change the template for this generated file go to
5  * Window - Preferences - Java - Code Style - Code Templates
6  */
7 package net.sourceforge.phpdt.smarty.ui.internal.text;
8
9 import java.util.Map;
10
11 import net.sourceforge.phpeclipse.xml.ui.internal.text.XMLConfiguration;
12 import net.sourceforge.phpeclipse.xml.ui.internal.text.XMLPartitionScanner;
13 import net.sourceforge.phpeclipse.xml.ui.text.XMLTextTools;
14
15 import org.eclipse.jface.text.IDocument;
16 import org.eclipse.jface.text.contentassist.ContentAssistant;
17 import org.eclipse.jface.text.contentassist.IContentAssistProcessor;
18 import org.eclipse.jface.text.contentassist.IContentAssistant;
19 import org.eclipse.jface.text.presentation.IPresentationReconciler;
20 import org.eclipse.jface.text.presentation.PresentationReconciler;
21 import org.eclipse.jface.text.rules.DefaultDamagerRepairer;
22 import org.eclipse.jface.text.source.ISourceViewer;
23 import org.eclipse.ui.texteditor.ITextEditor;
24
25 /**
26  * @author khartlage
27  * 
28  * TODO To change the template for this generated type comment go to Window - Preferences - Java - Code Style - Code Templates
29  */
30 public class HTMLConfiguration extends XMLConfiguration {
31   private SmartyTagScanner smartyTagScanner;
32   public HTMLConfiguration(XMLTextTools tools) {
33     this(tools, null);
34   }
35
36   public HTMLConfiguration(XMLTextTools tools, ITextEditor editor) {
37     super(tools, editor);
38     Map tokens = tools.getTokens();
39     smartyTagScanner = new SmartyTagScanner(tokens);
40   }
41
42   public IContentAssistant getContentAssistant(ISourceViewer sourceViewer) {
43     ContentAssistant assistant = new ContentAssistant();
44     assistant.setDocumentPartitioning(getConfiguredDocumentPartitioning(sourceViewer));
45
46     IContentAssistProcessor processor = new HTMLCompletionProcessor();
47     assistant.setContentAssistProcessor(processor, IDocument.DEFAULT_CONTENT_TYPE);
48     assistant.setContentAssistProcessor(processor, XMLPartitionScanner.XML_TAG);
49     assistant.setContentAssistProcessor(processor, XMLPartitionScanner.XML_PI);
50     assistant.setContentAssistProcessor(processor, XMLPartitionScanner.XML_COMMENT);
51     assistant.setContentAssistProcessor(processor, XMLPartitionScanner.XML_DECL);
52     assistant.setContentAssistProcessor(processor, XMLPartitionScanner.XML_TAG);
53     assistant.setContentAssistProcessor(processor, XMLPartitionScanner.XML_ATTRIBUTE);
54     assistant.setContentAssistProcessor(processor, XMLPartitionScanner.XML_CDATA);
55
56     assistant.setContextInformationPopupOrientation(IContentAssistant.CONTEXT_INFO_ABOVE);
57     assistant.setInformationControlCreator(getInformationControlCreator(sourceViewer));
58
59     return assistant;
60   }
61         /**
62          * Returns a scanner which is configured to scan XML text.
63          * 
64          * @return  an XML text scanner
65          */
66         public SmartyTagScanner getSmartyScanner() {
67                 return smartyTagScanner;
68         }
69   /*
70    * @see org.eclipse.jface.text.source.SourceViewerConfiguration#getPresentationReconciler(ISourceViewer)
71    */
72   public IPresentationReconciler getPresentationReconciler(ISourceViewer sourceViewer) {
73     PresentationReconciler reconciler = new PresentationReconciler();
74
75     DefaultDamagerRepairer dr;
76
77     dr = new DefaultDamagerRepairer(getSmartyScanner());
78     reconciler.setDamager(dr, IDocument.DEFAULT_CONTENT_TYPE);
79     reconciler.setRepairer(dr, IDocument.DEFAULT_CONTENT_TYPE);
80
81     dr = new DefaultDamagerRepairer(xmlTextTools.getDTDTextScanner());
82     reconciler.setDamager(dr, XMLPartitionScanner.DTD_INTERNAL);
83     reconciler.setRepairer(dr, XMLPartitionScanner.DTD_INTERNAL);
84
85     dr = new DefaultDamagerRepairer(xmlTextTools.getXMLPIScanner());
86
87     reconciler.setDamager(dr, XMLPartitionScanner.XML_PI);
88     reconciler.setRepairer(dr, XMLPartitionScanner.XML_PI);
89     reconciler.setDamager(dr, XMLPartitionScanner.DTD_INTERNAL_PI);
90     reconciler.setRepairer(dr, XMLPartitionScanner.DTD_INTERNAL_PI);
91
92     dr = new DefaultDamagerRepairer(xmlTextTools.getXMLCommentScanner());
93
94     reconciler.setDamager(dr, XMLPartitionScanner.XML_COMMENT);
95     reconciler.setRepairer(dr, XMLPartitionScanner.XML_COMMENT);
96     reconciler.setDamager(dr, XMLPartitionScanner.DTD_INTERNAL_COMMENT);
97     reconciler.setRepairer(dr, XMLPartitionScanner.DTD_INTERNAL_COMMENT);
98
99     dr = new DefaultDamagerRepairer(xmlTextTools.getXMLDeclScanner());
100
101     reconciler.setDamager(dr, XMLPartitionScanner.XML_DECL);
102     reconciler.setRepairer(dr, XMLPartitionScanner.XML_DECL);
103     reconciler.setDamager(dr, XMLPartitionScanner.DTD_INTERNAL_DECL);
104     reconciler.setRepairer(dr, XMLPartitionScanner.DTD_INTERNAL_DECL);
105
106     dr = new DefaultDamagerRepairer(xmlTextTools.getXMLTagScanner());
107
108     reconciler.setDamager(dr, XMLPartitionScanner.XML_TAG);
109     reconciler.setRepairer(dr, XMLPartitionScanner.XML_TAG);
110
111     dr = new DefaultDamagerRepairer(xmlTextTools.getXMLAttributeScanner());
112
113     reconciler.setDamager(dr, XMLPartitionScanner.XML_ATTRIBUTE);
114     reconciler.setRepairer(dr, XMLPartitionScanner.XML_ATTRIBUTE);
115
116     dr = new DefaultDamagerRepairer(xmlTextTools.getXMLCDATAScanner());
117
118     reconciler.setDamager(dr, XMLPartitionScanner.XML_CDATA);
119     reconciler.setRepairer(dr, XMLPartitionScanner.XML_CDATA);
120
121     return reconciler;
122   }
123 }