Fixed some bugs in the syntax editor preference page
[phpeclipse.git] / net.sourceforge.phpeclipse / src / net / sourceforge / phpeclipse / phpeditor / php / PHPCompletionProcessor.java
index a96712b..dee6cca 100644 (file)
@@ -17,14 +17,16 @@ import java.util.List;
 
 import net.sourceforge.phpdt.internal.corext.template.ContextType;
 import net.sourceforge.phpdt.internal.corext.template.ContextTypeRegistry;
-import net.sourceforge.phpdt.internal.ui.text.java.IJavaCompletionProposal;
-import net.sourceforge.phpdt.internal.ui.text.java.JavaCompletionProposalComparator;
+import net.sourceforge.phpdt.internal.ui.text.java.IPHPCompletionProposal;
+import net.sourceforge.phpdt.internal.ui.text.java.PHPCompletionProposalComparator;
 import net.sourceforge.phpdt.internal.ui.text.template.BuiltInEngine;
 import net.sourceforge.phpdt.internal.ui.text.template.IdentifierEngine;
 import net.sourceforge.phpdt.internal.ui.text.template.TemplateEngine;
 import net.sourceforge.phpeclipse.PHPeclipsePlugin;
+import net.sourceforge.phpeclipse.phpeditor.AbstractContentOutlinePage;
 import net.sourceforge.phpeclipse.phpeditor.PHPContentOutlinePage;
 import net.sourceforge.phpeclipse.phpeditor.PHPEditor;
+
 import org.eclipse.jface.text.IDocument;
 import org.eclipse.jface.text.ITextViewer;
 import org.eclipse.jface.text.TextPresentation;
@@ -234,9 +236,10 @@ public class PHPCompletionProcessor implements IContentAssistProcessor {
 
   protected final static String[] fgProposals = PHPFunctionNames.FUNCTION_NAMES;
 
+  private char[] fProposalAutoActivationSet;
   protected IContextInformationValidator fValidator = new Validator();
   private TemplateEngine fTemplateEngine;
-  private JavaCompletionProposalComparator fComparator;
+  private PHPCompletionProposalComparator fComparator;
   private int fNumberOfComputedResults = 0;
 
   public PHPCompletionProcessor() {
@@ -245,7 +248,26 @@ public class PHPCompletionProcessor implements IContentAssistProcessor {
     if (contextType != null)
       fTemplateEngine = new TemplateEngine(contextType);
 
-    fComparator = new JavaCompletionProposalComparator();
+    fComparator = new PHPCompletionProposalComparator();
+  }
+
+  /**
+   * Tells this processor to order the proposals alphabetically.
+   * 
+   * @param order <code>true</code> if proposals should be ordered.
+   */
+  public void orderProposalsAlphabetically(boolean order) {
+    fComparator.setOrderAlphabetically(order);
+  }
+
+  /**
+   * Sets this processor's set of characters triggering the activation of the
+   * completion proposal computation.
+   * 
+   * @param activationSet the activation set
+   */
+  public void setCompletionProposalAutoActivationCharacters(char[] activationSet) {
+    fProposalAutoActivationSet = activationSet;
   }
   /* (non-Javadoc)
    * Method declared on IContentAssistProcessor
@@ -287,13 +309,15 @@ public class PHPCompletionProcessor implements IContentAssistProcessor {
     if (offset > 0) {
 
       PHPEditor editor = null;
-      PHPContentOutlinePage outlinePage = null;
+      AbstractContentOutlinePage outlinePage = null;
 
       IEditorPart targetEditor = PHPeclipsePlugin.getActiveWorkbenchWindow().getActivePage().getActiveEditor();
       if (targetEditor != null && (targetEditor instanceof PHPEditor)) {
         editor = (PHPEditor) targetEditor;
         outlinePage = editor.getfOutlinePage();
-        identifiers = outlinePage.getVariables();
+        if (outlinePage instanceof PHPContentOutlinePage) {
+          identifiers = ((PHPContentOutlinePage) outlinePage).getVariables();
+        }
       }
     }
 
@@ -307,9 +331,9 @@ public class PHPCompletionProcessor implements IContentAssistProcessor {
       //        ErrorDialog.openError(shell, JavaTextMessages.getString("CompletionProcessor.error.accessing.title"), JavaTextMessages.getString("CompletionProcessor.error.accessing.message"), x.getStatus()); //$NON-NLS-2$ //$NON-NLS-1$
       //      }       
 
-      IJavaCompletionProposal[] templateResults = fTemplateEngine.getResults();
+      IPHPCompletionProposal[] templateResults = fTemplateEngine.getResults();
 
-      IJavaCompletionProposal[] identifierResults = new IJavaCompletionProposal[0];
+      IPHPCompletionProposal[] identifierResults = new IPHPCompletionProposal[0];
       if (identifiers != null) {
         IdentifierEngine identifierEngine;
         String proposal;
@@ -328,7 +352,7 @@ public class PHPCompletionProcessor implements IContentAssistProcessor {
         }
       }
 
-      IJavaCompletionProposal[] builtinResults = new IJavaCompletionProposal[0];
+      IPHPCompletionProposal[] builtinResults = new IPHPCompletionProposal[0];
       if (PHPFunctionNames.FUNCTION_NAMES != null) {
         BuiltInEngine builtinEngine;
         String proposal;
@@ -342,8 +366,8 @@ public class PHPCompletionProcessor implements IContentAssistProcessor {
       }
 
       // concatenate arrays
-      IJavaCompletionProposal[] total;
-      total = new IJavaCompletionProposal[templateResults.length + identifierResults.length + builtinResults.length];
+      IPHPCompletionProposal[] total;
+      total = new IPHPCompletionProposal[templateResults.length + identifierResults.length + builtinResults.length];
       System.arraycopy(templateResults, 0, total, 0, templateResults.length);
       System.arraycopy(identifierResults, 0, total, templateResults.length, identifierResults.length);
       System.arraycopy(builtinResults, 0, total, templateResults.length + identifierResults.length, builtinResults.length);
@@ -356,7 +380,7 @@ public class PHPCompletionProcessor implements IContentAssistProcessor {
        */
       return order(results);
     }
-    return new IJavaCompletionProposal[0];
+    return new IPHPCompletionProposal[0];
   }
 
   private int guessContextInformationPosition(ITextViewer viewer, int offset) {
@@ -366,13 +390,13 @@ public class PHPCompletionProcessor implements IContentAssistProcessor {
 
     //    try {
     //
-    //      JavaCodeReader reader= new JavaCodeReader();
+    //      PHPCodeReader reader= new PHPCodeReader();
     //      reader.configureBackwardReader(document, offset, true, true);
     //  
     //      int nestingLevel= 0;
     //
     //      int curr= reader.read();    
-    //      while (curr != JavaCodeReader.EOF) {
+    //      while (curr != PHPCodeReader.EOF) {
     //
     //        if (')' == (char) curr)
     //          ++ nestingLevel;
@@ -441,7 +465,8 @@ public class PHPCompletionProcessor implements IContentAssistProcessor {
    * Method declared on IContentAssistProcessor
    */
   public char[] getCompletionProposalAutoActivationCharacters() {
-    return null; // new char[] { '$' };
+    return fProposalAutoActivationSet;
+    //    return null; // new char[] { '$' };
   }
 
   /* (non-Javadoc)