misc changes
[phpeclipse.git] / net.sourceforge.phpeclipse.xml.ui / src / net / sourceforge / phpeclipse / xml / ui / internal / preferences / ContentAssistPreference.java
1 package net.sourceforge.phpeclipse.xml.ui.internal.preferences;
2
3 import net.sourceforge.phpeclipse.ui.PreferenceConstants;
4 import net.sourceforge.phpeclipse.ui.templates.template.BasicCompletionProcessor;
5 import net.sourceforge.phpeclipse.xml.ui.internal.text.XMLPartitionScanner;
6
7 import org.eclipse.jface.preference.IPreferenceStore;
8 import org.eclipse.jface.text.contentassist.ContentAssistant;
9 import org.eclipse.jface.text.contentassist.IContentAssistProcessor;
10
11
12 public class ContentAssistPreference {
13   /** Preference key for html content assist auto activation triggers */
14   private final static String AUTOACTIVATION_TRIGGERS_HTML = PreferenceConstants.CODEASSIST_AUTOACTIVATION_TRIGGERS_HTML;
15
16   /** Preference key for alphabetic ordering of proposals */
17   private final static String ORDER_PROPOSALS = PreferenceConstants.CODEASSIST_ORDER_PROPOSALS;
18   
19   private static BasicCompletionProcessor getHTMLProcessor(ContentAssistant assistant) {
20     IContentAssistProcessor p = assistant.getContentAssistProcessor(XMLPartitionScanner.XML_TAG);
21     if (p instanceof BasicCompletionProcessor)
22       return (BasicCompletionProcessor) p;
23     return null;
24   }
25   
26   private static void configureHTMLProcessor(ContentAssistant assistant, IPreferenceStore store) {
27     BasicCompletionProcessor hcp = getHTMLProcessor(assistant);
28     if (hcp == null)
29       return;
30
31     String triggers = store.getString(AUTOACTIVATION_TRIGGERS_HTML);
32     if (triggers != null)
33       hcp.setCompletionProposalAutoActivationCharacters(triggers.toCharArray());
34
35     boolean enabled;
36     //    boolean enabled = store.getBoolean(CASE_SENSITIVITY);
37     //    jdcp.restrictProposalsToMatchingCases(enabled);
38
39     enabled = store.getBoolean(ORDER_PROPOSALS);
40   //  hcp.orderProposalsAlphabetically(enabled);
41   } 
42   private static void changeHTMLProcessor(ContentAssistant assistant, IPreferenceStore store, String key) {
43     BasicCompletionProcessor jdcp = getHTMLProcessor(assistant);
44     if (jdcp == null)
45       return;
46
47     if (AUTOACTIVATION_TRIGGERS_HTML.equals(key)) {
48       String triggers = store.getString(AUTOACTIVATION_TRIGGERS_HTML);
49       if (triggers != null)
50         jdcp.setCompletionProposalAutoActivationCharacters(triggers.toCharArray());
51       //    } else if (CASE_SENSITIVITY.equals(key)) {
52       //      boolean enabled = store.getBoolean(CASE_SENSITIVITY);
53       //      jdcp.restrictProposalsToMatchingCases(enabled);
54     } else if (ORDER_PROPOSALS.equals(key)) {
55       boolean enable = store.getBoolean(ORDER_PROPOSALS);
56    //   jdcp.orderProposalsAlphabetically(enable);
57     }
58   }
59 }